Re: [R] solving first-order differential equation

From: Joerg van den Hoff <>
Date: Mon 12 Jun 2006 - 21:59:20 EST

ZhanWu Dai wrote:
> I am an initial user of R. Could you give me some explanations or examples on how to solve the first order differential equations by the first-order Runge-Kutta method?
> Thank you very much
> Kind regards
> ------------------------------------------------------------------------
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!

not really an answer, but a remark:

if your ODE is of the form

--- - k y = A f(x)

(k, A const.) it might be a better idea to use the 'analytic' solution instead of runge-kutta (faster, probably more accurate). for instance, if the initial condition is

y(x=0) = 0

and you're looking only at x>0 the solution simply is

y(x) = A (x) {*} exp(-kx)

where {*} means the finite (continous) convolution extending from 0 to x:

y(x) = A integral from z=0 to z=x {f(z) exp(-k(x-z)) dz}

(which, of course, still has to be computed numerically in general.) this closed-form solution can then
be used, for instance, to determine the unknown parameters (k, A) from a least squares fit to measured f(x), y(x) mailing list PLEASE do read the posting guide! Received on Mon Jun 12 22:04:00 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 13 Jun 2006 - 00:11:58 EST.

Mailing list information is available at Please read the posting guide before posting to the list.