1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Specifiying derivatives

  1. Dec 16, 2007 #1
    I'm just trying to understand how exactly derivatives are to be specified in C++ for use in the 4th order Runge-Kutta method.

    I am implementing the method in C++ (though this part of my program isn't complete yet) however what I am looking to do is first specify the derivatives of the variables in the two first-order differential equations im working with:

    θ' = ω
    ω' = − g⁄R sin θ

    (for modelling the motion of a single pendulum)

    double theta - initial angular displacement (Radians)
    double R - length of Pendulum Rod (Metres)
    double g - gravitational constant (Distance/Time^2)

    I just need a little help understanding how to specify the derivatives and basically what I'm doing when I am. (I'm familiar with calculus just not numerical solving algorithms).

    Thanx.
     
  2. jcsd
  3. Dec 17, 2007 #2

    EnumaElish

    User Avatar
    Science Advisor
    Homework Helper

    I will assume that the solution y = (y1, y2) = (θ, ω) you are seeking is defined in a "t x ANGLE2" space where θ [itex]\in[/itex] ANGLE and ω [itex]\in[/itex] ANGLE and variable t (e.g., time) is implicit -- that is, t does not appear as an argument of θ or ω. If that is not right, please post so.

    Given the initial value y(0) = (y1(0), y2(0)) = (θ(0), ω(0)), and an (arbitrarily small) step size h, the 4 functional steps are:

    k1(0) = (k11(0), k12(0)) = (θ'(0), ω'(0)) = (ω(0), −g⁄R sin θ(0));

    k2(0) = (k21(0), k22(0)) = (θ'(0)+h k11(0)/2, ω'(0)+h k12(0)/2) = (ω(0)+hω(0)/2, −g⁄R sin θ(0)+h[−g⁄R sin θ(0)]/2);

    Then define k3(0) = (k31(0), k32(0)) in terms of k2(0) = (k21(0), k22(0)) as described here: http://en.wikipedia.org/wiki/Runge-kutta#The_classical_fourth-order_Runge.E2.80.93Kutta_method;

    Then define k4(0) = (k41(0), k42(0)) in terms of k3(0) = (k31(0), k32(0)) as described here: http://en.wikipedia.org/wiki/Runge-kutta#The_classical_fourth-order_Runge.E2.80.93Kutta_method.

    Finally, calculate the weighted average y(1) = (θ(1), ω(1)) = y(0) + [k1(0) + 2k2(0) + 2k3(0) + k4(0)]h/6. And you are on your way to calculate y(2), ..., y(N).
     
    Last edited: Dec 18, 2007
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?