Tuesday 22 May 2012

C Program Of NA Using Runga-Kutta Mthod Of 4th Order

/* Runge-kutta method of 4th order to solve 10*dy/dx=(x*x)+(y*y)*/
# include <stdio.h>
# include <conio.h>
void main()
{
int c=0;
float x,y0,xp,h,i,y1,m1,m2,m3,m4;
float f(float,float);
clrscr();
printf("Solution by Runge kutta 2nd order Method\n");
printf("Enter initial Boundry condition x,y : ");
scanf("%f%f",&x,&y0);
printf("Enter Value of X at which Y is required : ");
scanf("%f",&xp);
printf("Enter Interval ,h : ");
scanf("%f",&h);
printf(" No. X\t m1 \t m2\t m3 \t m4 \t Y\n");
printf("-------------------------------------------------------------------\n");
for(i=x;i<=xp;i=i+h)
{
c++;
m1=h*f(i,y0);
m2=h*f(i+(h/2),y0+(m1/2));
m3=h*f(i+(h/2),y0+(m2/2));
m4=h*f(i+h,y0+m3);
y1=y0+((m1+2*m2+2*m3+m4)/6);
printf("%2d %5.6f %5.6f %5.6f %5.6f %5.6f %5.6f\n",c,i,m1,m2,m3,m4,y1);
y0=y1;
}
getch();
}
float f(float x,float y)
{
return ((x*x)+(y*y))/10;
}



OUTPUT



Solution by Runge kutta 2nd order Method
Enter initial Boundry condition x,y : 0 1
Enter Value of X at which Y is required : .09


Enter Interval ,h : .03
No. X m1 m2 m3 m4 Y
-------------------------------------------------------------------------------
1 0.000000 0.003000 0.003010 0.003010 0.003021 1.003010
2 0.030000 0.003021 0.003033 0.003033 0.003047 1.006043
3 0.060000 0.003047 0.003062 0.003062 0.003079 1.009106
4 0.090000 0.003079 0.003097 0.003097 0.003117 1.012204

No comments:

Post a Comment