nlsrk (version 1.1)

frunge: Numeric solution of an ODE (univariate)

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

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)

Value

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

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.

References

Numerical recipes http://www.nr.com

See Also

dfdt,nls

Examples

Run this code
	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

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)

Run the code above in your browser using DataLab