frunge: Numeric solution of an ODE (univariate)

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/frunge.R

Description

frunge provides a sampled numeric solution for an ODE for a given set of values of the independent variable (t). Returns a series of values corresponding to each values of t

Usage

1
frunge(t, param, y0, Dfdt, dt = 0.01, graph = FALSE)

Arguments

t

The independent variable. Must be sorted in increasing order

param

Numeric vector : under the form of c(param1,param2...) gives the parameters passed to dfdt

y0

The initial condition. May appear as a parameter for nls. See details

Dfdt

A function giving the right side of the ODE. Default is dfdt(nlsrk)

dt

Time increment for Runge-Kutta algorithm. Must be lower than the smaller difference between two consecutive t values

graph

If true, plots the graph of the function over the range of t. (For standalone usage)

Details

The vector t must be sorted in increasing order. Any badly placed t will result in an error and program exit. dt must be lower than min(diff(t)). If not, an error will occur. The shorter dt, the more accurate the solution but the longer the calculation will be.

Value

A numeric vector of length equal to the length of t. y[1] is set to y0

Author(s)

Jean-Sebastien Pierre
Jean-s[email protected]

References

Numerical recipes http://www.nr.com

See Also

dfdt,nls

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
	v<-frunge(t=seq(0,50,0.5), param=c(r=0.1,k=100), y0=3, Dfdt = dfdt, dt = 0.01, graph = TRUE)
        plot(seq(0,50,0.5),v)
## 
##     Example of model fitting with frunge. a : determined initial condition 
##
data(logis)
attach(logis)
nls(y~frunge(time,c(r,k),y0=3,dfdt,graph=FALSE),data=logis,start=list(r=0.05,k=100),trace=TRUE)->m1
plot(time,y)
lines(time,fitted(m1))
summary(m1)
detach(logis)
## 
##     Example of model fitting with frunge. b : unknown initial condition ; 
##     y0 is fitted as a parameter

## Not run: data(logis)
attach(logis)
nls(y~frunge(time,c(r,k,y0),y0,dfdt,graph=FALSE),data=logis,start=list(r=0.05,k=100,y0=y[1]),
    trace=TRUE)->m2
plot(time,y)
lines(time,fitted(m2))
summary(m1)
detach(logis)
## End(Not run)

nlsrk documentation built on June 24, 2017, 1:02 a.m.