📄 ode-initval.texi
字号:
@cindex differential equations, initial value problems@cindex initial value problems, differential equations@cindex ordinary differential equations, initial value problem@cindex ODEs, initial value problemsThis chapter describes functions for solving ordinary differentialequation (ODE) initial value problems. The library provides a varietyof low-level methods, such as Runge-Kutta and Bulirsch-Stoer routines,and higher-level components for adaptive step-size control. Thecomponents can be combined by the user to achieve the desired solution,with full access to any intermediate steps.These functions are declared in the header file @file{gsl_odeiv.h}.@menu* Defining the ODE System:: * Stepping Functions:: * Adaptive Step-size Control:: * Evolution:: * ODE Example programs:: * ODE References and Further Reading:: @end menu@node Defining the ODE System@section Defining the ODE SystemThe routines solve the general @math{n}-dimensional first-order system,@tex\beforedisplay$${dy_i(t) \over dt} = f_i (t, y_1(t), \dots y_n(t))$$\afterdisplay@end tex@ifinfo@exampledy_i(t)/dt = f_i(t, y_1(t), ..., y_n(t))@end example@end ifinfo@noindentfor @math{i = 1, \dots, n}. The stepping functions rely on the vectorof derivatives @math{f_i} and the Jacobian matrix, @c{$J_{ij} = \partial f_i(t, y(t)) / \partial y_j$}@math{J_@{ij@} = df_i(t,y(t)) / dy_j}. A system of equations is defined using the @code{gsl_odeiv_system}datatype.@deftp {Data Type} gsl_odeiv_systemThis data type defines a general ODE system with arbitrary parameters.@table @code@item int (* function) (double t, const double y[], double dydt[], void * params)This function should store the vector elements@c{$f_i(t,y,\hbox{\it params})$}@math{f_i(t,y,params)} in the array @var{dydt},for arguments (@var{t},@var{y}) and parameters @var{params}.The function should return @code{GSL_SUCCESS} if the calculation was completed successfully. Any other return value indicatesan error.@item int (* jacobian) (double t, const double y[], double * dfdy, double dfdt[], void * params);This function should store the vector of derivative elements @c{$\partial f_i(t,y,params) / \partial t$}@math{df_i(t,y,params)/dt} in the array @var{dfdt} and the Jacobian matrix @c{$J_{ij}$}@math{J_@{ij@}} in the array@var{dfdy}, regarded as a row-ordered matrix @code{J(i,j) = dfdy[i * dimension + j]}where @code{dimension} is the dimension of the system.The function should return @code{GSL_SUCCESS} if the calculation was completed successfully. Any other return value indicatesan error.Some of the simpler solver algorithms do not make use of the Jacobianmatrix, so it is not always strictly necessary to provide it (the@code{jacobian} element of the struct can be replaced by a null pointerfor those algorithms). However, it is useful to provide the Jacobian to allowthe solver algorithms to be interchanged---the best algorithms make useof the Jacobian.@item size_t dimension;This is the dimension of the system of equations.@item void * paramsThis is a pointer to the arbitrary parameters of the system.@end table@end deftp@node Stepping Functions@section Stepping FunctionsThe lowest level components are the @dfn{stepping functions} whichadvance a solution from time @math{t} to @math{t+h} for a fixedstep-size @math{h} and estimate the resulting local error.@deftypefun {gsl_odeiv_step *} gsl_odeiv_step_alloc (const gsl_odeiv_step_type * @var{T}, size_t @var{dim})This function returns a pointer to a newly allocated instance of astepping function of type @var{T} for a system of @var{dim} dimensions.@end deftypefun@deftypefun int gsl_odeiv_step_reset (gsl_odeiv_step * @var{s})This function resets the stepping function @var{s}. It should be usedwhenever the next use of @var{s} will not be a continuation of aprevious step.@end deftypefun@deftypefun void gsl_odeiv_step_free (gsl_odeiv_step * @var{s})This function frees all the memory associated with the stepping function@var{s}.@end deftypefun@deftypefun {const char *} gsl_odeiv_step_name (const gsl_odeiv_step * @var{s})This function returns a pointer to the name of the stepping function.For example,@exampleprintf ("step method is '%s'\n", gsl_odeiv_step_name (s));@end example@noindentwould print something like @code{step method is 'rk4'}.@end deftypefun@deftypefun {unsigned int} gsl_odeiv_step_order (const gsl_odeiv_step * @var{s})This function returns the order of the stepping function on the previousstep. This order can vary if the stepping function itself is adaptive.@end deftypefun@deftypefun int gsl_odeiv_step_apply (gsl_odeiv_step * @var{s}, double @var{t}, double @var{h}, double @var{y}[], double @var{yerr}[], const double @var{dydt_in}[], double @var{dydt_out}[], const gsl_odeiv_system * @var{dydt})This function applies the stepping function @var{s} to the system ofequations defined by @var{dydt}, using the step size @var{h} to advancethe system from time @var{t} and state @var{y} to time @var{t}+@var{h}.The new state of the system is stored in @var{y} on output, with anestimate of the absolute error in each component stored in @var{yerr}.If the argument @var{dydt_in} is not null it should point an arraycontaining the derivatives for the system at time @var{t} on input. Thisis optional as the derivatives will be computed internally if they arenot provided, but allows the reuse of existing derivative information.On output the new derivatives of the system at time @var{t}+@var{h} willbe stored in @var{dydt_out} if it is not null.If the user-supplied functions defined in the system @var{dydt} return astatus other than @code{GSL_SUCCESS} the step will be aborted. In thiscase, the elements of @var{y} will be restored to their pre-step valuesand the error code from the user-supplied function will be returned. Todistinguish between error codes from the user-supplied functions andthose from @code{gsl_odeiv_step_apply} itself, any user-defined returnvalues should be distinct from the standard GSL error codes.@end deftypefunThe following algorithms are available,@deffn {Step Type} gsl_odeiv_step_rk2@cindex RK2, Runge-Kutta method@cindex Runge-Kutta methods, ordinary differential equationsEmbedded Runge-Kutta (2, 3) method.@end deffn@deffn {Step Type} gsl_odeiv_step_rk4@cindex RK4, Runge-Kutta method4th order (classical) Runge-Kutta.@end deffn@deffn {Step Type} gsl_odeiv_step_rkf45@cindex Fehlberg method, differential equations@cindex RKF45, Runge-Kutta-Fehlberg methodEmbedded Runge-Kutta-Fehlberg (4, 5) method. This method is a goodgeneral-purpose integrator.@end deffn@deffn {Step Type} gsl_odeiv_step_rkck @cindex Runge-Kutta Cash-Karp method@cindex Cash-Karp, Runge-Kutta methodEmbedded Runge-Kutta Cash-Karp (4, 5) method.@end deffn@deffn {Step Type} gsl_odeiv_step_rk8pd @cindex Runge-Kutta Prince-Dormand method@cindex Prince-Dormand, Runge-Kutta methodEmbedded Runge-Kutta Prince-Dormand (8,9) method.@end deffn@deffn {Step Type} gsl_odeiv_step_rk2imp Implicit 2nd order Runge-Kutta at Gaussian points.@end deffn@deffn {Step Type} gsl_odeiv_step_rk4imp Implicit 4th order Runge-Kutta at Gaussian points.@end deffn@deffn {Step Type} gsl_odeiv_step_bsimp @cindex Bulirsch-Stoer method@cindex Bader and Deuflhard, Bulirsch-Stoer method.@cindex Deuflhard and Bader, Bulirsch-Stoer method.Implicit Bulirsch-Stoer method of Bader and Deuflhard. This algorithmrequires the Jacobian.@end deffn@deffn {Step Type} gsl_odeiv_step_gear1 @cindex Gear method, differential equationsM=1 implicit Gear method.@end deffn@deffn {Step Type} gsl_odeiv_step_gear2 M=2 implicit Gear method.@end deffn@node Adaptive Step-size Control@section Adaptive Step-size Control@cindex Adaptive step-size control, differential equationsThe control function examines the proposed change to the solutionproduced by a stepping function and attempts to determine the optimalstep-size for a user-specified level of error.@deftypefun {gsl_odeiv_control *} gsl_odeiv_control_standard_new (double @var{eps_abs}, double @var{eps_rel}, double @var{a_y}, double @var{a_dydt})The standard control object is a four parameter heuristic based onabsolute and relative errors @var{eps_abs} and @var{eps_rel}, andscaling factors @var{a_y} and @var{a_dydt} for the system state@math{y(t)} and derivatives @math{y'(t)} respectively.The step-size adjustment procedure for this method begins by computingthe desired error level @math{D_i} for each component,@tex\beforedisplay$$D_i = \epsilon_{abs} + \epsilon_{rel} * (a_{y} |y_i| + a_{dydt} h |y'_i|)$$\afterdisplay@end tex@ifinfo@exampleD_i = eps_abs + eps_rel * (a_y |y_i| + a_dydt h |y'_i|)@end example@end ifinfo@noindentand comparing it with the observed error @math{E_i = |yerr_i|}. If theobserved error @var{E} exceeds the desired error level @var{D} by morethan 10% for any component then the method reduces the step-size by anappropriate factor,@tex\beforedisplay$$h_{new} = h_{old} * S * (E/D)^{-1/q}$$\afterdisplay@end tex@ifinfo@exampleh_new = h_old * S * (E/D)^(-1/q)@end example@end ifinfo@noindentwhere @math{q} is the consistency order of the method (e.g. @math{q=4} for4(5) embedded RK), and @math{S} is a safety factor of 0.9. The ratio@math{E/D} is taken to be the maximum of the ratios@math{E_i/D_i}. If the observed error @math{E} is less than 50% of the desired errorlevel @var{D} for the maximum ratio @math{E_i/D_i} then the algorithmtakes the opportunity to increase the step-size to bring the error inline with the desired level,@tex\beforedisplay$$h_{new} = h_{old} * S * (E/D)^{-1/(q+1)}$$\afterdisplay@end tex@ifinfo@example
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -