# Numerical Analysis/ODE in vector form Exercises

All of the standard methods for solving ordinary differential equations are intended for first order equations. When you need to solve a higher order differential equation, you first convert it to a system of first order of equations. Then you rewrite as a vector form and solve this ODE using a standard method. On this page we demonstrate how to convert to a system of equations and then apply standard methods in vector form.

## Reduction to a first order system

I want to show how to convert higher order differential equation to a system of the first order differential equation. Any differential equation of order n of the form

${\displaystyle f\left(t,u,u',u'',\ \cdots ,\ u^{(n-1)}\right)=u^{(n)}}$

can be written as a system of n first-order differential equations by defining a new family of unknown functions

${\displaystyle y_{i}=u^{(i-1)}\quad {\text{for}}\quad i=1,2,...n\,.}$

The n-dimensional system of first-order coupled differential equations is then

${\displaystyle {\begin{array}{rclcl}y_{1}&=&u\\y_{2}&=&u'\\y_{3}&=&u''\\&\vdots &\\y_{n}&=&u^{(n-1)}.\\\end{array}}}$

Differentiating both sides yields

${\displaystyle {\begin{array}{rclclcl}y_{1}'&=&u'&=&y_{2}\\y_{2}'&=&u''&=&y_{3}\\y_{3}'&=&u'''&=&y_{4}\\&\vdots &\\y_{n}'&=&u^{(n)}&=&f(t,y_{1},\cdots ,y_{n}).\\\end{array}}}$

We can express this more compactly in vector form

${\displaystyle \mathbf {y} '=\mathbf {f} (t,\mathbf {y} )}$

where ${\displaystyle \ y_{i+1}=f_{i}\left(t,\mathbf {y} \right)}$ for ${\displaystyle i and ${\displaystyle \ f_{n}\left(t,\mathbf {y} \right)}$ = ${\displaystyle \ f\left(t,y_{1},y_{2},\cdots ,y_{n}\right)\,.}$

## Exercise

Consider the second order differential equation ${\displaystyle \ u''+u=0}$ with initial conditions ${\displaystyle \ u{(0)}=1}$ and ${\displaystyle \ u'{(0)}=0}$. We will use two steps with step size ${\displaystyle \ h={\frac {\pi }{8}}}$ and approximate the values of ${\displaystyle \ u{({\frac {\pi }{4}})}}$ and ${\displaystyle \ u'{({\frac {\pi }{4}})}.}$

Since the exact solution is ${\displaystyle u(t)=\cos(t)}$ we have ${\displaystyle \ u{({\frac {\pi }{4}})}=0.707106781}$ and ${\displaystyle u'{({\frac {\pi }{4}})}=-0.707106781}$.