

RUNGE KUTTA 2ND ORDER
//Solve by Runge Kutta 4th order method dy/dx=((1+x^2)y) where y(0)=1 and x=0(0.2)0.6
#include<stdio.h>
#include<math.h>
float f(float x,float y)
{
return ((1+pow(x,2))*y);
}
int main()
{
float x,y,p,q,xf,h,d1,d2;
int i=0;
printf("Enter the initial value of x : ");
scanf("%f",&x);
printf("\nEnter the initial value of y : ");
scanf("%f",&y);
printf("\nEnter the final value of x : ");
scanf("%f",&xf);
printf("\nEnter the value of step length (h) : ");
scanf("%f",&h);
printf("\n\n Ite\t Xi\t\t Yi\t\t D1\t\t D2\t\t Yi+1\n");
printf("----------------------------------------");
printf("----------------------------------------");
while(x<xf)
{
d1=h*f(x,y);
d2=h*f(x+h/2,y+d1/2);
p=x;
q=y;
x=x+h;
y=y+d2;
printf("\n%3d\t%f\t%f\t%f\t%f\t%f",i++,p,q,d1,d2,y);
}
printf("\n\n\n\t\t\t The result of Y(%.3f) = %f\n",x,y);
return 1;
}
