DAE to ODE conversion w/ piecewise function

I'm getting an error with "Illegal use of reserved keyword 'If'" with the use of the command'odeFunction'. I don't know how to go beyond this step.
if true
% %%standard
clear
format short e
%%initialize variables
syms n(t) s(t) a(t) b(t) G(t) L(t)
Ga1 = 2;
Ga2 = .5;
Ga3 = .2;
B1 = .8;
B2 = 5;
S1 = .2;
Ga0= .05;
%%equations
eqs(1) = diff(n(t), t) == G(t)*n(t) - Ga1*L(t)*n(t);
eqs(2) = diff(s(t), t) == -Ga2*G(t)*n(t) - B1*Ga1*L(t)*n(t);
eqs(3) = diff(a(t), t) == -(b(t)*a(t))/(1 + a(t));
eqs(4) = diff(b(t), t) == -Ga3*b(t) + B2*Ga1*L(t)*n(t);
eqs(5) = G(t) == (s(t)/(1 + s(t)))*(1-n(t));
eqs(6) = L(t) == (times(((a(t)/(S1 + a(t)))*G(t)-Ga0),gt(((a(t)/(S1 + a(t)))*G(t)-Ga0),0)));
%%variables
vars = [ n(t) ,s(t), a(t), b(t), G(t), L(t)];
%%reduction of order
M = incidenceMatrix(eqs, vars);
[eqs, vars, R] = reduceDifferentialOrder(eqs, vars);
isLowIndexDAE(eqs,vars);
[DAEs,DAEvars] = reduceDAEIndex(eqs,vars);
[DAEs,DAEvars] = reduceRedundancies(DAEs,DAEvars);
isLowIndexDAE(DAEs,DAEvars);
%%convert DAE to MATLAB function handle
[M,F] = massMatrixForm(DAEs,DAEvars)
M = odeFunction(M, DAEvars);
end
The above is my code
if true
%Error using symengine
Error: Illegal use of reserved keyword "if".
Error in symengine
Error in sym/matlabFunction (line 186) g = symengine('makeFhandle',varnames,body);
Error in sym/odeFunction (line 135) f = matlabFunction(expr, 'vars', varsAndParams, matlabFunOptions{:});
Error in holder (line 31) M = odeFunction(M, DAEvars); end above is my error
if true
%G(t)*n(t) - 2*L(t)*n(t)
- (8*L(t)*n(t))/5 - (G(t)*n(t))/2
-(a(t)*b(t))/(a(t) + 1)
10*L(t)*n(t) - b(t)/5
-(G(t) - s(t) + G(t)*s(t) + n(t)*s(t))/(s(t) + 1)
piecewise([1/20 < (G(t)*a(t))/(a(t) + 1/5), -L(t) < -(400*L(t) - 10*a(t) - 25*a(t)^2 + 1000*G(t)*a(t)^2 + 10000*L(t)*a(t)^2 - 10000*G(t)^2*a(t)^2 + 200*G(t)*a(t) + 4000*L(t)*a(t) - 1)/(400*(5*a(t) + 1)^2)], [(G(t)*a(t))/(a(t) + 1/5) < 1/20, -(400*L(t) - 10*a(t) - 25*a(t)^2 + 1000*G(t)*a(t)^2 + 10000*L(t)*a(t)^2 - 10000*G(t)^2*a(t)^2 + 200*G(t)*a(t) + 4000*L(t)*a(t) - 1)/(400*(5*a(t) + 1)^2) < -L(t)])
end
above are the equations returned from the reduction of order. i'm fairly certain that the cause of this is piecewise function but that is something I have to retain.

Risposte (0)

Richiesto:

il 22 Apr 2016

Modificato:

il 22 Apr 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by