Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Satellite orbit in C++ using runge kutta

  1. Dec 15, 2008 #1
    Hi, i am trying to solve the following differential equations for a satellite travelling from earth to jupiter using a runge kutta algorithm.

    The equations are:

    dr/dt=+-(h/r)[((r/r0)-1)(1-(r/r1))]^(0.5)

    and

    dr/d(theta)=+-r[((r/r0)-1)(1-(r/r1))]^(0.5).

    where r0 and r1 are the radii of earths and Jupiters orbits respectively.

    The problem is when trying to solve with the runge kutta when the initial conditions are set (ie r = r0) the function returns 0 and hence there is nochange in further steps. The equations in polar co ords. and my RK is as follows:

    double dr(double r)
    {
    double h,v0=38534.7, r0=0.1495*(pow(10.0,12)), r1=0.7778*(pow(10.0,12));
    h=v0*r0;
    return h/pow(r,2);
    }

    int main()
    {
    double t=0.0, s=10000,r1,th1,kr1,kr2,kr3,kr4; //Declaration and initiation of vars for use in 4th order runge kutta
    int n=0;
    while (t<=8000000)
    {
    t=n*s; //time
    cout << t << "\t" << r0 << endl; //output data to terminal and file
    outs1 << t << "\t" << r0 << endl;

    //Runge Kutta Method
    kr1=s*dr(r0);
    kr2=s*dr(r0+kr1/2);
    kr3=s*dr(r0+kr2/2);
    kr4=s*dr(r0+kr3);
    r1=r0+(kr1+2*kr2+2*kr3+kr4)/6.0;

    r0=r1;
    n++;
    }
    }

    I am unsure if i am using the correct equations of motion to solve this, a full breakdown of the math is availible at http://www.greyfriars-catering.co.uk/math.pdf and any help would be greatly appreciated.

    Cheers

    Sol
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you help with the solution or looking for help too?
Draft saved Draft deleted



Similar Discussions: Satellite orbit in C++ using runge kutta
Loading...