ODE error message "Error using exist The first input to exist must be a string scalar or character vector"

11 visualizaciones (últimos 30 días)
this is my code
syms no(k1,k2,k3,k_1,k_2,k_3,o2,n2,o,h2o,oh,h,t)
n=(k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh);
eqn1=k1*o*n2-k_1*no*n+k2*n*o2-k_2*no*o+k3*n*oh-k_3*no*h;
fin = diff(no,t)==eqn1;
tspan = [0 10];
i=[0 0];
ra=ode45(fin,tspan,i)
  2 comentarios
darova
darova el 29 de Mayo de 2020
  • you are using symbolic variables. ode45 needs function or function handle
  • your no function depends on several variables (a lot), ode45 works only with one independent variable (ordinary differential equation)
Can you attach original equations?
Abdelrahman Eldaly
Abdelrahman Eldaly el 29 de Mayo de 2020
Editada: Abdelrahman Eldaly el 29 de Mayo de 2020
here no function only in t i want no(t). Unable to find explicit solution appears
T=2146;
a=(101.325/(8.314*T))*10^-3;
o2=16.8*a; n2=717*a; o=0.245*a; h2o=171*a; oh=2.75*a; h=0.134*a;
k1=1.8*10^14*exp(-38370/T);
k_1=3.8*10^13*exp(-425/T);
k2=1.8*10^10*T*exp(-4680/T);
k_2=3.8*10^9*T*exp(-28280/T);
k3=7.1*10^13*exp(-450/T);
k_3=1.7*10^14*exp(-24560/T);
syms no(t)
fin = diff(no,t)==k1*o*n2-k_1*no*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))+k2*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))*o2-k_2*no*o+k3*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))*oh-k_3*no*h;
cond= no(0)==0;
no(t)=dsolve(fin,cond)

Iniciar sesión para comentar.

Respuestas (2)

darova
darova el 29 de Mayo de 2020
Try this way: prepare function handle for ode45 solver
fin = @(t,no) k1*o*n2-k_1*no*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))+k2*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))*o2-k_2*no*o+k3*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))*oh-k_3*no*h;
[t,no] = ode45(fin,[0 1e-7],0);
plot(t,no)

Abdelrahman Eldaly
Abdelrahman Eldaly el 29 de Mayo de 2020
Editada: Abdelrahman Eldaly el 29 de Mayo de 2020
it should appear like this. where is the error
T=2146;
a=(101.325/(8.314*T))*10^-3;
o2=16.8*a; n2=717*a; o=0.245*a; h2o=171*a; oh=2.75*a; h=0.134*a;
k1=1.8*10^14*exp(-38370/T);
k_1=3.8*10^13*exp(-425/T);
k2=1.8*10^10*T*exp(-4680/T);
k_2=3.8*10^9*T*exp(-28280/T);
k3=7.1*10^13*exp(-450/T);
k_3=1.7*10^14*exp(-24560/T);
fin = @(t,no) k1*o*n2-k_1*no*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))+k2*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))*o2-k_2*no*o+k3*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))*oh-k_3*no*h;
tim=0:0.1:2;
[t,no] = ode45(fin,tim,0);
plot(t,no)
  3 comentarios
darova
darova el 29 de Mayo de 2020
The only idea i have is to separate this long expression into two parts. Because it's hard to check if it's correct or not
% fin = @(t,no) k1*o*n2-k_1*no*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))+k2*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))*o2-k_2*no*o+k3*((k1*o*n2+k_2*no*o+k_3*no*h)/(k_1*no+k2*o2+k3*oh))*oh-k_3*no*h;
N = @(no) (...)/(...);
fin = @(t,no) k1*o*n2 - k_1*no*N(no) + ...

Iniciar sesión para comentar.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by