How to solve two coupled second order differential equations using ode45 in MatLab?

Equations are:

$b_1\cdot\ddot{X}+b_2\cdot\ddot{Y}+b_3\cdot X+b_4\cdot Y+b_5\cos{2t}\cdot X=0$

$a_1\cdot\ddot{X}+a_2\cdot\ddot{Y}+b_4\cdot X+a_3\cdot Y=0$

where $t$ is time variable, overdots are time derivatives and $a$ and $b$ are constants. Notice the two coupled second order derivatives in both equations.

  • 1
    $\begingroup$ Introduce variables say $A=\dot{X},B=\dot{Y}$, and treat it as four first order differential equations. You'll need to rewrite the equations in the form $\ddot{X}=\dots,\ddot{Y}=\dots$, but that is easy to do because of $a,b$ being constant (you just have to solve a 2x2 linear system, perhaps symbolically if you want to do general a,b). $\endgroup$
    – Ian
    Oct 31, 2017 at 20:03
  • $\begingroup$ I am interested only in ode45 solution. However, I think there is a problem in MatLab using the state equations of the first order when defining the second order derivatives two times in the same equation. For example for $A=[A_1, A_2, A_3, A_4]$ where $A_1=X, A_2=Y, A_3=\dot{X},A_4=\dot{Y}$ yields four first order equations where two of them looks like $ \dot{A_3} = - b_2 / b_1 \cdot \dot{A_4}...$ and $\dot{A_4}=-a_2/a_1\cdot\dot{A_3}...$. $\endgroup$
    – MCaric90
    Oct 31, 2017 at 20:39
  • $\begingroup$ I have no idea what you mean by that. The second derivatives themselves are coupled, so you need to decouple them by solving an algebraic system of equations. When you do that you find that $\dot{A}_3$ and $\dot{A}_4$ are written in terms of $A_1,A_2$. $\endgroup$
    – Ian
    Oct 31, 2017 at 20:46

1 Answer 1


Let $A=\begin{bmatrix} b_1 & b_2 \\ a_1 & a_2 \end{bmatrix}$. Then $\begin{bmatrix} \ddot{X} \\ \ddot{Y} \end{bmatrix} = -A^{-1} \begin{bmatrix} b_3 X + b_4 Y + b_5 \cos(2t) X \\ b_4 X + a_3 Y \end{bmatrix}$. You can combine this with new variables $B=\dot{X},C=\dot{Y}$ to get a system of four scalar first order differential equations.

This assumes $A$ is invertible in the first place; the system is ill-defined otherwise.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .