# Runge Kutta Method implementation in c

## The Runge-Kutta Method was developed by two German men, Carl Runge (1856-1927) and Martin Kutta (1867- 1944), in 1901.

 Runge Kutta Method implementation in c

Carl Runge developed numerical methods for solving the differential equations that arose in his study of atomic spectra.

Today his name is associated with the Runge-Kutta methods to numerically solve differential equations. Another German applied mathematician, Kutta, is also remembered for contributing to the differential equations-based Kutta-Joukowski theory of airfoil lift in aerodynamics.

The 4th-Order Runge-Kutta method is a standard numerical method used to solve differential equations with a known initial condition. The method starts at the initial condition and proceeds stepwise to develop successive points in the function based on the previous point and the calculated Runge-Kutta parameters. The method lends itself to spreadsheet calculations.

The code for the Runge Kutta method has been written in c language.

### CODE for Runge Kutta method in C:

#include<stdio.h>
#include<conio.h>
#include<math.h>
float fun(float x, float y)
{
return(0.1*x*x+0.1*y*y);       /* here we will give our function which to be solved*/
}
int main( )
{
int i,j,N;
float x0,y0,x,h,y,k[20][20],Y[20],n,p,a;
printf("\n Enter the initial value of X:");
scanf("%f",&x0);
printf("\n Enter the initial value of Y:");
scanf("%f",&y0);
printf("\n Enter the given value of X:");
scanf("%f",&x);
printf("\n Enter the value of step size h:");
scanf("%f",&h);
n=(x-x0)/h;
N=(int)n;
printf("\nNumber of iterations is:%d\n",N);
for(i=1;i<=N;i++)
{
k[i][1]=h*fun(x0,y0);
k[i][2]=h*fun(x0+0.5*h,y0+0.5*k[i][1]);
k[i][3]=h*fun(x0+0.5*h,y0+0.5*k[i][2]);
k[i][4]=h*fun(x0+h,y0+k[i][3]);
k[i][5]=(1.0/6.0)*(k[i][1]+2*k[i][2]+2*k[i][3]+k[i][4]);
x0=x0+h;
y=y0+k[i][5];
Y[i]=y;
y0=y;
}
printf("\nk1\t\tk2\t\tk3\t\tk4\t\tk\t\tY\n");
x0=x0-n*h;
p=h;
for(i=1;i<=N;i++)
{
for(j=1;j<=5;j++)
{
printf("%f\t",k[i][j]);
}
a=x0+h;
printf("\tY(%f)=%f",a,Y[i]);
printf("\n");
h=h+p;
}
printf("\nThe final value of Y:\t%f",y);
getch();
}

#### Input and Output:

If the function is 0.1*x*x+0.1*y*y, then what will happen in the program is given below

 Runge Kutta Method implementation in c

### APPLICATION OF RUNGE KUTTA METHOD:

Runge-Kutta methods are widely used to integrate initial value problems for ordinary differential equations. They can also incorporate initial value problems for time-dependent partial differential equations by applying the so-called method of lines