[R-sig-dyn-mod] how to model equation with two differential variable?

Karline Soetaert Karline.Soetaert at nioz.nl
Mon May 19 11:12:09 CEST 2014


Hi, 

I don't think this is a DAE; as far as I can see, Pi is an output variable, so you calculate it after the derivatives have been calculated and pass it as a variable.
Example:


model <- function (t, y, p) {
   with(as.list(c(y, p)),{
     dPhi = y[1]
     dAlpha = y[2]
     Pi = a * dPhi + b * dAlpha + c
      return(list(c(dPhi, dAlpha), Pi = Pi))
   })
}

out <- ode (y = c(1,1), times = 0:10, parms = c(a = 1, b = 2, c = 3), func = model)
plot(out)


Hope it helps,
Karline

-----Original Message-----
From: r-sig-dynamic-models-bounces at r-project.org [mailto:r-sig-dynamic-models-bounces at r-project.org] On Behalf Of Gianmarco Polotti
Sent: zaterdag 17 mei 2014 17:59
To: Special Interest Group for Dynamic Simulation Models in R
Subject: Re: [R-sig-dyn-mod] how to model equation with two differential variable?

If I'm not wrong this fall in DAEs. I would suggest:
use deSolve with the option LSODAR.
Write a function for derivatives (let call func) that gives:
dPhi/dt = ....
dAlpha/dt = ....
Write a function for the algebric part (let call rootfunc ):
inside rootfunc, first call func and get inside it the values of  dPhi/dt and dAlpha/dt, end then you can calculate:
r=-Pi +a * dPhi/dt + b * dAlpha/dt + c
the parameters a,b,c, can be passed by the vector, pars, in the main call to LSODAR.
I hope this help you.
Bye
Gianmarco
PS in deSolve there are routines for DAEs solution in one shot, however I have not direct experience. Maybe someone has a better knowledge.


2014-05-17 2:45 GMT+02:00 Jinsong Zhao <jszhao at yeah.net>:

> Hi there,
>
> Don't know if the subject is reasonable. In the model I am trying to 
> solve have a function like:
>
> Pi = a * dPhi/dt + b * dAlpha/dt + c
> dPhi/dt = ....
> dAlpha/dt = ....
>
> I don't know how to make the model equation for the first equation.
>
> I try to use deSolve package.
>
> Any suggestions? Thanks in advance.
>
> Best,
> Jinsong
>
> _______________________________________________
> R-sig-dynamic-models mailing list
> R-sig-dynamic-models at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
>



--
Gianmarco

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-dynamic-models mailing list
R-sig-dynamic-models at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models



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