Solving System of two second order ODE's

1 view (last 30 days)
chen
chen on 9 Jan 2015
Commented: Amos on 11 Jan 2015
Hi , I have tried solving the following system of ODE's (eq1 attached) using Matlab. first i reduced it into a system of four 1st order ODE's (eq2 attached). thani tried to solve it using ode45() in the following manner:
function xprime = Mirage(t,x);
k=2;
xprime=[x(1); k*(1-x(1).^2)./(1+k*x(2)); x(3) ; -(k*x(1)*x(3))./(1+k*x(2))];
end
x0=[1 1 1 1];
tspan=[0,20];
[t,x]=ode45(@Mirage,tspan,x0)
did i set the vector x well in the function? where did i wrong? i will appreciate your help.

Answers (1)

Amos
Amos on 9 Jan 2015
In order to get a system of first order equations, you substitute y' by t and z' by s, right? So your independent functions are then y,t,z,s. These should be ordered in a vector, e.g. x=[y,t,z,s]. The function xprime obviously returns the derivative of the four entries of x. But then x(1)' should be set to x(2), as you have y'=t and not y'=y. The same holds for x(3)' which should not be set to x(3) but rather to x(4).
  2 Comments
chen
chen on 10 Jan 2015
ok i've changed the function code:
function xprime = Mirage(t,x);
k=0.0001;
xprime=[x(2); k*(1-x(2).^2)./(1+k*x(1)); x(4) ; (k*x(2)*x(4))./(1+k*x(1))];
end
the result of x is a matrix . each row is another iteration. i get values for the first two terms [y,t..] but no values for the two last terms [..,z,s] z stays on its initial condition as well s.
finally i want to plot y(z) like so: plot(x(:,3),x(:,1),'r');
again, i'll appreciate your help
Amos
Amos on 11 Jan 2015
So what is actually your question?
When I run the code, I get a four column matrix for x, as you expected. It is true that t=x(2) is stationary, but this is just a consequence of t' being proportional to 1-t. So, if you start with t=1, t' is zero and therefore t doesn't change.
By the way, I think in your corrected version Mirage(t,x), there is a minus sign missing in the last entry of xprime.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!