[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum » Codeing » C ++ Examples of maths » Runge-Kutta Method of Fourth order (Runge-Kutta Method of Fourth order tested)
Runge-Kutta Method of Fourth order
pradeepDate: Wednesday, 02 November 11, 6:50 PM | Message # 1
pk
Group: Administrators
Messages: 82
Status: Offline
Code
/*Runge-Kutta Method of Fourth order*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
      float f (float x, float y);/* function prototype*/
       float x0, y0, h, xn, k1, k2, k3, k4, k, x, y;
        int i, n;
        clrscr();
         printf("Enter the initial values of x and y :");
         scanf("%f%f", &x0, &y0);
         printf("\n Enter x at which y is required :");
         scanf("%f" , &xn);
         printf("\n Enter step size;");
         scanf("%f",&h);
         n = ((xn-x0)/h+0.5);
             x=x0;
               y=y0;
            printf("\n\n step x y \n\n ");
   for (i=1; i <= n; i++)
{
  k1=h*f(x ,y);/* function call */
  k2=h*f(x+h/2.0, y + k1/2.0);/* Function call*/
  k3=h*f(x+h/2.0, y + k2/2.0);/* Function call*/
  k4=h*f(x+h, y+k3); /* function call*/
  k =(k1+2.0 * (k2+k3) +k4)/6.0;
  x=x+h;
  y=y+k;
  printf ("%3d%10.3f%10.3f\n" , i, x , y);
}
  printf("\n Value of y at x = %f is %f\n\n", x, y );
  getch( );
}
  /* function denfinition f()*/
  float f ( float x , float y)
{
  return (x*y*y -y/x); /*R.H.S of the given equation */

}
 
Forum » Codeing » C ++ Examples of maths » Runge-Kutta Method of Fourth order (Runge-Kutta Method of Fourth order tested)
  • Page 1 of 1
  • 1
Search: