[R-sig-dyn-mod] How to change a parameter after steady?

Jinsong Zhao jszhao at yeah.net
Sun Apr 27 20:42:59 CEST 2014


On 2014/4/27 2:08, Thomas Petzoldt wrote:
> On 4/27/2014 8:13 AM, Jinsong Zhao wrote:
>>
>> Can the following example be used here? Assumed the model reached
>> steady when times >= 100. Then I hope to change r to 0.12, or K to
>> 15. How to? May forcings in the previous post work? Any other
>> solution?
>
> Yes, forcings can be used if your aim is to create a "long-term"
> simulation with changing parameters. Just make r and K time dependent
> forcing functions instead of fixed parameters.
>
> Nevertheless, I still don't understand why you want to do this. If your
> aim is to start a model from an equilibrium, you may consider to
> identify the equilibrium point with a solver from package rootSolve and
> then to use this as the initial value of your simulation.
>
> It is also possible to run several simulations with different parameters
> independently, but that's another story.
>
> Thomas

Thank you very much for the detailed explanation and code demo.

I had tried the solution provided by rootSolve. However, I was misled by 
the plot that magnified the tiny difference in numeric of the output. I 
should take care about the numeric result.

Thanks again!

Regards,
Jinsong

>
>
> model <- function (time, y, parms) {
>      with(as.list(c(y, parms)), {
>           dN <- r * N * (1 - N / K)
>           list(dN)
>      })
> }
>
>
> ## find equilibrium
> library(rootSolve)
> y <- c(N = 0.1)
> parms <- c(r = 0.1, K = 10)
> times <- c(0, Inf)
> equilibrium <- steady(y, times, model, parms, method="runsteady")
>
>
> ## change parameters and run simulation
> library(deSolve)
> y <- equilibrium$y
> parms <- c(r = 0.12, K = 15)
> times <- seq(0, 100, 1)
> out <- ode(y, times, model, parms)
>
> plot(out)
>



More information about the R-sig-dynamic-models mailing list