In the present world and technology, differential equations are used almost everywhere. Ordinary differential are most commonly used for population growth and over-population, over-use of natural resources leading to extinction of animal populations and the depletion of natural resources, genocide, and the spread of diseases.
Finding solutions for these differential equations has been a difficult and interesting task. Around 1900, two mathematicians named C Runge and M W Kutta developed different techniques to find out the approximate solutions of ordinary differential equations. These Techniques are thus named after them as Runge-Kutta methods. Most commonly used method for finding solutions of an ordinary differential equation is RK4 (Runge-Kutta 4th order).
Real world Applications :
Runge-kutta methods are used widely in many researches mainly in fluid dynamics and mechanics for better solutions of the fluids. Other real life application of Runge-Kutta method is simulation and games. In all present games, we find the motion of object relatively and vary the position of different objects according to it. If there is only one force acting on the body, or only one acceleration such as gravity then we can apply simply laws of motion. But in reality, there are lot of constraints that change with time or velocity or any another physical quantity. In this type of situations we need to numerically integrate the equations we have to get the approximation of the moving object.
RK4 is a iterative method to find out the approximate solution of ODE(Ordinary Differential Equation). Starting with an initial given condition we calculate forward step by step using RK4 algorithm. The differential equation of the form
and with an initial condition
are given. We need to find solution for some .
Here is the number of iterations. Now we define the step size .
With the above values, the RK4 method is as follows :
Here is a unknown function of x for which we have to find approximate solution. We are told that , the rate at which changes, is a function of and itself. The initial approximation of the value is . The function and are given initially.
Now, for we have
fornumber of iterations
Here is nothing but the RK4 approximation of
We can see that is calculated by adding to the weighted average of the four increments.
We can use an example for a small demonstration of how this method actually works.
Suppose and Find .
Let us take the step-size as 0.5, so that it takes few steps for the result.
For (1st iteration)
Now we have
Now 2nd iteration)
The above example of 1st degree differential equation itself takes a lot of time to find out the four increments and then the weighted averaged and then the required result. What if we need to calculate the result after 10 iterations ?or 20 ? or even 100 ? Or what if instead of 1st degree equation, a 2nd or 3rd degree equation ? It takes days to find the approximate result just by hand. In this case we need to develop an algorithm for RK4 method and code it, so that it can save a lot of time.
In my case, I got to find the solution of a three degree differential equation
With initial conditions This kind of problem takes a lot of time to do manually. The solution can be found but the main drawback is time. So I wrote an algorithm for this problem to solve in RK4 method to save time and reduce errors.
- For any given differential equation, find out the function of the highest derivative.
For my problem it is
As 3 is the highest degree in the given equation.
- As the degree is 3, define 3 different functions as following
- Suppose we need to find the solution of y at 100th iteration with a step-size 0.1, we do the RK4 method to find .
- Apply RK4 method for all 3 functions separately,
- After every iteration print the data with respective value of or save all the data in a text file.
- Plot graph of the solution required with the data we have.
C++ CODE :
using namespace std;
double fun1(double t, double u1, double v1, double w1)
double fun2(double t, double u1, double v1, double w1)
double fun3(double t, double u1, double v1,double w1)
int m=2, l=-1;
cout<<“R.K. 4th order method to solve a 2nd order diff eqn”<<endl<<endl;
cout<<“t \t\tu1 \t\tu2 \t\t”<<endl<<endl;
With the help of this code we can save data on a text file named as RK4.txt automatically in the same folder where the program is being compiled. From that data we can plot graphs if necessary.
- Ravi TejaVarma