Tag Archives: Runge-Kutta Method

Improvements on the Euler Method (backwards Euler and Runge-Kutta)

Several improvements to Euler’s Method exist: the backwards Euler method and the Runge-Kutta method (for Improved Euler method see BingJing Zheng’s post Improved Euler’s Method).

Backwards Euler Method with Example

Recalling that in Euler’s method, one approximates the point (t_{n+1}, y_{n+1}) from the slope of the previous point (t_{n},y_{n}). This yields the equation y_{n+1}=y_{n}+hf(t,y), where the function f represent the slope, or y'(t), and h is the step size. This proves rather inaccurate as the slope at the new point won’t be the same slope of the previous point. In backwards Euler, one considers the same scenario, but takes into account the line connected the two points. Instead of taking the slope at the previous point (t_{n}, y_{n}), one takes the slope at the new point (t_{n+1}, y_{n+1}). This yields the equation y_{n+1}=y_{n}+hf(t_{n+1}, y_{n+1}) for the backwards Euler method.

Example: Given y' = t^2-y, y(0)=1, h = .05 approximate y(1)

Find y at t = 0

Given: At t = 0, y = 1

Find y at t = 0.5

At t = 0.5, y_{n+1}=y_{n}+h*f(t_{n+1},y_{n+1})

At t = 0.5, y_{n+1}=1+0.5y'(0.5,y_{n+1})

At t = 0.5, y_{n+1}=1+0.5(0.5^2-y_{n+1})

At t = 0.5, 1.5y_{n+1}=1.125

At t = 0.5, y_{n+1}=0.75

Find y at t = 1

At t = 1, y_{n+1}=y_{n}+hf(t_{n+1},y_{n+1})

At t = 1, y_{n+1}=0.75+0.5y'(1,y_{n+1})

At t = 1, y_{n+1}=0.75+0.5(1^2-y_{n+1})

At t = 1, 1.5y_{n+1}=1.25

At t = 1, y_{n+1}=0.8333333333

Runge-Kutta Method with Example

Much like the Improved Euler method, one tries to find a better fit for the definite integral of a curve. One uses the idea that a parabola would cover the most area under a curve (compared to a rectangle or trapezoid of other methods). From this idea, one found equations for the following points:

y_{n+1}=y_{n}+h(\frac{k_{1}+2k_{2}+2k_{3}+k_{4}}{6})

where

k_{1}=f(t_{n},y_{n})

 

k_{2}=f(t_{n}+0.5h,y_{n}+0.5hk_{1})

 

k_{3}=f(t_{n}+0.5h,y_{n}+0.5hk_{2})

 

k_{4}=f(t_{n}+h,y_{n}+hk_{3})

 

Example: Given y' = t^2-y, y(0)=1, h = .05 approximate y(1)

Find y at t = 0

Given: At t = 0, y = 1

Find y at t = 0.5

k_{1}=f(t_{n},y_{n})

 

k_{1}=y'(0,1)

 

k_{1}=0^2-1

 

k_{1}=-1

 

k_{2}=f(t_{n}+0.5h,y_{n}+0.5hk_{1})

 

k_{2}=y'(0+0.5(0.5),1+0.5(0.5)(-1))

 

k_{2}=y'(0.25,0.75)

 

k_{2}=0.25^2-0.75

 

k_{2}=-0.6875

 

k_{3}=f(t_{n}+0.5h,y_{n}+0.5hk_{2})

 

k_{3}=y'(0+0.5(0.5),1+0.5(0.5)(-0.6875))

 

k_{3}=y'(0.25,0.828125)

 

k_{3}=0.25^2-0.828125

 

k_{3}=-0.765625

 

k_{4}=f(t_{n}+h,y_{n}+h*k_{3})

 

k_{4}=y'(0+0.5,1+0.5(-0.765625))

 

k_{4}=y'(0.5,0.6171875)

 

k_{4}=0.5^2-0.6171875

 

k_{4}=-0.3671875

 

y_{n+1}=y_{n}+h(\frac{k_{1}+2k_{2}+2k_{3}+k_{4}}{6})

 

y_{0.5}=1+0.5(\frac{-1+2(-0.6875)+2(-0.765625)+(-0.3671875)}{6})

 

y_{0.5}=0.6438802083

 

Find y at t = 1

k_{1}=f(t_{n},y_{n})

 

k_{1}=y'(0.5,0.6438802083)

 

k_{1}=0.5^2-0.6438802083

 

k_{1}=-0.3938802083

 

k_{2}=f(t_{n}+0.5h,y_{n}+0.5hk_{1})

 

k_{2}=y'(0.5+0.5(0.5),0.6438802083+0.5(0.5)(-0.3938802083))

 

k_{2}=y'(0.75,0.5454101562)

 

k_{2}=0.75^2-0.5454101562

 

k_{2}=0.0170898438

 

k_{3}=f(t_{n}+0.5h,y_{n}+0.5hk_{2})

 

k_{3}=y'(0.5+0.5(0.5),0.6438802083+0.5(0.5)(0.0170898438))

 

k_{3}=y'(0.75,0.6481526692)

 

k_{3}=0.75^2-0.6481526692

 

k_{3}=-0.0856526692

 

k_{4}=f(t_{n}+h,y_{n}+h*k_{3})

 

k_{4}=y'(0.5+0.5,0.6438802083+0.5(-0.0856526692))

 

k_{4}=y'(1,0.6010538737)

 

k_{4}=1^2-0.6010538737

 

k_{4}=0.3989461263

 

y_{n+1}=y_{n}+h(\frac{k_{1}+2k_{2}+2k_{3}+k_{4}}{6})

 

y_{1}=0.6438802083+0.5(\frac{-0.3938802083+2(0.0170898438)+2(-0.0856526692)+(0.3989461263)}{6})

 

y_{1}=0.6328751629

 

Analysis

After answering the same question using both the backwards Euler method and Runge-Kutta method, one can see the accuracy of the results.

The exact solution for y(1) is 0.6321205588.

Using the Euler method, y(1) is approximately 0.375.

Using the backwards Euler method, y(1) is approximately 0.8333333333.

Using the Runge-Kutta method, y(1) is approximately 0.6328751629.

The backwards Euler method provides a better approximation than the Euler method, with a few more steps. The Runge-Kutta method provides the best approximation, but involves more calculation.