How to solve an ODE separately inside function with system of ODEs??
Show older comments
Hello All, I am trying to solve a system of ODEs using odes15s where one of my equation is just time dependent equation, the problem is that when i solve the equation separately out of the system it give the right solution but when i put it inside the function with the other ODEs it return me wrong values here my code example:
function dydt=Chemical(t,y,a,b,vdot)
vdot=f(t) % only function ot t;
dy(1)=y(1)
dy(2)=ay(2)*y(1)
dy(3)=y(2)+by(1)
dy(4)=ay(3)*by(2)
dydt=[dy(1)
dy(2)
dy(3)
dy(4)
vdot]
end
then i used odes15s to solve with function handle
out=ode15s(@Chemical,tspan,Y0,a,b) , so why vdot give different values in this system than those when i solve it alone , Thanks
1 Comment
RahulTandon
on 6 Jul 2015
We ought to solve the two equations 1) symbolically first! 2) Convert to a system of ODEs 3) apply ODE45/15s whatever! Could you please send me a copy of vdot(t) = f(t) so that i can provide a complete solution!
Answers (1)
Torsten
on 2 Jul 2015
Y0 = [1 1 1 1 1];
[T,Y]=ode15s(@(t,x)Chemical(t,y,a,b),tspan,Y0)
function dydt=Chemical(t,y,a,b)
vdot=f(t); % only function ot t
dy(1)=y(1);
dy(2)=a*y(2)*y(1);
dy(3)=y(2)+b*y(1);
dy(4)=a*y(3)*b*y(2);
dydt=[dy(1)
dy(2)
dy(3)
dy(4)
vdot];
end
Best wishes
Torsten.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!