/*
Runga-Kutta Method
COmpute:: f(0.2)=?
When f(x,y)=x+y^2; y(0)=1 h=0.1
*/
#include<conio.h>
#include<stdio.h>
void main()
{
float x,y,h,xf,k1,k2,k3,k4,n;
int i;
float f(float,float);
printf("\nEnter x0 & y0");
scanf("%f%f",&x,&y);
printf("\nEnter x & h");
scanf("%f%f",&xf,&h);
n=(xf-x)/h;
for(i=0;i<=(int)n;i++)
{
k1=h*f(x,y);
k2=h*f(x+h/2,y+k1/2);
k3=h*f(x+h/2,y+k2/2);
k4=h*f(x+h,y+k3);
y=y+(k1+2*(k2+k3)+k4)/6;
x=x+h;
}
printf("\nResult %f",y);
getch();
}
float f(float x,float y)
{
return x+y*y;
}
0 Comments