Initial problem, Euler and Runge-Kutta methods

PMiKNoM seminars - class 3

Cauchy initial problem

Differential equation in the form: `y' = f(x,y)`
Initial condition: `y(x_0) = y_0`

Explicit Euler's method

The considered problem: ` y’(x)=y(x)+x `
Initial condition: `y(0) = 1`
To be calculated: `y(1)=?`
Explicit Euler's method - eduction
Explicit Euler's method - program's algorithm
  1. Define the function describing the derivative `f(x,y) = y + x`
  2. Declare the variables (including arrays)
  3. Calculate the step of the method (`h`)
  4. Calculate the location of `x(i)` points - for loop
  5. Assign the function value in the initial point `y(0) = 1`
  6. Calculate the value of the function in every next discrete point using Euler's method - for loop
  7. Save the calculated value in the spreadsheet.

Runge-Kutta Methods

Second order Runge-Kutta Method

The method is also known as the midpoint method. While in explicit Euler's method, we aproximate the funcion value in each next discrete point using the value of the derivative in the current point, i.e.

` y_{i+1} = y_i + h \cdot f(x_i, y_i) `

In the midpoint method, we aproximate the funcion value in each next discrete point using the value of the derivative in the so called midpoint:

` y_{i+1} = y_i + h \cdot f(x_{i+ \frac 1 2}, y_{i+ \frac 1 2}) `
where `x_{i+1/2} = x_i +h/2`, while `y_{i+1/2}` is calculated (with Euler's method) as:
` y_{i+ \frac 1 2} = y_i + \frac h 2 \cdot f(x_i, y_i) `

Therefore, the equation for 2nd order Runge-Kutta Method reads:

` y_{i+ 1} = y_i + h \cdot f ( x_i + \frac h 2, y_i + \frac h 2 \cdot f(x_i, y_i) ) `
Fourth order Runge-Kutta Method

Iterative equation for 4nd order Runge-Kutta Method is:

` y_{i+1} = y_i + \frac 1 6 (k_1 + 2 \cdot k_2 + 2 \cdot k_3 + k_4) `
where:
` k_1 = h \cdot f(x_i, y_i) `
` k_2 = h \cdot f(x_i + \frac h 2, y_i + \frac {k_1} 2) `
` k_3 = h \cdot f(x_i + \frac h 2, y_i + \frac {k_2} 2) `
` k_4 = h \cdot f(x_i + h, y_i + k_3) `
Runge-Kutta methods - programs' algorithm
  1. Define the function describing the derivative `f(x,y) = y + x`
  2. Declare the variables (including arrays)
  3. Calculate the step of the method (`h`)
  4. Calculate the location of `x(i)` points - for loop
  5. Assign the function value in the initial point `y(0) = 1`
  6. Calculate the value of the function in every next discrete point using Runge-Kutta method - for loop
  7. Save the calculated value in the spreadsheet.

Comparison between analytical and numerical solution

Additional materials: