Search:

Submit Article

# RUNGE-KUTTA 4th ORDER METHOD

Posted By: Lurleen Fischer     Category: C Programming     Views: 22487

## Code for RUNGE-KUTTA 4th ORDER METHOD in C Programming

```#include<stdio.h>
#include <math.h>
#include<conio.h>
//dy/dx = 1 + y^2#define F(x,y)  1 + (y)*(y)
void main()
{
double y0,x0,y1,n,h,f,k1,k2,k3,k4;
clrscr();
printf("\nEnter the value of x0: ");
scanf("%lf",&x0);
printf("\nEnter the value of y0: ");
scanf("%lf",&y0);
printf("\nEnter the value of h: ");
scanf("%lf",&h);
printf("\nEnter the value of last point: ");
scanf("%lf",&n);
for(; x0<n; x0=x0+h)
{
f=F(x0,y0);
k1 = h * f;
f = F(x0+h/2,y0+k1/2);
k2 = h * f;
f = F(x0+h/2,y0+k2/2);
k3 = h * f;
f = F(x0+h/2,y0+k2/2);
k4 = h * f;
y1 = y0 + ( k1 + 2*k2 + 2*k3 + k4)/6;
printf("\n\n  k1 = %.4lf  ",k1);
printf("\n\n  k2 = %.4lf ",k2);
printf("\n\n  k3 = %.4lf ",k3);
printf("\n\n  k4 = %.4lf ",k4);
printf("\n\n  y(%.4lf) = %.3lf ",x0+h,y1);
y0=y1;
}
getch();
}

/*____________________________________         OUT PUT____________________________________Enter the value of x0: 0Enter the value of y0: 0Enter the value of h: 0.2Enter the value of last point: 0.4     k1 = 0.2000     k2 = 0.2020     k3 = 0.2020     k4 = 0.2020       y(0.2000) = 0.202     k1 = 0.2081     k2 = 0.2187     k3 = 0.2193     k4 = 0.2193       y(0.4000) = 0.419*/```
Share:

Didn't find what you were looking for? Find more on RUNGE-KUTTA 4th ORDER METHOD Or get search suggestion and latest updates.

 Lurleen Fischer author of RUNGE-KUTTA 4th ORDER METHOD is from Frankfurt, Germany. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!