System of two second order ODE's

In summary, the conversation was about a problem with solving a system of ODE's using Matlab. The person initially reduced the problem into a system of four 1st order ODE's and tried to solve it using the ode45() function. However, the program seemed to be in an infinite loop and the person was asking for help in fixing the code. Another person suggested swapping the indices in the code, which solved the problem. The conversation ended with the person thanking the other for their help.
  • #1
chenrim
17
0
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)the program seem to be in infinite loop(stays Busy).
where did i wrong?
i will appreciate your help.
 

Attachments

  • eq1.JPG
    eq1.JPG
    3.6 KB · Views: 433
  • eq2.JPG
    eq2.JPG
    4.8 KB · Views: 493
Physics news on Phys.org
  • #2
You've got the order of the vector elements wrong. Matlab assumes the function [itex]\vec y' = \vec f(t, \vec y)[/itex]. In other words, [tex]
\left[ \begin{array}{ccc}
y_1' \\
y_2' \\
y_3' \end{array} \right] =
\left[ \begin{array}{ccc}
f_1(t, \vec y) \\
f_2(t, \vec y) \\
f_3(t, \vec y) \end{array} \right], \vec y =
\left[ \begin{array}{ccc}
y_1 \\
y_2 \\
y_3 \end{array} \right]
[/tex] and so on. The slowdown in your case is due to xprime's current setup wrecking havoc on ode45's adaptive step feature i.e. it's making the time step smaller and smaller.
 
  • #3
Hi da_nang thanks for your answer.
I think i didn't fully understand. In the Mirage function i set two inputs: the first one is the time interval for solving the problem.
the second will be a vector of initial conditions.
the line where " xprime=.." i must have mixed values of x(1) with x(2) and so on because the four equations are semi dependent.
how should the elements should be set? i'll be happy if you can post a fixed code.
thanks
 
  • #4
It's easier to show if you number your functions. [tex]\vec y =
\left[ \begin{array}{ccc}
y_1 \\
y_2 \\
y_3 \\
y_4 \end{array} \right] =
\left[ \begin{array}{ccc}
y \\
y' \\
z \\
z' \end{array} \right]
[/tex]
This gives you the following system of ODEs. [tex] \vec y' = \vec f(t, \vec y) \iff
\left[ \begin{array}{ccc}
y_1' \\
y_2' \\
y_3' \\
y_4' \end{array} \right] =
\left[ \begin{array}{ccc}
y_2 \\
\frac{k(1 - y_2^2)}{1 + k y_1} \\
y_4 \\
\frac{k y_2 y_4}{1 + k y_1}\end{array} \right]
[/tex]

From this you can fix the code by swapping the indices 1 with 2 and 3 with 4.
 
  • #5
I tried your seggestion and it's still doesn't seem to work out for me..
is it working for you?
 
  • #6
Replace
Code:
xprime=[x(1); k*(1-x(1).^2)./(1+k*x(2)); x(3) ; -(k*x(1)*x(3))./(1+k*x(2))];
with
Code:
xprime=[x(2); k*(1-x(2).^2)./(1+k*x(1)); x(4) ; -(k*x(2)*x(4))./(1+k*x(1))];
.

The functions [itex]y[/itex] and [itex]z[/itex] are stored in
Code:
x(:,1)
and
Code:
x(:,3)
respectively after you've run the program. It should work.
 
  • #7
It's working , Thank you very much :)
appreciate your help !
 

FAQ: System of two second order ODE's

What is a system of two second order ODE's?

A system of two second order ODE's (Ordinary Differential Equations) is a set of two equations that involve a function and its derivatives with respect to one independent variable. These equations are used to model systems in various fields such as physics, engineering, and biology.

How is a system of two second order ODE's solved?

Solving a system of two second order ODE's involves first converting the equations into a system of first order ODE's by introducing new variables. The system can then be solved using various techniques such as separation of variables, substitution, or numerical methods.

What are some applications of a system of two second order ODE's?

A system of two second order ODE's has many applications in different fields. It can be used to model the motion of a pendulum, the oscillations of a spring-mass system, the growth of a population, or the dynamics of an electrical circuit.

Can a system of two second order ODE's have a unique solution?

Yes, a system of two second order ODE's can have a unique solution under certain conditions. These conditions include having initial values specified, the equations being linear, and the coefficients being continuous functions. However, in some cases, the system may have multiple solutions or no solutions at all.

How do I know if a system of two second order ODE's is stable?

The stability of a system of two second order ODE's can be determined by analyzing the behavior of its solutions. If the solutions approach a fixed point or converge to a specific value as the independent variable increases, the system is considered stable. Otherwise, it is considered unstable.

Back
Top