Skip to main content

Scientific Computing

Essential Maths

Linear algebra 2 []

Scientific Computing

Essential Maths

Differential ... []

Scientific Computing

Essential Maths

Systems of di... []

This material has been adapted from material by Fergus Cooper from the "Essential Mathematics" module of the SABS R³ Center for Doctoral Training.

This material has been adapted from material by Fergus Cooper from the "Essential Mathematics" module of the SABS R³ Center for Doctoral Training.

Creative Commons License
This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

Creative Commons License

Systems of differential equations 1

Linear Systems


YouTube lecture recording from October 2020

The following YouTube video was recorded for the 2020 iteration of the course. The material is still very similar:

Youtube lecture thumbnail


Our aim is to solve systems of equations of the form:

dyidt=fi(y1,,yn,t),\displaystyle \frac{{\rm d}y_i}{{\rm d}t} = f_i(y_1,\ldots,y_n,t),

for i=1,,n\displaystyle i=1,\ldots,n.

Let us first consider the simplest form: a 2×22\times2 linear system

dxdt=ax+by,dydt=cx+dy.\begin{align*} \frac{{\rm d}x}{{\rm d}t} &= ax+by,\\ \frac{{\rm d}y}{{\rm d}t} &= cx+dy. \end{align*}

Motivation

In order to understand these systems, we must first understand coupled linear systems.

Recap of eigenvalues

A=(1120)\displaystyle A = \left(\begin{matrix} 1 & 1\\2 & 0 \end{matrix}\right)

import sympy as sp A = sp.Matrix([[1, 1],[2, 0]]) A.eigenvals()

{1:1, 2:1}\displaystyle \left\{ -1 : 1, \ 2 : 1\right\}

Recap of eigenvectors

A=(1120)\displaystyle A = \left(\begin{matrix} 1 & 1\\2 & 0 \end{matrix}\right)

A.eigenvects()

[(1, 1, [[121]]), (2, 1, [[11]])]\displaystyle \left[ \left( -1, \ 1, \ \left[ \left[\begin{matrix}- \frac{1}{2}\\1\end{matrix}\right]\right]\right), \ \left( 2, \ 1, \ \left[ \left[\begin{matrix}1\\1\end{matrix}\right]\right]\right)\right]

Recap of diagonalisation

Recall that, for a matrix AA with eigenvectors v1\mathbf{v}_1 and v2\mathbf{v}_2, and eigenvalues λ1\lambda_1 and λ2\lambda_2, we can write a matrix of eigenvectors: P=(v1v2)P = \left(\begin{matrix} \mathbf{v}_1 & \mathbf{v}_2 \end{matrix}\right). Then:

A=P(λ100λ2)P1\displaystyle A = P \left(\begin{matrix} \lambda_1 & 0 \\ 0& \lambda_2 \end{matrix}\right) P^{-1}

(This is also true for general n×nn \times n matrices.)

In our example,

P=(12111),λ1=1,λ2=2.P = \left(\begin{matrix} -\frac{1}{2} & 1 \\ 1& 1 \end{matrix}\right),\qquad\lambda_1 = -1,\qquad\lambda_2=2.

Coupled ODEs

For coupled system of first order linear differential equations of the form

dxdt=ax+by,dydt=cx+dy.\begin{align*} \frac{{\rm d}x}{{\rm d}t} &= ax+by,\\ \frac{{\rm d}y}{{\rm d}t} &= cx+dy. \end{align*}

we have three methods of analysing them mathematically:

  • Turn them into one second order equation (if we can solve second order!)

  • Divide one by other, to get one equation independent of tt

  • Perform matrix diagonalisation (extends to n×nn \times n problems)

Example

Solve

dxdt=x+y,dydt=2x.\begin{align*} \frac{{\rm d}x}{{\rm d}t} &= x+y,\\ \frac{{\rm d}y}{{\rm d}t} &= 2x. \end{align*}

Subject to

x(0)=0,y(0)=3.\begin{align*} x(0) &= 0,\\ y(0) &= 3. \end{align*}

Method 1: Second order

We start with:

dxdt=x+y,dydt=2x.\begin{align*} \frac{{\rm d}x}{{\rm d}t} &= x+y,\\ \frac{{\rm d}y}{{\rm d}t} &= 2x. \end{align*}

We can convert that into a second order equation:

d2xdt2=dxdt+dydt=dxdt+2x    d2xdt2=dxdt+2x\frac{{\rm d}^2x}{{\rm d}t^2} = \frac{{\rm d}x}{{\rm d}t} + \frac{{\rm d}y}{{\rm d}t} = \frac{{\rm d}x}{{\rm d}t} + 2x \quad \quad\implies \quad\quad \boxed{\frac{{\rm d}^2x}{{\rm d}t^2} = \frac{{\rm d}x}{{\rm d}t} + 2x}

