You are on page 1of 2

RUNGE KUTTA METHOD

Q. Write a C program to evaluate y(1.3) using Rx4th order method with


𝒅𝒚
h=0.1 of ODE = 𝒙𝟐 + 𝒚𝟐 , y(1)=0 .
𝒅𝒙

Answer:
1 /*
2 Solve by Runge kutta Method, dy/dx = x²+y² .
3 Name- Ajit Kumar Podder
4 Roll No- 2212413
5 Registration Number- 0532105030370
6 */
7
8 #include<stdio.h>
9 #include<math.h>
10 #include<conio.h>
11
12 float f(float x, float y)
13 {
14 return(x*x+y*y);
15 }
16 int main()
17
18 {
19 int i,n;
20 float x0,y0,x,y,h,k,k1,k2,k3,k4;
21 printf("Enter the value of x0:");
22 scanf("%f",&x0);
23 printf("Enter the value of y0:");
24 scanf("%f",&y0);
25 printf("Enter the value of h:");
26 scanf("%f",&h);
27 printf("Enter the value of x:");
28 scanf("%f",&x);
29 n=(x-x0)/h;
30 x=x0;
31 y=y0;
32 printf("\nx\t\ty\t\tk1\t\tk2\t\tk3\t\tk4\n");
33 printf ("__________________________________________________________\n");
34 for(i=0;i<=n;i++)
35 {
36 k1=h*f(x,y);
37 k2=h*f(x+h/2,y+k1/2);
38 k3=h*f(x+h/2,y+k2/2);
39 k4=h*f(x+h,y+k3);
40 k=(k1+2*k2+2*k3+k4)/6;
41 y=y+k;
42 x=x+h;
43 printf("%d\t\t%f\t%f\t%f\t%f\t%f\t%f\n", x,y,k1,k2,k3,k4);
44 }
45 printf("\n The required value y(1.3)=%f",y);
46 getch();
47
48 }
49
50
51
Output:
Enter the value of x0:1

Enter the value of y0:0

Enter the value of h:0.1

Enter the value of x:1.3

x y k1 k2 k3 k4

___________________________________________________________________________________

-1610612736 0.110722 0.100000 0.110500 0.110555 0.122222 0.000000

1073741824 0.246314 0.122226 0.135203 0.135430 0.150059 0.000000

-536870912 0.413570 0.150067 0.166576 0.167114 0.186092 0.000000

The required value y(1.3)=0.413570

______________________________________________________________________

You might also like