#include<stdio.h>
#include<math.h>
float funct(float,float);
void main()
{
float y0,yprime,k1,k2,k3,k4;
float h,x,iter,x0;
printf("\n\t\t\tFourth Order Runge-Kutta Method To Solve Differential Equation");
printf("\n=========================================================================================================================\n");
printf("\t\t\tEnter the value of h(the interval) ");
scanf("%f",&h);
printf("\n=========================================================================================================================\n");
printf("\t\t\tEnter the value of X(for which you need value of y) ");
scanf("%f",&x);
printf("\n=========================================================================================================================\n");
printf("\t\t\tEnter the intital value y0 ");
scanf("%f",&y0);
printf("\n=========================================================================================================================\n");
printf("\t\t\tEnter the intital value x0 ");
scanf("%f",&x0);
for(iter=x0;iter<=x;iter=iter + h)
{
k1=funct(iter,y0);
k2=funct(iter+(h/2),y0+(k1*h)/2);
k3=funct(iter+((h/2)),y0+(k2*h)/2);
k4=funct(iter+h,y0+(k3*h));
yprime=y0+((h/6)*(k1+2*(k2+k3)+k4));
printf("\n\tValue of X=%f then Value of Y=%f ",iter,y0);
y0=yprime;
}
getchar();
}
float funct(float x,float y)
{
return ((x-y)/(x+y));
}
Sunday, 23 October 2011
Fourth Order Runge-Kutta Method For Differential Equation
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment