Skip to content

Commit 070d38c

Browse files
Add files via upload
1 parent 18c6030 commit 070d38c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Runge_Kutta_method.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<stdio.h>
2+
#define f(x,y) (x+y*y)//(y*y-x*x)/(y*y+x*x)//(x+y)// //(x-y)/(x+y)
3+
int main()
4+
{
5+
float x0,y0,h,xrq,yrq,k,k1,k2,k3,k4,n;
6+
printf("Enter the initial values of x and y:");
7+
scanf("%f%f",&x0,&y0);
8+
printf("Enter the step length:");
9+
scanf("%f",&h);
10+
printf("Enter the value of x for which y is required:");
11+
scanf("%f",&xrq);
12+
n=(xrq-x0)/h;
13+
for(int i=0;i<n;i++)
14+
{
15+
k1=h*(f(x0,y0));
16+
printf("k1=%f\n",k1);
17+
k2=h*(f((x0+h/2),(y0+k1/2)));
18+
printf("k2=%f\n",k2);
19+
k3=h*(f((x0+h/2),(y0+k2/2)));
20+
printf("k3=%f\n",k3);
21+
k4=h*(f((x0+h),(y0+k3)));
22+
printf("k4=%f\n",k4);
23+
k=(k1+2*k2+2*k3+k4)/6;
24+
printf("k=%f\n",k);
25+
yrq=y0+k;
26+
printf("x%d=%f\n",i,x0);
27+
printf("y%d=%f\n",i,y0);
28+
x0=x0+h;
29+
y0=yrq;
30+
printf("yrq%d=%f\n",i,yrq);
31+
}
32+
33+
}

0 commit comments

Comments
 (0)