How to solve an ODE separately inside function with system of ODEs??

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

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!

Sign in to comment.

Answers (1)

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.

2 Comments

Thanks for yr response , but is still the same when i solve vdot like:
[T1,Y1]=odes15s(@(t,y)vdot,t) % vdot only f(t) it give me the right answer . but inside the system that i showed u, it return different values even it is independent to any of the other equation
Please post the complete call to ODE15S and the function routine you are using.
Best wishes
Torsten.

Sign in to comment.

Products

Tags

Asked:

on 2 Jul 2015

Commented:

on 6 Jul 2015

Community Treasure Hunt

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

Start Hunting!