You are on page 1of 1

/*To find the solution of the differential equation dy/dx=f(x,y) by Runge-Kutta 4

method*/
#include<stdio.h>
#include<math.h>
float func(float x,float y); /*prototype of function*/
void main()
{
float x0,y0,xn,yn,h;
float k1,k2,k3,k4,k;
float ks=2.0;
x0=0.0;
y0=ks/10;
h=0.1;
printf("Solution set is\n");
printf("\n x\t\t y \n");
printf("________________________");
printf("\n%.5f \t %.5f",x0,y0);
while(xn<=1.0) {
k1=h*func(x0,y0);
k2=h*func(x0 + h/2,y0 + k1/2);
k3=h*func(x0 + h/2,y0 + k2/2);
k4=h*func(x0 + h,y0 + k3);
k=(k1 + 2*k2 + 2*k3 + k4)/6;
xn=x0+h;
yn=y0+k;
printf("\n%.5f \t %.5f",xn,yn);
x0=xn;
y0=yn;
}
}
/*function definition*/
float func(float x,float y)
{
float fval;
float k=2.0,a=k/10,b=k/100;
fval=tan(a*y) + ((x*x*y*y)/(b*b + x*x));
return fval;
}

Output:

Solution set is

x y
________________________
0.00000 0.20000
0.10000 0.20712
0.20000 0.21573
0.30000 0.22497
0.40000 0.23483
0.50000 0.24539
0.60000 0.25670
0.70000 0.26886
0.80000 0.28195
0.90000 0.29608
1.00000 0.31137

You might also like