Print content
Initial problem, Euler and Runge-Kutta methods
PMiKNoM seminars - class 3
Cauchy initial problem
- What is Cauchy initial problem and what are its applications?
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
- We divide the segment `(0,1)` into n sub-segments, each having the length `h = \frac{1}{n}`
- The discrete points `x` are located at `x_i = h \cdot i`
- According to definition `y'=\lim_{h->0} {y(x+h)-y(x)}/h`
- Let's denote `y_i = y(x_i)` and get rid of the limit (assumption: h is close to 0). We obtain: `y_i ' = {y_{i+1}-y_i}/h`
- After transforming the equation and denoting `y_i ' = f(x_i,y_i)` we obtained the equation known as Explicit Euler's Method: `y_{i+1} = y_i + h \cdot f(x_i, y_i) `
- This way we obtain the value of the function in each discrete point, to approximate the solution.
Explicit Euler's method - program's algorithm
- Define the function describing the derivative `f(x,y) = y + x`
- Declare the variables (including arrays)
- Calculate the step of the method (`h`)
- Calculate the location of `x(i)` points - for loop
- Assign the function value in the initial point `y(0) = 1`
- Calculate the value of the function in every next discrete point using Euler's method - for loop
- 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
- Define the function describing the derivative `f(x,y) = y + x`
- Declare the variables (including arrays)
- Calculate the step of the method (`h`)
- Calculate the location of `x(i)` points - for loop
- Assign the function value in the initial point `y(0) = 1`
- Calculate the value of the function in every next discrete point using Runge-Kutta method - for loop
- Save the calculated value in the spreadsheet.
Comparison between analytical and numerical solution
- Analytical solution: `y(x)= 2e^x-x-1`
- The dependence between the precision, the number of discrete points and the order of the numriacal method.
Additional materials:
- R. Filipek, K. Szyszkiewicz-Warzecha "Metody Matematyczne dla Ceramików", pages 85-95.