Subscribe Us

Responsive Advertisement

Advertisement

13.Runge Kutta's method

 

13.Runge Kutta's method

by ujjal roy



//dy/dx=x+y;

#include<bits/stdc++.h>

using namespace std;

double f(double x,double y)

{

    return x+y*y;

}

int main()

{

    double x0,y0,x,y,h;

    cout<<"Enter X0 and Y0 : ";

    cin>>x0>>y0;

    cout<<"Enter X : ";

    cin>>x;

    h=(x-x0)/5.0;

    for(int i=0;i<5;i++)

    {

        double k1,k2,k3,k4;

        k1=h*f(x0,y0);

        k2=h*f((x0+h/2.0),(y0+k1/2.0));

        k3=h*f((x0+h/2.0),(y0+k2/2.0));

        k4=h*f((x0+h),(y0+k3));

        double k;

        k=(k1+2*k2+2*k3+k4)/6.0;

        y=y0+k;

        x0+=h;

        y0=y;


    }

    cout<<y<<endl;




    return 0;

}


Post a Comment

0 Comments