//GAURAV MITTAL(2K9/EE/830)
//QUESTION 11. Runge-Kutta Method.
// dy/dx = (y^2-2x)/(y^2+x).
#include
#include
float z;
float f(float x,float y)
{
z=(y*y-2*x)/(y*y+x);
return z;
}
int main()
{
float x0, y0, h, xn, k[5];
printf("\n\nRunge-Kutta Method");
printf("\n\ndy/dx = (y^2-2x)/(y^2+x)");
printf ("\n\n\n\n\n\nEnter the values of 'x0' : ");
scanf ("%f",&x0);
printf ("\nEnter the values of 'y0' : ");
scanf ("%f",&y0);
printf ("\nEnter the increment in x i.e. 'h' : ");
scanf ("%f",&h);
printf ("\nEnter the nth value of x i.e. 'xn' : ");
scanf ("%f",&xn);
printf("\n\n\n\n");
do
{
k[0] = h*f(x0, y0);
k[1] = h*f((x0+(h/2)),(y0+(k[0]/2)));
k[2] = h*f((x0+(h/2)),(y0+(k[1]/2)));
k[3] = h*f((x0+h),(y0+k[2]));
k[4] = ((k[0]+(2*(k[1]+k[2]))+k[3])/6);
x0=x0+h;
y0=y0+k[4];
printf ("\nThe value of y(%f) is = %f\n", x0, y0);
}
while (x0 < xn);
getch();
return 0;
}
No comments:
Post a Comment