Method 2: eliminate tt

We start with:

dxdt=x+y,dydt=2x.\begin{align*} \frac{{\rm d}x}{{\rm d}t} &=& x+y,\\ \frac{{\rm d}y}{{\rm d}t} &=& 2x. \end{align*}

Then, dividing:

dydx=dydtdxdt    dydx=2xx+y\frac{{\rm d}y}{{\rm d}x} = \frac{ \quad \frac{{\rm d}y}{{\rm d}t} \quad }{ \frac{{\rm d}x}{{\rm d}t} } \quad \quad\implies \quad\quad \boxed{\frac{{\rm d}y}{{\rm d}x} = \frac{2x}{x+y} }

Method 3: diagonalisation

Let v=(xy),\displaystyle \mathbf{v}=\left(\begin{matrix}x\\y\end{matrix}\right),

then

dxdt=x+y,dydt=2x,    dvdt=Av,\frac{{\rm d}x}{{\rm d}t} = x+y,\quad \frac{{\rm d}y}{{\rm d}t} = 2x, \quad \implies \quad \boxed{\frac{{\rm d}\mathbf{v}}{{\rm d}t} = A\mathbf{v},}

where A=(1120).\displaystyle A = \left(\begin{matrix} 1 & 1\\2 & 0 \end{matrix}\right).

Substitute

A=P(λ100λ2)P1.\displaystyle A = P \left(\begin{matrix} \lambda_1 & 0 \\ 0 & \lambda_2 \end{matrix}\right) P^{-1}.

then

dvdt=P(λ100λ2)(P1v)\displaystyle \frac{{\rm d}\mathbf{v}}{{\rm d}t} = P \left(\begin{matrix} \lambda_1 & 0 \\ 0 & \lambda_2 \end{matrix}\right) \left( P^{-1}\mathbf{v} \right)\qquad

or

ddt(P1v)=(λ100λ2)(P1v)\displaystyle \frac{{\rm d}}{{\rm d}t}(P^{-1} \mathbf{v}) = \left(\begin{matrix} \lambda_1 & 0 \\ 0 & \lambda_2 \end{matrix}\right) \left( P^{-1}\mathbf{v} \right)

We can now introduce a new variable   z=(z1z2)=P1v  \displaystyle \;\mathbf{z} = \left(\begin{matrix} z_1 \\ z_2\end{matrix}\right) = P^{-1} \mathbf{v}\; so that:

dzdt=(λ100λ2)z.\displaystyle \frac{{\rm d}\mathbf{z}}{{\rm d}t} = \left(\begin{matrix} \lambda_1 & 0 \\ 0 & \lambda_2 \end{matrix}\right) \mathbf{z}.

But now, because the matrix is diagonal, the system is no longer coupled. The first equation only involves z1z_1 and the second only involves z2z_2, so we can solve each one individually:

dz1dt=λ1z1    z1(t)=Aeλ1t\displaystyle \frac{{\rm d}z_1}{{\rm d}t} = \lambda_1 z_1 \qquad\implies\qquad z_1(t) = A\,e^{\lambda_1 t} > dz2dt=λ2z2    z2(t)=Beλ2t\displaystyle \frac{{\rm d}z_2}{{\rm d}t} = \lambda_2 z_2 \qquad\implies\qquad z_2(t) = B\,e^{\lambda_2 t}

Finally, we can substitute z1z_1 and z2z_2 back in terms of xx and yy to find the solution to the original coupled system:

We have

z=(z1z2)=P1v=13(2221)(xy)=(Aeλ1tBeλ2t)\displaystyle \mathbf{z} = \left(\begin{matrix} z_1 \\ z_2\end{matrix}\right) \quad = \quad P^{-1} \mathbf{v} \quad = \quad \frac{1}{3}\left(\begin{matrix} -2 & 2 \\ 2& 1 \end{matrix}\right) \left(\begin{matrix} x \\ y\end{matrix}\right) \quad = \quad \left(\begin{matrix} A\,e^{\lambda_1 t} \\ B\,e^{\lambda_2 t}\end{matrix}\right)

Rearranging, we now have two equations relating xx and yy:

2x+2y=Ceλ1t\displaystyle -2x + 2y = C\,e^{\lambda_1 t} > 2x+y=Deλ2t\displaystyle 2x + y = D\,e^{\lambda_2 t}

where C=3AC=3A and D=3BD=3B. Using our initial conditions, x(0)=0\,x(0)=0\, and y(0)=3\,y(0)=3\, we find C=6C=6 and D=3D=3.

Finally, solving the simultaneous equations, we have a solution:

