dydx

Ordinary Differential Equations

Your Progress in this Chapter

0%

0 / 21 units completed

Chapter Overview

System of First Order Differential Equations

Section 8.2 of 723 min7 code examples

Introduction

A system of first‑order differential equations involves multiple dependent variables, each with its own derivative, coupled together. Many physical, biological, and engineering models naturally lead to such systems.

Examples:

  • Predator–prey dynamics(Lotka–Volterra)
  • Coupled oscillators
  • Chaotic systems(Lorenz attractor)

SepalSolver provides tools to solve these systems numerically using , just as with single ODEs, but the function signature changes to accept and return arrays.

General Form

A system of n first‑order ODEs can be written as:

dy1dt=f1(t,y1,y2,,yn)dy2dt=f2(t,y1,y2,,yn)dyndt=fn(t,y1,y2,,yn)\begin{array}{c} \cfrac{dy_1}{dt} = f_1(t, y_1, y_2,\dots, y_n) \\ \cfrac{dy_2}{dt} = f_2(t, y_1, y_2,\dots, y_n) \\ \vdots \\ \cfrac{dy_n}{dt} = f_n(t, y_1, y_2,\dots, y_n) \end{array}

In SepalSolver, this is represented by a function:

Example 1C#

1
2
Code is ready to run

where y is the vector of dependent variables.

Examples

These are examples of how to use SepalSolver to solve various systems of first-order ODEs.

.. Admonition:: Example 1 : Simple Harmonic Oscillator

A simple harmonic oscillator can be modeled as a system of first-order ODEs:

\begin{eqnarray} y_1' &= y_2 \\ y_2' &= -y_1 \end{eqnarray}

This represents a simple harmonic oscillator written as a system.

Example 2C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Code is ready to run
OutputFrom the book
Simple_Harmonic_Oscillator.png

.. Admonition:: Example 2 : Lotka–Volterra Predator–Prey

The Lotka–Volterra equations model the dynamics between predator and prey populations. Mathemtically, it is defined as:

\begin{eqnarray} x' &= \alpha x-\beta xy \\ y' &= \delta xy-\gamma y \end{eqnarray}

Example 3C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Code is ready to run
OutputFrom the book
Lotka_Volterra_Predator_Prey_System.png

.. Admonition:: Example 3 : Lorenz System (Chaotic, Non‑analytical)

The Lorenz system is a set of three coupled, first‑order ODEs that exhibit chaotic behavior:

\begin{eqnarray} \cfrac{dx}{dt} &= \sigma (y - x) \\ \cfrac{dy}{dt} &= x(\rho - z) - y \\ \cfrac{dz}{dt} &= xy - \beta z \end{eqnarray}

Example 4C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Code is ready to run
OutputFrom the book
Lorenz_System.png

.. Admonition:: Example 4 : SIR Epidemic Model

The SIR model divides a population into three compartments: Susceptible (S), Infected (I), and Recovered (R). The model is defined by the following system of ODEs:

\begin{eqnarray} \cfrac{dS}{dt} &= -\beta\cfrac{S I}{N} \\ \cfrac{dI}{dt} &= \beta\cfrac{S I}{N} - \gamma I \\ \cfrac{dR}{dt} &= \gamma I \end{eqnarray}

Example 5C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Code is ready to run
OutputFrom the book
SIR_Epidemic_Model.png

.. Admonition:: Example 5 : Brusselator Model

The brusselator is a theoretical model for a type of autocatalytic reaction. It is defined by the following system of ODEs:

\begin{eqnarray} \cfrac{dx}{dt} &= A - (B + 1)x + x^2y \\ \cfrac{dy}{dt} &= Bx - x^2y \end{eqnarray}

Example 6C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Code is ready to run
OutputFrom the book
Brusselator_Model.png

.. Admonition:: Example 6 : Blasius Boundary Layer

The Blasius Boundary Layer refers to a boundary layer of fluid in the vicinity of a flat plate that moves steadily in its own plane.This concept was first introduced by German mathematician Heinrich Blasius. This solution is important in the field of fluid dynamics, particularly in the area of laminar flow.In this solution, the flow velocity outside the boundary layer is assumed to be uniform. Inside the boundary layer, the fluid's velocity changes from zero at the plate surface to the free stream velocity at the edge of the boundary layer. This concept plays a significant role in understanding and predicting the behavior of fluid flow in various engineering and scientific applications. The solutions to the Blasius equation provide valuable insights into the behavior of fluid flow near a boundary. For instance, it demonstrates that the boundary layer thickness grows as the square root of the distance along the plate. Also, it reveals that the shear stress at the plate surface is proportional to the square root of the free stream velocity, among other observations. The Blasius Boundary Layer solution, despite its simplifications, offers a good approximation for real-life engineering problems involving fluid flow over flat surfaces.This understanding is crucial in designing and optimizing various engineering systems, ranging from airfoils in aeronautics to heat exchangers in thermal power plants and thermal shield design on reusable rockets.

2f+ff=02f''' + f''f = 0

This equation can be solved by transforming it into a system of 1st order differential equations. Let: y_1 = f, y_2 = f', y_3 = f'' hence

y1=f=y2,y2=f=y3,y3=f=0.5ff=0.5y3y1\begin{array}{rcl} y'_1&=&f' = y_2, \\ y'_2&=&f'' = y_3, \\ y'_3&=&f''' = -0.5f''f = -0.5y_3y_1 \end{array}

So, the system of first order differential equation is thus:

y1=y2,y2=y3,y3=0.5y3y1\begin{array}{rcl} y'_1&=& y_2, \\ y'_2&=& y_3, \\ y'_3&=& -0.5y_3y_1 \end{array}

Subject to the following initial and terminal conditions. y_1(0) = 0, y_2(0) = 0, y_2(\infty) = 1 To solve system of ordinary differential equation, you need the initial conditions, but when one of the initial conditions is missing, and we have a terminal condition instead, we can solve for the initial condition we do not have using the terminal condition we have, just like finding the root of a nonlinear function.But to evaluate the value of the function that you want to be zero, you have to perform the integration of the ode, using the guess given by the nonlinear solver and then return the function value which is the difference between the terminal value you obtained from the integration and the desired value.In this case the unknown value is y_3(0), and the function value is y_2(\infty) - 1.

Example 7C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Code is ready to run
OutputFrom the book
Solution is 0.33256562390833655
Blasius-bounary-layer.png