C Programming For Runge Kutta Method:
#include<stdio.h>
#define f(x,y) ((x)+(y*y))
int main()
{
int n,i;
float x0,y0,h,k1,k2,k3,k4,k;
printf("Enter the value of x0,y0 and h");
scanf("%f",&x0);
scanf("%f",&y0);
scanf("%f",&h);
printf("Enter the Number of Iteration");
scanf("%d",&n);
for(i=0;i<n;i++)
{ {
k1=h*(f(x0,y0));
k2=h*(f(x0+h/2,y0+k1/2));
k3=h*(f(x0+h/2,y0+k2/2));
k4=h*(f(x0+h,y0+k3));
k=(k1+2*k2+2*k3+k4)/6;
printf("The Output is %f",y0+k);
}
y0=y0+k;
x0=x0+h;
}
printf("The Output is %f",y0);
return 0;
}
Comments
Post a Comment