Showing posts with label ODE. Show all posts
Showing posts with label ODE. Show all posts

Wednesday, May 29, 2013

Solution of Ordinary Differential Equation using Runge-Kutta Method | RK4 method for ODE Solution in C

In numerical analysis, the Runge–Kutta methods are an important family of implicit and explicit iterative methods for the approximation of solutions of ordinary differential equations. These techniques were developed around 1900 by the German mathematicians C. Runge and M. W. Kutta.

There are many variants of the Runge-Kutta method, but the most widely used one is the following known as RK-4 method: 
y' = f(x,y) 
y(xn) = yn 
we compute in turn 
k1 = hf(xn,yn) 
k 2 = hf (xn+h/2,yn+k1/2)
k3 = hf (xn+h/2,yn+k2/2)
k4 = hf(xn + h, yn + k3) 
yn+1 = yn + (k1 + 2*k2 + 2*k3 + k4 )/6

This algorithm can be implemented  using the following source code in C: