[R] Defining a variable outside of optim or differential equation solver.
thpe at simecol.de
Fri Jul 20 14:16:26 CEST 2012
Hi Tjun Kat,
you can define variables outside the ode function, but normally NOT
state variables, because their values need to be updated by the solver
during the simulation process.
But, if you want to block this for any debugging purposes and want to
e.g. fix a derivative to a certain value, even this is possible. Note
however that this is a very special case and I suspect that you don't
Can you please tell, why you want to define states outside? I guess you
want to emulate a feature that is already available in deSolve, e.g.
forcings or events. In that case, please have a look into the
documentation and one of the papers tutorial slides etc. that can be
Note also that your code contains 3 errors:
1) The call must be "function(t, y, p)", i.e. with "p" even if this is
not required by the model, because ode needs this interface.
2) the closing parenthesis ")" of list is missing.
3) dvdpol vs. vdpol
Hope it helps
On 7/18/2012 3:59 AM, Tjun Kiat Teo wrote:
> This is applicable to either using optim or the differential equation
> solver or any similar solver
> Suppose I want to use the differential equation solver and this is my
> The thing is I want d to be composed of one of state variables in the
> differential function vdopl. Can it be done ?
> tjun kiat
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help