Solving System of two second order ODE's
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!