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

How to solve ODE for independent function

  1. Aug 10, 2011 #1

    I need to solve numerically an equation of the form

    v(t) = k1*z(t)*w(t)-k2*i(t)-k3*di(t)/dt

    The issue is that rungekutta methods are useful for solving

    di(t)/dt = 1/k3 * [ k1*z(t)*w(t)-k2*i(t)-k3*-v(t) ]

    but I need to solve for v(t)

    What I did was:

    v (t) = k1*z(t)*w(t)-k2*i(t)-k3*[i(t)-i(t-1)]/h

    But is not a good approximation because the step size h cannot be small enough. I need a more sophisticated method than directly applying the difference quotient as I did.
    Thanks a lot!
  2. jcsd
  3. Aug 12, 2011 #2


    User Avatar
    Science Advisor

    So your problem is just numerically differentiating the known function i(t)? That can be tricky- just reducing the step size in the "difference quotient" can be unstable. You might want to look at the "five-point stencil" given here:
  4. Aug 12, 2011 #3
    Thanks HallsofIvy!

    I'll give you a little bit more of insight about my problem.
    The equations are for an electric generator in stand alone operation, the actual equation is
    vd=Lq*iq*wr-Rs*id-Ld*did/dt (I wrote a different one for clarity)
    where Lq, Ld, and Rs are constant parameters and vd, iq, wr, and id are functions of time.

    My first approach of course was did/dt = (id(t)-id(t-h))/h, then I improved by a higher order approximation of the form did/dt = (3*id(t) - 4*id(t-h) + id(t-2h))/(2*h)
    But still I have the same problem that did/dt oscillates too much and get's unstable with h less than 0.002, which is too big for me.
    The variables are declare as double in the C code, to have a better precision.

    I do my derivative calculation backwards because I can't use future values. I'm using this equation to produce values of vd in a real-time application. So, I obtain say vd(t1) and with that value I calculate id(t2),iq(t2), and w(t2). With the new values I calculate vd(t2). So I can save the history of the system and use it to calculate the derivative, but I don't have future values.

    Thanks again for your reply!!!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook