Results 1 to 1 of 1

Math Help - Solving double pendulum with runge kutta

  1. #1
    Newbie
    Joined
    Feb 2009
    From
    Gauteng
    Posts
    5

    Solving double pendulum with runge kutta

    I have four first order differential equations (see attachement diff.jpg).

    where
    g= 9.8m/s
    l1 = 0.216 m
    l2 = 0.241 m

    B = g/l1
    alpha = l2/l1

    u = 1 + m1/m2 = 2.22

    // Initial values
    t = 0.0;
    theta1 = (141.7/180)*pi;
    theta2 = (169.8/180)*pi;
    p = 0.0;
    q = 0.0;
    the time step size , h=0.01s

    please see the second order runge kutta funtion I created in C++ and advice if the method was correct

    void RungeKutta(double *t, double *theta1, double *p, double *theta2, double *q, double h)
    {
    double tVal, theta1Val, pVal, theta2Val, qVal;
    double k1, n1, k2, n2, k, n;
    double K1, N1, K2, N2, K, N;

    tVal = *t;
    theta1Val = *theta1;
    pVal = *p;
    theta2Val = *theta2;
    qVal = *q;

    //cout << endl << tVal << " " << theta1Val << " " << pVal << " " << theta2Val << " " << qVal <<endl;

    k1 = h*f(tVal, theta1Val, pVal, theta2Val, qVal);
    n1 = h*g(tVal, theta1Val, pVal, theta2Val, qVal);
    K1 = h*F(tVal, theta1Val, pVal, theta2Val, qVal);
    N1 = h*G(tVal, theta1Val, pVal, theta2Val, qVal);


    k2 = h*f(tVal+h, theta1Val+k1, pVal+n1, theta2Val+K1, qVal+N1);
    n2 = h*g(tVal+h, theta1Val+k1, pVal+n1, theta2Val+K1, qVal+N1);
    K2 = h*F(tVal+h, theta1Val+k1, pVal+n1, theta2Val+K1, qVal+N1);
    N2 = h*G(tVal+h, theta1Val+k1, pVal+n1, theta2Val+K1, qVal+N1);

    //cout << k2 << " " << n2 << " "<< K2 << " "<< N2 << " " <<endl;

    k = (k1 + k2)/2;
    n = (n1 + n2)/2;
    K = (K1 + K2)/2;
    N = (N1 + N2)/2;

    // cout << endl << k << " " << n << " "<< K << " "<< N << " " <<endl;

    tVal += h; theta1Val += k; pVal += n; theta2Val += K; qVal += N;

    *t = tVal;
    *theta1 = theta1Val;
    *p = pVal;
    *theta2 = theta2Val;
    *q = qVal;

    }
    Attached Thumbnails Attached Thumbnails Solving double pendulum with runge kutta-diff.jpg  
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Solving Second Order Differential Equations using Runge Kutta
    Posted in the Differential Equations Forum
    Replies: 5
    Last Post: December 22nd 2010, 12:33 PM
  2. Solving 2nd ODE with Runge Kutta?
    Posted in the Differential Equations Forum
    Replies: 5
    Last Post: October 11th 2010, 05:50 AM
  3. Runge Kutta (RK4) help
    Posted in the Calculus Forum
    Replies: 5
    Last Post: December 20th 2009, 11:10 AM
  4. Runge Kutta Help
    Posted in the Calculus Forum
    Replies: 0
    Last Post: October 16th 2008, 10:50 PM
  5. Runge-Kutta
    Posted in the Differential Equations Forum
    Replies: 0
    Last Post: May 22nd 2008, 08:54 PM

Search Tags


/mathhelpforum @mathhelpforum