[R] More accurate ODE solver?

Ben Bolker bbolker at gmail.com
Thu Sep 16 21:06:49 CEST 2010


Tianchan Niu <niu <at> isis.georgetown.edu> writes:

> 
> Dear All,
> 
> I was using rk4 and lsoda to solve a ODE system. However, both of them gave
> bad accurate solutions, especially compared with Matlab solver ODE45. For
> example, ODE45 gave solutions that can go to a stable level (about 1.6) when
> time goes to infinity, however, the solutions from lsoda are decreasing to
> very very small (about 1e-130) numbers. 
> 
> Does R have more accurate ODE solvers as ODE45 in Matlab?

  See ?rkMethods in the deSolve package. You could try

rk(..., method="ode45")

or otherwise try playing with the tolerances.
Without a reproducible example, it's pretty much impossible to
say what the precise problem is.  It's mildly surprising (although
I am *not* a numerical analyst) that the default 'lsoda' solver
doesn't work well.

  At least in the general description of the algorithm,
method="ode45" is the same as MATLAB's algorithm, although it's
entirely possible that the default tolerances, details of the
implementation, etc., have been tuned differently in the two
packages (since MATLAB is closed-source, we can't tell what the
precise details are).

  It would be interesting to know where the actual problem lies
(different tolerance setting, ode45 vs lsoda, MATLAB vs R implementation);
can you report on your findings and/or post a reproducible example?



More information about the R-help mailing list