How can I solve This system of ODEs?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I tried to solve these ODE equations but there is an error!
This is my code:
syms x1(w) x2(w) x3(w)
T=773.15; R=1.314;
K=(3.35e+24)*exp(-(70e+3)/(1.987*T));
Keq=exp(53.47-(27330/T));
ode1=diff(x1,w)==((-K*x1)/((x1+x2+x3)*(R*T))*(1-((x2*x3^3)/(x1*((x1+x2+x3)^3)*Keq))));
ode2=diff(x2,w)==((K*x1)/((x1+x2+x3)*(R*T))*(1-((x2*x3^3)/(x1*((x1+x2+x3)^3)*Keq))));
ode3=diff(x3,w)==((3*K*x1)/((x1+x2+x3)*(R*T))*(1-((x2*x3^3)/(x1*((x1+x2+x3)^3)*Keq))));
odes=[ode1;ode2;ode3]
cond1=x1(0)==2;
cond2=x2(0)==0;
cond3=x3(0)==4;
conds=[cond1;cond2;cond3];
[x1Sol(w), x2Sol(w), x3Sol(w)] = dsolve(odes,conds)
And this is the error message
Warning: Explicit solution could not be found.
> In dsolve (line 201)
Error using sym/subsindex (line 796)
Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and
the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.
0 Kommentare
Antworten (2)
Star Strider
am 1 Dez. 2017
You can create a function usable in the numeric ODE solvers by adding:
[odes_vf, vfsubs] = odeToVectorField(odes);
odes_fcn = matlabFunction(odes_vf, 'Vars',{w, Y});
[w,y] = ode15s(odes_fcn, [0 1], [2; 0; 4]);
just after your ‘odes’ assignment. However when I tried that, the numerical integration threw warnings and produced nothing.
0 Kommentare
Karan Gill
am 1 Dez. 2017
You have numeric values in your equations, so solve this numerically. Try ode45: https://www.mathworks.com/help/matlab/ref/ode45.html
For the difference between symbolic and numeric methods, see: https://www.mathworks.com/help/symbolic/choose-symbolic-or-numeric-arithmetic.html.
The error is because you didn't declare the symbolic functions [x1Sol(w), x2Sol(w), x3Sol(w)]. You can ignore it for the moment and focus on getting a solution.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!