RUNGE-KUTTA 2nd ORDER METHOD.
//program to implement runge kutta method of 4th order
#include<stdio.h>
#include<math.h>
double F (double x,double y)
{
return (x+y)/x;
}
int main ()
{
double x0,y0,y1,n,h,f,k1,k2,k3,k4;
printf("Enter x0,y0,h,xn values \n");
scanf("%lf%lf%lf%lf",&x0,&y0,&h,&n);
for(;x0<n;x0+=h)
{
f=F(x0,y0);
k1=h*f;
f=F(x0+h,y0+k1);
k2=h*f;
y1=y0+(k1+k2)/2;
printf("\nk1=%.5lf\nk2=%.5lf\n",k1,k2);
printf("y(%.5lf) = %.3lf",x0+h,y1);
y0=y1;
}
}
#include<stdio.h>
#include<math.h>
double F (double x,double y)
{
return (x+y)/x;
}
int main ()
{
double x0,y0,y1,n,h,f,k1,k2,k3,k4;
printf("Enter x0,y0,h,xn values \n");
scanf("%lf%lf%lf%lf",&x0,&y0,&h,&n);
for(;x0<n;x0+=h)
{
f=F(x0,y0);
k1=h*f;
f=F(x0+h,y0+k1);
k2=h*f;
y1=y0+(k1+k2)/2;
printf("\nk1=%.5lf\nk2=%.5lf\n",k1,k2);
printf("y(%.5lf) = %.3lf",x0+h,y1);
y0=y1;
}
}
Comments
Post a Comment