[R] solving first-order differential equation
Joerg van den Hoff
j.van_den_hoff at fz-rossendorf.de
Mon Jun 12 13:59:20 CEST 2006
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
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
not really an answer, but a remark:
if your ODE is of the form
dy
--- - k y = A f(x)
dx
(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)
More information about the R-help
mailing list