- 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"
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
darova
2020-5-29
Can you attach original equations?
回答(2 个)
darova
2020-5-29
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 个评论
Abdelrahman Eldaly
2020-5-29
编辑:Abdelrahman Eldaly
2020-5-29
3 个评论
darova
2020-5-29
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) + ...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!