View Full Version : How to solve ODE for independent function
kaushel
Aug10-11, 03:26 PM
Hello,
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!
HallsofIvy
Aug12-11, 08:27 AM
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:
http://en.wikipedia.org/wiki/Numerical_differentiation
kaushel
Aug12-11, 06:33 PM
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!!!
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.