Solving System of two second order ODE's

조회 수: 1 (최근 30일)
chen
chen 2015년 1월 9일
댓글: Amos 2015년 1월 11일
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.

답변 (1개)

Amos
Amos 2015년 1월 9일
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
chen
chen 2015년 1월 10일
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 2015년 1월 11일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by