ODE error message "Error using exist The first input to exist must be a string scalar or character vector"
Ältere Kommentare anzeigen
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 Kommentare
darova
am 29 Mai 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
am 29 Mai 2020
Bearbeitet: Abdelrahman Eldaly
am 29 Mai 2020
Antworten (2)
darova
am 29 Mai 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
am 29 Mai 2020
Bearbeitet: Abdelrahman Eldaly
am 29 Mai 2020
3 Kommentare
darova
am 29 Mai 2020
Can you show the original equation?
Abdelrahman Eldaly
am 29 Mai 2020
darova
am 29 Mai 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) + ...
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



