- 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)
ODE error message "Error using exist The first input to exist must be a string scalar or character vector"
19 views (last 30 days)
Show older comments
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 Comments
darova
on 29 May 2020
Can you attach original equations?
Answers (2)
darova
on 29 May 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)

0 Comments
Abdelrahman Eldaly
on 29 May 2020
Edited: Abdelrahman Eldaly
on 29 May 2020
3 Comments
darova
on 29 May 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) + ...
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


