dsolve Indexing Error - system of ODE's

1 Ansicht (letzte 30 Tage)
John Barr
John Barr am 6 Apr. 2020
Beantwortet: Guru Mohanty am 13 Apr. 2020
Good evening;
When I try to run the code to solve this system of ODE's using dsolve,
syms X(z) T(z)
K1 = exp(-14.96+11070/T);
K2 = exp(-1.331+2331/T);
Keq = exp(-11.02+11570/T);
R = (X((1-0.167*(1-X))^0.5) - (2.2*(1-X)/Keq))/((K1+K2(1-X))^2);
ode1 = diff(X) == -50*R;
ode2 = diff(T) == -4.1*(T-673.2)+ 10200*R;
odes = [ode1; ode2];
cond1 = T(0) == 673.2;
cond2 = X(0) == 1;
conds = [cond1, cond2];
[XSol(z), TSol(z)] = dsolve(odes,conds);
I keep on getting the following error:
How do I index my above formulas correctly? By calling ode1 and ode2 I know they are formed correctly in lines 9 and 10.
Warning: Unable to find explicit solution.
> In dsolve (line 201)
In Question1 (line 16)
Error using sym/subsindex (line 845)
Invalid indexing or function definition. Indexing
must follow MATLAB indexing. Function arguments
must be symbolic variables, and function body must
be sym expression.
Error in Question1 (line 16)
[XSol(z), TSol(z)] = dsolve(odes,conds);
  1 Kommentar
darova
darova am 6 Apr. 2020
Maybe it can't handle to solve it symbolically. Did you try numerical method?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guru Mohanty
Guru Mohanty am 13 Apr. 2020
In this case dsolve cannot find an explicit or implicit solution. You try to find a numeric solution using the MATLAB® ode23 or ode45 function. The system of differential equation can be solved through following steps.
  1. Define Time span and Initial Conditions.
  2. Build the System of equations.
  3. Use ode45 to solve.
Here is a sample code for it.
% O(1)=> T
% O(2)=> X
cond1 = 673.2;
cond2 = 1;
conds = [cond1, cond2];
tspan=0:0.01:100;
[t,Out]=ode45(@(z,O)odefun(O,z),tspan,conds);
plot(t,Out(:,1),'-',t,Out(:,2),'-.')
% Form The differential Equation
function diffO = odefun(O,z)
diffO = zeros(2,1);
K1 = exp(-14.96+11070/O(1));
K2 = exp(-1.331+2331/O(1));
Keq = exp(-11.02+11570/O(1));
R = (O(2)*((1-0.167*(1-O(2)))^0.5) - (2.2*(1-O(2))/Keq))/((K1+K2*(1-O(2)))^2);
diffO(1)=-50*R;
diffO(2)=-4.1*(O(1)-673.2)+ 10200*R;
end

Kategorien

Mehr zu Symbolic Math Toolbox 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!

Translated by