Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Numerical MethodsRSS Feeds

RUNGE-KUTTA METHOD

Posted By: Brenda Fischer     Category: C Programming     Views: 43233

Write a program of RUNGE-KUTTA METHOD.

Code for RUNGE-KUTTA METHOD in C Programming

#include<stdio.h>
#include <math.h>
#include<conio.h>
//dy/dx = y - x#define F(x,y)  (y)-(x)
void main()
{
  double y0,x0,y1,n,h,f,f1,k1,k2;
  int j;
  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;
    f1 = F(x0+h,y0+k1);
    k2 = h * f1;
    y1 = y0 + ( k1 + k2)/2;
    printf("\n\n  k1 = %.4lf ",k1);
    printf("\n\n  k2 = %.4lf ",k2);
    printf("\n\n  y(%.4lf) = %.3lf ",x0+h,y1);
    y0=y1;
  }
getch();
}
/*
____________________________________

OUT PUT
____________________________________


Enter the value of x0: 0

Enter the value of y0: 2

Enter the value of h: 0.05

Enter the value of last point: 0.1


k1 = 0.1000

k2 = 0.1025

y(0.0500) = 2.101

k1 = 0.1026

k2 = 0.1052

y(0.1000) = 2.205
*/
  
Share: 

 
 

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

Brenda Fischer
Brenda Fischer author of RUNGE-KUTTA METHOD is from Frankfurt, Germany.
 
View All Articles

 

Other Interesting Articles in C Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!