2 Matlab implementation

To use ODE45, one must first convert the above second order ODE to two ODE’s, each of which is first order. Letting \(x_{1}=x, x_{2}=x^{\prime }(t)\) results in

\[ \left . \begin {array} [c]{c}x_{1}=x\\ x_{2}=x^{\prime }\left ( t\right ) \end {array} \right \} \left . \begin {array} [c]{c}x_{1}^{\prime }=x^{\prime }\left ( t\right ) =x_{2}\\ x_{2}^{\prime }=x^{\prime \prime }\left ( t\right ) =c\left ( 1-x^{2}\right ) x^{\prime }\left ( t\right ) -kx\left ( t\right ) \end {array} \right \} \left . \begin {array} [c]{c}x_{1}^{\prime }=x_{2}\\ x_{2}^{\prime }=c\left ( 1-x_{1}^{2}\right ) x_{2}-kx_{1}\end {array} \right \} \]

The system of equations to be solved by ODE45 is the following

\[\begin {pmatrix} x_{1}^{^{\prime }}\\ x_{2}^{^{\prime }}\end {pmatrix} =\begin {pmatrix} x_{2}\\ c\left ( 1-x_{1}^{2}\right ) x_{2}-kx_{1}\end {pmatrix} \]

Subject to initial conditions \(x_{1}(0) =x(0) \) and \(x_{2}(0) = x^{\prime }(0)\). In the Matlab implementation below, the values of \(c,k\) and the initial conditions are defined at the top of the code. This needs to be modified to change the initial conditions before running the program again.