# 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

$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

$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

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

Differentiating both sides yields

${\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

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

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

## Exercise

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

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