KEMBAR78
Code 4 | PDF
0% found this document useful (0 votes)
10 views3 pages

Code 4

The document outlines a practical exercise involving the implementation of the Fourth Order Runge-Kutta Method to solve an ordinary differential equation. It includes a C++ code that computes the solution based on user-defined initial conditions and step size. The conclusion highlights the method's effectiveness in providing stable and accurate numerical solutions when analytical methods are not feasible.

Uploaded by

saakshitkd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Code 4

The document outlines a practical exercise involving the implementation of the Fourth Order Runge-Kutta Method to solve an ordinary differential equation. It includes a C++ code that computes the solution based on user-defined initial conditions and step size. The conclusion highlights the method's effectiveness in providing stable and accurate numerical solutions when analytical methods are not feasible.

Uploaded by

saakshitkd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical no: 4

Name- saakshi champaneria


Enrollment no. –ET23BTIC004
Aim- Solving the ordinary differential equation using Fourth Order Runga-Kutta
Mehtod

dy
dx
=f(x,y) y(0)=1

dy
dx
2
=x + y
2
[ x=0, y0=1, h=0.2]

CODE:

#include<stdio.h>

#include<conio.h>

#define f(x,y) (x*x+y*y)

int main()

float x0,y0,xn,h,yn,m1,m2,m3,m4,m;

int i,n;

printf("Enter Initial Condition:\n");

printf("x0 = ");

scanf("%f",&x0);

printf("y0 = ");

scanf("%f",&y0);

printf("Enter calculation point xn = ");

scanf("%f",&xn);

printf("Enter step size:");

scanf("%f",&h);

n=(xn-x0)/h;
printf("%d",n);

printf("\nx0\t\ty0\t\tm\t\tyn\n");

for(i=0;i<n;i++)

m1=f(x0,y0);

m2=f((x0+h/2),(y0+(m1*h/2)));

m3=f((x0+h/2),(y0+(m2*h/2)));

m4=f((x0+h),(y0+(m3*h)));

m=((m1+(2*m2)+(2*m3)+m4)/6);

yn=y0+(m*h);

printf("%f\t%f\t%f\t%f\n",x0,y0,m,yn);

x0=x0+h;

y0=yn;

printf("\nValue of y at x =%f is %f",xn,yn);

return 0;

OUTPUT:
CONCLUSION:
The Runge-Kutta 4th order method was successfully implemented using
C++. The program accurately computed the solution to the first-order
ODE with given initial conditions. This method provides a stable and
accurate numerical solution, and is particularly useful when analytical
methods are difficult or impossible to apply.

You might also like