Skip to content

[R-sig-dyn-mod] Simple doubt about how to use function ode

3 messages · Augusto Ribas, Thomas Petzoldt

#
Hello Augustos,

there is nothing wrong with your examples or with the used packages, at 
least not in a technical sense. The problem is indeed your mathematical 
understanding. Your observation simply shows the difference between the 
discrete (function logistico) and a continuous solution (function 
Logistic with ode).

As an example, you may compare an animal population that reproduces once 
a year (= discrete) with a bacterial population with millions of 
individuals that seem to reproduce continuously. The discrete model is 
also called a "difference equation" and the continuous form a 
"differential equation". Package deSolve is intended for solving 
differential equations, and it can be also used for difference equations 
by using the "euler" method.

Read sections 1.4, 3.1 and 3.2 of Henry Stevens book for the details.

A few additional comments are interspersed below.
On 2/25/2011 4:53 PM, Augusto Ribas wrote:
Please respect capitalization, i.e. library(deSolve)
this is natural, because Nts contains a discrete and out a continuous 
solution. Try the following for a discrete solution with deSolve:

out<- ode(y = state, times = times, func = Logistic, parms = parameters, 
method="euler")

And don't forget to consult the book of Stevens and a book about 
differential calculus to understand the difference.
In programming there are always different ways to do the same thing. 
Both methods are intended to unpack the content of "state" and 
"parameters" so that their content can be used by their names (e.g. r, 
n, k).

While the first form:

with(as.list(c(state, parameters)), .....

unpacks both using the "with" function, the second form uses:

n<-state[1]

to "unpack" the state and

with(as.list(parameters), ......

to unpack the parameters. Both have their pros and cons if used for 
bigger models, and the use of either the one or the other for the 
logistic is only a matter of style.

Hope it helps

ThPe