Friday, April 1, 2022

Resolution of first order differential equations. Method of Euler

 


Let's consider a differential equation defined by dy/dx = f(x,y) with the initial value of y(0) = y₀. Let's say there isn't any method that can't solve this equation. Not knowing how to find the solution, let's then approximate it.

Let's consider two approximate points solutions of the differential equation and draw a line through these points ( see figure above). Let's calculate the slope of that line. The slope is the tangent of the angle made by by the line and the parallel to the x-axis. Let's call this angle θ. We have:

tanθ. = yⁱᵢ₊₁ - yᵢ /xᵢ₊₁-xᵢ . It is rise/run, the formula to calculate the slope.

tanθ is also the slope of the point (xᵢ, yᵢ). Then we can write f(xᵢ, yᵢ) = yⁱᵢ₊₁ - yᵢ /xᵢ₊₁-xᵢ . We can derive the formula of Euler from this but it will not be fair to do that. What I want to show here is is a reminder of the formula of the slope which is rise/run. 

Let's consider the following figure:



We still have the same differential equation dy/dx = f(x,y) with the initial condition y(0) = y₀

Let's draw a tangent line through the point (0, y₀). Knowing x₁, let y₁ be the approximate solution of the differential equation.. Its value can be calculated using the slope of the tangent line. This slope is the slope at the point (x₀, y₀) which is f(x₀, y₀). We have two points here (x₀, y₀) and (x₁, y₁). Using the formula of the slope rise/run we have:

f(x₀, y₀) = y₁ - y₀/x₁ - x₀

(fx₀, y₀)(/x₁ - x₀) = y₁ - y₀

y₁ = y₀ + (fx₀, y₀)(/x₁ - x₀). This is the approximate value of y₁ 

Now let's draw a line through the point (x₁, y₁) and let's y₂ be the second approximation of the solution knowing x₂

The slope of the line that passes through the points (x₁, y₁) and (x₂, y₂) is :

f(x₁, y₁) = y₂ -y₁/x₂ - x₁

   f(x₁, y₁)(x₂ - x₁) = y₂ -y₁

y₂ = y₁ +  f(x₁, y₁)(x₂ - x₁). This is the approximate value of y₂.

A pattern appears here based on the values of  y₁ and y₂. If we were to calculate a third approximation of the solution which is y₃, it would be: y₃ = y₂ + f(x₂, y₂)(x₃ - x₂)'

Any approximation yₙ can be calculated by yₙ = yₙ₋₁ + f(xₙ₋₁, yₙ₋₁) (xₙ - xₙ₋₁)

Let's write  xₙ - xₙ₋₁ = h, the above equation can be written as : yₙ = yₙ₋₁ + f(xₙ₋₁, yₙ₋₁)h where h is called the step size. This is the Euler formula that allows to calculate the approximate values of a function.

Example

Let's consider a differential equation with a given solution y' + 2y = 2 - e^-4t  y(0) = 1 Use the Euler method with a step size of h = 0.1 to find approximate values of the solutions at t = 0.1 t = 0.2  t = 0.3

Solution 

Let's write the equation on its explicit form: 

y' = 2 - e^-4t - 2y

Let's apply the Euler formula:   yₙ = yₙ₋₁ + f(xₙ₋₁, yₙ₋₁)h. Since the independent variable is t, we can write the formula as yₙ = yₙ₋₁ + f(tₙ₋₁, yₙ₋₁)h

We have h = 0.1 we have to find y for t = 0.1. Since this is the first value of y, we have to call it y₁Let's substitute n by 1 in the formula:

y₁ = y₀ + f(t₀, y₀).0.1

We already have y₀. Let's calculate f(t₀, y₀) or f(0,1). In order to do that, we substitute t by 0 and y by 1 in the explicit form of the differential equation

f(0,1) = 2 - e^0 - 2 = 2 - 1 - 2 = -1

Let's substitute y₀ and f(0,1):

y₁ = 1 + (-1)(0.1) = 1 - 0.1 = 0.90

Let's find y for the value of t = 0.2: In this case we have to substitute n by 2 in the Euler formula in order to find y₂. 

y₂ = y₁ + f(t₁, y₁).0.1

Let's find f(t₁, y₁):

f(0.1, 0.9) = 2 - e^-0.4 - 2(0.9) = -0.47

y₂ = 0.9 + (-0.47)(0.1) = 0.85.

Let's find another approximate value of y for t = 0.3

y₃ = y₂ + f(t₂,y₂).0.1

Let's calculate f(t₂,y₂):

f(0.2, 0.85) = 2 - e^-0.8 -2.0.85 = 2 - 1/e^0.8 - 1.70 = 2 - 0.449 - 1.70 = -0.149

y₃ = 0.85 + (-0.149)(0.1)

y₃ = 0.8351

Where the calculations of the approximate values contain decimals it's better to find the approximations with more than 2 or 3 decimals.

Interested in reviewing Calculus I check this site: Center for Integral Development