x(t)=eλ1t+eλ2t\displaystyle x(t) = -e^{\lambda_1 t} + e^{\lambda_2 t} > y(t)=2eλ1t+eλ2t\displaystyle y(t) = 2e^{\lambda_1 t} + e^{\lambda_2 t}

Summary

  • Three methods to analytically solve systems of linear first order ODEs

  • Best method depends on the system and what you need to ask about it

Introductory problems

Introductory problems 1

Find the general solution to the following system of ODEs:

dxdt=x,anddydt=y.\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{x}{t} = x, \quad\text{and}\quad \dd{y}{t}=y.

Sketch the form of the solution in the x,yx,\,y plane, using arrows to indicate where the solution moves over time.

Introductory problems 2

Take the general decoupled linear system

dxdt=ax,anddydt=by.\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{x}{t} = ax, \quad\text{and}\quad \dd{y}{t} = by.

  1. Integrate the two equations separately to solve for xx and yy in terms of tt.

  2. If you start at t=0t=0, x(0)=0x(0)=0, y(0)=0y(0)=0 what happens to the solution over time?

  3. If you start at a general position x(0)=x0x(0)=x_0, y(0)=y0y(0)=y_0 what happens to the solution as tt\rightarrow\infty?

    • What if aa and bb are both negative?

    • What if only one of aa or bb is negative? What if either x0x_0 or y0y_0 is negative?

  4. Either by eliminating tt from the original equations or by eliminating tt from your solutions to part 1., find a general solution of the system. (Why not try both methods?)

  5. Sketch this solution for

    • a>0,    b>0,    a=b\quad a>0,\;\;b>0,\;\;a=b

    • a>0,    b<0,    a=b\quad a>0,\;\;b<0,\;\;a=-b.

Main problems

Main problems 1

By reformulating the following system as one first order equation (i.e eliminating tt), find the general solution to:

dxdt=y,anddydt=x.\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{x}{t} = -y, \quad\text{and}\quad \dd{y}{t} = x.

Sketch the form of the solutions in the x,yx,\,y plane.

Main problems 2

Again by eliminating tt and reformulating the system as one first order equation, find the general solution to the following system of ODEs:

dxdt=y,anddydt=x.\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{x}{t} = y, \quad\text{and}\quad \dd{y}{t} = x.

Sketch the form of the solutions in the x,yx,\,y plane.

Main problems 3

Find the eigenvalues and two independent eigenvectors v1\mathbf{v}_{1} and v2\mathbf{v}_{2} of the matrix

A=(1411)\displaystyle A = \left(\begin{array}{cc} 1 & 4 \\ 1 & 1 \end{array} \right).

  1. Put the vectors v1\mathbf{v}_{1} and v2\mathbf{v}_{2} as the columns of a 2×22\times 2 matrix PP. Find P1P^{-1} and show (by calculation) that P1APP^{-1}AP is diagonal. What are the entries of this matrix? What do they correspond to?

  2. Find the general solution of the system dxdt=x+4y,anddydt=x+y\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{x}{t} = x+4y, \quad\text{and}\quad \dd{y}{t} = x + y.

  3. Find the particular solution subject to x(0)=0x(0)=0 and y(0)=2y(0)=2.

  4. Sketch the trajectory (the x(t),y(t)x(t),\,y(t) coordinates over time) in the x,yx,\,y plane.

    • Draw the eigenvectors v1\mathbf{v}_{1} and v2\mathbf{v}_{2} on the same figure.

    • What happens as tt\rightarrow \infty?

    • What about tt\rightarrow -\infty?

    • What is dydx\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} \dd{y}{x} at a general point on the yy-axis?

Extension problems

Extension problems 1

The force on a damped harmonic oscillator is f=kxmνdxdt\displaystyle \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} f = -k x - m \nu \dd{x}{t}, where xx is a displacement, k>0k>0 is a spring force constant, m>0m>0 is the mass and ν>0\nu>0 is the strength of the damping.

  1. Use Newton's 2nd law of motion to write down an equation for the acceleration d2xdt2\displaystyle \def\ddd#1#2{{{{\rm d}^2#1}\over{\d{#2}^2}}} \def\d#1{{\rm d}#1} \ddd{x}{t}.

  2. Make the substitution y=dxdt  (and hence dydt=d2xdt2)\displaystyle \def\ddd#1#2{{{{\rm d}^2#1}\over{\d{#2}^2}}} \def\d#1{{\rm d}#1} \def\dd#1#2{{\frac{{\rm d}#1}{{\rm d}#2}}} y=\dd{x}{t}\;\left(\text{and hence }\dd{y}{t} = \ddd{x}{t}\right) to obtain a system of two first-order linear ODEs.