runsteady(rootSolve)
runsteady()所属R语言包:rootSolve
Dynamically runs a system of ordinary differential equations (ODE) to steady-state
动态稳态运行系统的常微分方程(ODE)
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Solves the steady-state condition of ordinary differential equations (ODE) in the form:
解决了稳态条件下的常微分方程(ODE)的形式:
by dynamically running till the summed absolute values of the derivatives become smaller than some predefined tolerance.
通过动态地运行,直到该衍生物的求和的绝对值变得小于一些预定义的公差。
The R function runsteady makes use of the FORTRAN ODE solver DLSODE, written by Alan C. Hindmarsh and Andrew H. Sherman
R的功能runsteady使用在FORTRAN ODE求解器DLSODE的,写的艾伦·C.欣德马什和安德鲁·谢尔曼
The system of ODE's is written as an R function or defined in compiled code that has been dynamically loaded. The user has to specify whether or not the problem is stiff and choose the appropriate solution method (e.g. make choices about the type of the Jacobian).
该系统的ODE的书面一个R函数或定义在编译的代码已被动态加载。用户必须指定与否的问题是僵硬的,并选择适当的解决方法(例如,选择的类型的雅可比)。
用法----------Usage----------
runsteady(y, times = c(0, Inf), func, parms,
stol = 1e-8, rtol = 1e-6, atol = 1e-6,
jacfunc = NULL, jactype = "fullint", mf = NULL,
verbose = FALSE, tcrit = NULL, hmin = 0, hmax = NULL,
hini = 0, ynames = TRUE, maxord = NULL, bandup = NULL,
banddown = NULL, maxsteps = 100000, dllname = NULL,
initfunc = dllname, initpar = parms, rpar = NULL,
ipar = NULL, nout = 0, outnames = NULL,
forcings = NULL, initforc = NULL, fcontrol = NULL, ...)
参数----------Arguments----------
参数:y
the initial (state) values for the ODE system. If y has a name attribute, the names will be used to label the output matrix.
初始值(州)的ODE系统。 y如果有一个name属性,名称将被用于标记输出矩阵。
参数:times
The simulation time. This should be a 2-valued vector, consisting of the initial time and the end time. The last time value should be large enough to make sure that steady-state is effectively reached in this period. The simulation will stop either when times[2] has been reached or when maxsteps have been performed.
仿真时间。这应该是一个2 - 值的矢量,组成的起始时间和结束时间。的最后的时间值应足够大,以确保在此期间被有效地达到稳态。在模拟将停止times[2]已达到或当maxsteps已经进行了的。
参数:func
either an R-function that computes the values of the derivatives in the ODE system (the model definition) at time t, or a character string giving the name of a compiled function in a dynamically loaded shared library. If func is an R-function, it must be defined as: yprime = func(t, y, parms,...). t is the current time point in the integration, y is the current estimate of the variables in the ODE system. If the initial values y has a names attribute, the names will be available inside func. parms is a vector or list of parameters; ... (optional) are any other arguments passed to the function. The return value of func should be a list, whose first element is a vector containing the derivatives of y with respect to time, and whose next elements are global values that are required at each point in times. The derivatives should be specified in the same order as the state variables y.
可以是R-函数计算的值的ODE系统(模型定义)在时间t的,或者是一个字符串给出一个编译功能的一个动态加载的共享库的名称中的衍生物。如果func是一个R-函数,它必须被定义为:yprime = func(t, y, parms,...)。 t是当前时间点的整合,y是目前估计的ODE系统中的变量。如果初始值y有一个名称属性,名称将是提供内func。 parms是一个向量或参数列表; (可选)传递给函数的任何其他参数。 func的返回值应该是一个列表的第一个元素是一个向量包含y的衍生工具就time,而其下一个元素是全球性的,需要在每个值点的times。衍生工具应以相同的顺序指定的作为状态变量y。
参数:parms
vector or list of parameters used in func or jacfunc.
矢量或在func或jacfunc使用的参数列表。
参数:stol
steady-state tolerance; it is assumed that steady-state is reached if the average of absolute values of the derivatives drops below this number.
稳态容忍,它假定,在达到稳定状态,如果低于此数值的平均值的绝对值的衍生物。
参数:rtol
relative error tolerance of integrator, either a scalar or an array as long as y. See details.
相对误差的积分,只要y一个标量或数组。查看详细信息。
参数:atol
absolute error tolerance of integrator, either a scalar or an array as long as y. See details.
绝对误差的积分,一个标量或数组只要y。查看详细信息。
参数:jacfunc
if not NULL, an R function that computes the jacobian of the system of differential equations dydot(i)/dy(j), or a string giving the name of a function or subroutine in "dllname" that computes the jacobian (see Details below for more about this option). In some circumstances, supplying jacfunc can speed up the computations, if the system is stiff. The R calling sequence for jacfunc is identical to that of func. If the jacobian is a full matrix, jacfunc should return a matrix dydot/dy, where the ith row contains the derivative of dy_i/dt with respect to y_j, or a vector containing the matrix elements by columns (the way R and Fortran store matrices). If the jacobian is banded, jacfunc should return a matrix containing only the nonzero bands of the jacobian, rotated row-wise. See first example of lsode.
如果不是NULL,一个R函数来计算的雅可比系统的微分方程dydot(I)/ DY(J),或一个字符串中的一个函数或子程序的名称dllname “计算雅可比(有关此选项的更多信息,请参阅下面的详细信息)。在某些情况下,提供jacfunc可以加快计算,如果系统是僵硬的。的R调用jacfunc的序列是相同的func。如果雅可比是一个完整的矩阵,jacfunc应该返回一个矩阵dydot / DY,其中第i行包含衍生工具的dy_i/dty_j,或一个向量,包含矩阵元素列的方式(R和Fortran的商店矩阵)。如果是带状的雅可比,jacfunc应该返回一个只包含非零带的雅可比矩阵,逐行旋转。见示例的lsode。
参数:jactype
the structure of the jacobian, one of "fullint", "fullusr", "bandusr" or "bandint" - either full or banded and estimated internally or by user; overruled if mf is not NULL.
的雅可比,“fullint”之一中,“fullusr”,“bandusr”或“bandint” - 无论是全部或带状和估计内部或由用户;的结构如果推翻mf是不是NULL。
参数:mf
the "method flag" passed to function lsode - overrules jactype - provides more options than jactype - see details.
法“标志”通过功能lsode - 驳回jactype - 比jactype - 详情请参阅提供了更多的选择。
参数:verbose
if TRUE: full output to the screen, e.g. will output the settings of vectors *istate* and *rstate* - see details.
如果TRUE:完整的输出到屏幕上,例如将输出设置向量istate *和* rstate时* - 见细节。
参数:tcrit
if not NULL, then lsode cannot integrate past tcrit. The Fortran routine lsode overshoots its targets (times points in the vector times), and interpolates values for the desired time points. If there is a time beyond which integration should not proceed (perhaps because of a singularity), that should be provided in tcrit.
如果没有NULL,那么lsode不能整合过去tcrit。 Fortran例程lsode过冲的目标(次向量的点times),和插补值所需的时间点。如果有时间,超过这个整合不应该继续(也许是因为奇点),应提供在tcrit。
参数:hmin
an optional minimum value of the integration stepsize. In special situations this parameter may speed up computations with the cost of precision. Don't use hmin if you don't know why!
一个可选的最低值的整合步长。在特殊情况下,这个参数可能会加快运算速度与成本的精确度。不要使用hmin如果你不知道为什么!
参数:hmax
an optional maximum value of the integration stepsize. If not specified, hmax is set to the largest difference in times, to avoid that the simulation possibly ignores short-term events. If 0, no maximal size is specified.
一个可选的最大值的整合的步长。如果未指定,hmax设置为times,以避免可能的模拟忽略短期的事件最大的区别在。如果为0,没有最大尺寸。
参数:hini
initial step size to be attempted; if 0, the initial step size is determined by the solver.
尝试初始步长,如果是0,初始步骤的大小是由求解器确定。
参数:ynames
if FALSE: names of state variables are not passed to function func ; this may speed up the simulation.
如果FALSE:状态变量的名称传递给函数func;这可能加快模拟。
参数:maxord
the maximum order to be allowed. NULL uses the default, i.e. order 12 if implicit Adams method (meth=1), order 5 if BDF method (meth=2). Reduce maxord to save storage space.
最大的顺序就可以了。 NULL使用默认的,即第12号命令,若隐亚当斯法(甲基= 1),5阶BDF方法(甲基= 2)。减少maxord以节省存储空间。
参数:bandup
number of non-zero bands above the diagonal, in case the jacobian is banded.
数量的非零对角线以上频带的情况下,是带状的雅可比。
参数:banddown
number of non-zero bands below the diagonal, in case the jacobian is banded.
对角以下的数量的非零频带的情况下,是带状的雅可比。
参数:maxsteps
maximal number of steps. The simulation will stop either when maxsteps have been performed or when times[2] has been reached.
步骤的最大数目。仿真时,将停止maxsteps已执行或times[2]已经达到。
参数:dllname
a string giving the name of the shared library (without extension) that contains all the compiled function or subroutine definitions refered to in func and jacfunc. See package vignette.
一个字符串,给出共享库(不带扩展名),其中包含所有已编译的函数或子程序定义参考,以func和jacfunc的名称。包小插曲。
参数:initfunc
if not NULL, the name of the initialisation function (which initialises values of parameters), as provided in "dllname". See package vignette.
的初始化功能的名称(初始化的参数的值),如果不为NULL,如设置在dllname。包小插曲。
参数:initpar
only when "dllname" is specified and an initialisation function initfunc is in the dll: the parameters passed to the initialiser, to initialise the common blocks (fortran) or global variables (C, C++).
只有当dllname指定一个初始化函数initfunc是在dll中传递的参数的初始化程序,初始化公共块(FORTRAN)或全局变量(C,C + +) 。
参数:rpar
only when "dllname" is specified: a vector with double precision values passed to the dll-functions whose names are specified by func and jacfunc.
只有当dllname指定一个向量,其双精度值传递的DLL函数的名称所指定的func和jacfunc。
参数:ipar
only when "dllname" is specified: a vector with integer values passed to the dll-functions whose names are specified by func and jacfunc.
只有当dllname指定一个向量,其整数值传递的DLL函数的名称所指定的func和jacfunc。
参数:nout
only used if dllname is specified and the model is defined in compiled code: the number of output variables calculated in the compiled function func, present in the shared library. Note: it is not automatically checked whether this is indeed the number of output variables calculed in the dll - you have to perform this check in the code - See package vignette of deSolve.
只用了如果dllname指定模型的定义在编译后的代码输出的数量计算的变量在编译的函数func,目前在共享库。注意:它不会自动检查是否这是真实的 - 你必须在代码中执行此检查 - 在dll中的输出变量值可以包小插曲deSolve。
参数:outnames
only used if "dllname" is specified and nout > 0: the names of output variables calculated in the compiled function func, present in the shared library.
如果只使用dllname指定和nout> 0:输出计算的变量在编译的函数func,目前在共享库的名字。
参数:forcings
only used if "dllname" is specified: a vector with the forcing function values, or a list with the forcing function data sets, each present as a two-columned matrix, with (time,value); interpolation outside the interval [min(times), max(times)] is done by taking the value at the closest data extreme. This feature is here for compatibility with models defined in compiled code from package deSolve; see deSolve's package vignette "compiledCode".
如果只使用dllname的指定的:与强迫函数值,或与强制函数数据集的列表,每个作为一个两列的矩阵存在,与(时间值)的矢量;插值外分(times),最大(times)是通过在最近的数据极端值。此功能是这里的模型定义在编译后的代码包deSolve的兼容性; deSolve的的包小插曲"compiledCode"。
参数:initforc
if not NULL, the name of the forcing function initialisation function, as provided in "dllname". It MUST be present if forcings has been given a value. See deSolve's package vignette "compiledCode".
如果不是NULL,强制函数初始化函数的名称,设置在dllname。它必须是forcings如果已被赋予了价值。请参阅deSolve的的包小插曲"compiledCode"。
参数:fcontrol
A list of control parameters for the forcing functions. See deSolve's package vignette "compiledCode".
列表控制参数的强制功能。请参阅deSolve的的包小插曲"compiledCode"。
参数:...
additional arguments passed to func and jacfunc allowing this to be a generic function.
额外的参数传递到func和jacfunc这是一个通用的功能。
Details
详细信息----------Details----------
The work is done by the Fortran subroutine dlsode, whose documentation should be consulted for details (it is included as comments in the source file "src/lsode.f"). The implementation is based on the November, 2003 version of lsode, from Netlib.
的工作是由Fortran子程序dlsode,应谘询文件的详细信息(包括注释的源文件src/lsode.f)。的实现是基于2003年十一月,的lsode版本,从Netlib。
Before using runsteady, the user has to decide whether or not the problem is stiff.
在使用runsteady,用户必须决定是否的问题是僵硬。
If the problem is nonstiff, use method flag mf = 10, which selects a nonstiff (Adams) method, no Jacobian used..
如果问题是“非刚性,使用方法标志mf = 10,选择一个非刚性(亚当斯)方法,没有雅可比...
If the problem is stiff, there are four standard choices which can be specified with jactype or mf.
如果问题是激烈的,有四个标准选择可以指定jactype或mf的。
The options for jactype are
该选项jactype是
jactype = "fullint" : a full jacobian, calculated internally by lsode, corresponds to mf=22.
jactype =“fullint”:一个完整的雅可比,内部lsode计算,对应的mf = 22。
jactype = "fullusr" : a full jacobian, specified by user function jacfunc, corresponds to mf=21.
jactype =“fullusr”:一个完整的雅可比,指定的用户功能jacfunc,对应于mf= 21。
jactype = "bandusr" : a banded jacobian, specified by user function jacfunc; the size of the bands specified by bandup and banddown, corresponds to mf=24.
jactype =“bandusr”:一个带状的雅可比,由用户指定的功能等jacfunc;由bandup和banddown指定的频带的大小,对应于mf= 24。
jactype = "bandint" : a banded jacobian, calculated by lsode; the size of the bands specified by bandup and banddown, corresponds to mf=25.
jactype =“bandint”:一个带状的雅可比矩阵,计算出lsode指定的bandup和banddown的乐队的大小,对应于mf= 25。
More options are available when specifying mf directly.
直接指定MF时有了更多的选择。
The legal values of mf are 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25.
mf的合法值是10,11,12,13,14,15,20,21,22,23,24,25。
mf is a positive two-digit integer, mf = (10*METH + MITER), where
mf是一个积极的两位数的整数,mf=(10 * METH + MITER),其中
METH indicates the basic linear multistep method: METH = 1 means the implicit Adams method. METH = 2 means the method based on backward differentiation formulas (BDF-s).
METH表示基本的线性多步方法:METH = 1表示隐式亚当斯的方法。 METH = 2表示方法的基础上向后微分公式(BDF-S)。
MITER indicates the corrector iteration method: MITER = 0 means functional iteration (no Jacobian matrix is involved). MITER = 1 means chord iteration with a user-supplied full (NEQ by NEQ) Jacobian. MITER = 2 means chord iteration with an internally generated (difference quotient) full Jacobian (using NEQ extra calls to func per df/dy value). MITER = 3 means chord iteration with an internally generated diagonal Jacobian approximation (using 1 extra call to func per df/dy evaluation). MITER = 4 means chord iteration with a user-supplied banded Jacobian. MITER = 5 means chord iteration with an internally generated banded Jacobian (using ML+MU+1 extra calls to func per df/dy evaluation).
MITER表示校正迭代方法:MITER = 0表示函数迭代(没有雅可比矩阵参与)。 MITER = 1时,意味着和弦用户提供完整的(NEQ由NEQ)的雅可比迭代。 MITER = 2是指和弦迭代与内部产生的(差商)完整的雅可比(NEQ额外调用func每DF / DY价值的)。 MITER = 3是指和弦迭代内部产生的对角的雅可比逼近(使用1张额外的调用到func每DF / DY评估的的)。 MITER = 4表示和弦用户提供的带状雅可比迭代。 MITER = 5时,意味着和弦迭代与内部产生的带状雅可比(使用ML + MU +1额外调用func每DF / DY评价的)。
If MITER = 1 or 4, the user must supply a subroutine jacfunc.
如果MITER = 1或4时,用户必须提供一个子程序jacfunc。
Inspection of the example below shows how to specify both a banded and full jacobian.
检查下面的例子展示了如何指定一个带状的和全面的雅可比。
The input parameters rtol, and atol determine the error control performed by the solver.
的输入参数rtol和atol确定错误的求解器进行控制。
See stode for details.
见stode的详细信息。
Models may be defined in compiled C or Fortran code, as well as in an R-function. See function stode for details.
模型可以定义在编译的C或Fortran代码,以及在R-函数。函数stode的详细信息。
The output will have the attributes *istate*, and *rstate*, two vectors with several useful elements.
输出的属性istate *,* rstate时,两个向量与一些有用的元素。
if verbose = TRUE, the settings of istate and rstate will be written to the screen.
如果verbose= TRUE,设置的istate和rstate时会被写入到屏幕上。
the following elements of istate are meaningful:
以下的istate元素是有意义的:
el 1 : gives the conditions under which the last call to the integrator returned. 2 if lsode was successful, -1 if excess work done, -2 means excess accuracy requested. (Tolerances too small), -3 means illegal input detected. (See printed message.), -4 means repeated error test failures. (Check all input), -5 means repeated convergence failures. (Perhaps bad Jacobian supplied or wrong choice of MF or tolerances.), -6 means error weight became zero during problem. (Solution component i vanished, and atol or atol(i) = 0.)
EL 1给出了在何种条件下返回到积分的最后一次通话。 2,如果lsode如果多余的工作是成功的,-1,-2要求多余的准确性。 (公差太小),-3表示检测到非法输入。 (请参阅打印的消息。)-4表示重复的错误的测试失败。 (检查所有的输入),-5表示重复的收敛失败。 (也许是坏的雅可比矩阵提供的或错误的选择的MF或公差。),-6表示误差权重为零过程中的问题。 (溶液组分我消失了,ATOL或ATOL(I)= 0)。
el 12 : The number of steps taken for the problem so far.
埃尔12:问题迄今采取的步骤的数目。
el 13 : The number of evaluations for the problem so far.,
EL 13:评价的问题为止。
el 14 : The number of Jacobian evaluations and LU decompositions so far.,
EL 14:雅可比评价和LU分解的数量为止。
el 15 : The method order last used (successfully).,
EL 15的方法,最后使用的(成功)。
el 16 : The order to be attempted on the next step.,
EL 16:为了要尝试下一个步骤。
el 17 : if el 1 =-4,-5: the largest component in the error vector,
如果厄尔尼诺EL 17:1 = -4,-5的误差矢量的最大组成部分,
rstate contains the following:
rstate时包含以下内容:
1: The step size in t last used (successfully).
1:最后一次使用的步长吨(成功地)。
2: The step size to be attempted on the next step.
2:上尝试下一个步骤的步长大小。
3: The current value of the independent variable which the solver has actually reached, i.e. the current internal mesh point in t.
3:独立变量的当前值的求解实际上已经达到,即目前的内部网格点在t。
4: A tolerance scale factor, greater than 1.0, computed when a request for too much accuracy was detected.
4:公差比例因子,大于1.0,太多的精度检测到一个请求时,计算。
For more information, see the comments in the original code lsode.f
欲了解更多信息,请参阅在原代码lsode.f的评论
值----------Value----------
A list containing
一个列表,其中包含
参数:y
a vector with the state variable values from the last iteration during estimation of steady-state condition of the system of equations. If y has a names attribute, it will be used to label the output values.
从最后一次迭代在估算过程中的方程系统的稳态状况的状态变量值的一个矢量。如果y有一个名称属性,它会被用来标注的输出值。
参数:...
the number of "global" values returned.
返回的“全球性”的价值观。
The output will have the attribute steady, which returns TRUE, if steady-state has been reached, the attribute precis with the precision attained at the last iteration estimated as the mean absolute rate of change (sum(abs(dy))/n), the attribute time with the simulation time reached and the attribute steps with the number of steps performed.
输出将具有steady,它返回的属性TRUE,如果已达到稳定状态,则该属性precis作为平均绝对率在最后一次迭代估计达到的精度变化(总和(绝对(DY))/ n)的,属性time与模拟时间达到和属性steps执行的步骤的数目。
The output will also have the attributes istate, and rstate, two vectors with several useful elements of the dynamic simulation. See details. The first element of istate returns the conditions under which the last call to the integrator returned. Normal is istate[1] = 2. If verbose = TRUE, the settings of istate and rstate will be written to the screen.
的输出也将具有的属性istate,rstate,两个向量的动态模拟与一些有用的元素。查看详细信息。第一个元素的istate返回的条件下,返回到积分的最后一次通话。正常是istate[1] = 2。如果verbose=TRUE,设置的istate和rstate时会被写入到屏幕上。
(作者)----------Author(s)----------
Karline Soetaert <karline.soetaert@nioz.nl>
参考文献----------References----------
Solvers," in Scientific Computing, R. S. Stepleman, et al., Eds.
参见----------See Also----------
steady, for a general interface to most of the steady-state solvers
steady,一个通用的接口,大部分的稳态解算器
steady.band, to find the steady-state of ODE models with a banded Jacobian
steady.band,找到稳定状态的ODE模型的一个带状的雅可比
steady.1D, steady.2D, steady.3D steady-state solvers for 1-D, 2-D and 3-D partial differential equations.
steady.1D,steady.2D,steady.3D1-D,2-D和3-D偏微分方程的稳态解算器。
stode, iterative steady-state solver for ODEs with full or banded Jacobian.
stode,常微分方程全部或带状雅可比迭代稳态解算器。
stodes, iterative steady-state solver for ODEs with arbitrary sparse Jacobian.
stodes,常微分方程任意稀疏Jacobian迭代稳态解算器。
实例----------Examples----------
## =======================================================================[#================================================= ======================]
## A simple sediment biogeochemical model[#一个简单的沉积物生物地球化学模型]
## =======================================================================[#================================================= ======================]
model<-function(t, y, pars) {
with (as.list(c(y, pars)),{
Min = r*OM
oxicmin = Min*(O2/(O2+ks))
anoxicmin = Min*(1-O2/(O2+ks))* SO4/(SO4+ks2)
dOM = Flux - oxicmin - anoxicmin
dO2 = -oxicmin -2*rox*HS*(O2/(O2+ks)) + D*(BO2-O2)
dSO4 = -0.5*anoxicmin +rox*HS*(O2/(O2+ks)) + D*(BSO4-SO4)
dHS = 0.5*anoxicmin -rox*HS*(O2/(O2+ks)) + D*(BHS-HS)
list(c(dOM, dO2, dSO4, dHS), SumS = SO4+HS)
})
}
# parameter values[参数值]
pars <- c(D = 1, Flux = 100, r = 0.1, rox = 1,
ks = 1, ks2 = 1, BO2 = 100, BSO4 = 10000, BHS = 0)
# initial conditions[初始条件]
y <- c(OM = 1, O2 = 1, SO4 = 1, HS = 1)
# direct iteration[直接迭代]
print( system.time(
ST <- stode(y = y, func = model, parms = pars, pos = TRUE)
))
print( system.time(
ST2 <- runsteady(y = y, func = model, parms = pars, times = c(0, 1000))
))
rbind("Newton Raphson" = ST$y, "Runsteady" = ST2$y)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|