nlsrk (version 1.1)

evrunge: Numerical Runge-Kutta Solver (multi point, multivariate)

Description

evrunge evaluates the solutions of a system of first order ordinary equations for a given set of values of the independent variable (generally the time).

Usage

evrunge(t, param, y0, sys, dt = 0.01, graph = FALSE, observable = rep(1, length(y0)))

Arguments

t

numerical vector : the values of t at which the ODE system must be evaluated

param

numerical vector or numerical objects list. Passed as arguments to sys

y0

numerical vector : the initial values of the unknown functions to solve

sys

the function giving the right side of the system. Must be written by user (see ?sys)

dt

integration step for Runge-Kutta algorithm. Default = 0.01

graph

optionally : graphic representation of the set of solutions. Default = FALSE

observable

A numeric vector coding what trajectories are observable. 1 = observable, 2 = not observable. Default : a vector of 1, nfunct times

Value

A vector of size nfunct*length(t) where nfunct is the number of equations in sys

Details

This function is intended basically to be used in conjunction with nls for non linear least square fit of a set of ODEs on experimental data. This is the reason why the solutions are concatenated in a single column. For fitting with nls, the data have to be organised in the same way. Use prepare(nlsrk) to convert a data frame with observations in separate columns in one where the columns are concatenated. In a further version of this function, the solutions will optionnaly be provided as columns of an data.frame. The system must be provided by user. See sys for an editable example.

t must be sorted in ascending order and every intervals between two consecutive values of t must be greater then dt. Otherwise, the function stops and an error message is displayed.

Although the algorithm works with dt slightly lower than with min(t[i+1] - t[i]) the accuracy of the results are not guaranted. It is recommanded to chose with dt fairly lower than the minimum interval in with t See the note below concerning the parameter 'observable'

References

~put references to the literature/web site here ~

See Also

multirunge, sys, prepare, nls

Examples

Run this code
##
##	example 1 : solving and plotting the system sys provided in the package
##
data(syslin.don)
syslin<-prepare(syslin.don)
  evrunge(t=c(1:30),param=c(1,1),y0=c(1000,0),sys=sys,graph=TRUE)
##
##	example 2 : fitting by nls on data \code{syslin} fixed and known initial conditions
##
data(syslin)
attach(syslin)
nls(y~ evrunge(t,param=c(k1,k2),y0=c(1000,0),sys,graph=FALSE),data=syslin,start=list(k1=1,k2=1),
	trace=TRUE)->m1
summary(m1)
detach(syslin)
##
##	example 3 : fitting by nls on data syslin "unknown" initial conditions: 
##                  they have to be fitted as parameters
##
data(syslin)
nls(y~ evrunge(t,param=c(k1,k2,y0),y0,sys,graph=FALSE),data=syslin,start=list(k1=1,k2=1,
	y0=c(1000,0)),trace=TRUE)->m2
summary(m2)
plot.nlsrk(m2,syslin)
##
##	example 4 : fitting by nls on data syslin with known initial conditions: 
##                  There are no observations for the trajectory 1 which is not observable. 
##		    sys is unchanged
##
data(syslin)
##     We eliminate the data corresponding to trajectory 1 and fit only on trajectory 2. 
##     Fixed initial conditions
 syslin2<-syslin[syslin$traj==2,]
 attach(syslin2)
 nls(y~ evrunge(t,param=c(k1,k2),y0=c(1000,0),sys,graph=FALSE,observable=c(0,1)),data=syslin2,
     start=list(k1=1,k2=1),trace=TRUE)->m3
 summary(m3)
 plot.nlsrk(m3,syslin2)
 detach(syslin2)

Run the code above in your browser using DataLab