📄 ode-initval.texi
字号:
h_new = h_old * S * (E/D)^(-1/(q+1))@end example@end ifinfo@noindentThis encompasses all the standard error scaling methods. To avoiduncontrolled changes in the stepsize, the overall scaling factor islimited to the range @math{1/5} to 5.@end deftypefun@deftypefun {gsl_odeiv_control *} gsl_odeiv_control_y_new (double @var{eps_abs}, double @var{eps_rel})This function creates a new control object which will keep the localerror on each step within an absolute error of @var{eps_abs} andrelative error of @var{eps_rel} with respect to the solution @math{y_i(t)}.This is equivalent to the standard control object with @var{a_y}=1 and@var{a_dydt}=0.@end deftypefun@deftypefun {gsl_odeiv_control *} gsl_odeiv_control_yp_new (double @var{eps_abs}, double @var{eps_rel})This function creates a new control object which will keep the localerror on each step within an absolute error of @var{eps_abs} andrelative error of @var{eps_rel} with respect to the derivatives of thesolution @math{y'_i(t)}. This is equivalent to the standard controlobject with @var{a_y}=0 and @var{a_dydt}=1.@end deftypefun@deftypefun {gsl_odeiv_control *} gsl_odeiv_control_scaled_new (double @var{eps_abs}, double @var{eps_rel}, double @var{a_y}, double @var{a_dydt}, const double @var{scale_abs}[], size_t @var{dim})This function creates a new control object which uses the same algorithmas @code{gsl_odeiv_control_standard_new} but with an absolute errorwhich is scaled for each component by the array @var{scale_abs}.The formula for @math{D_i} for this control object is,@tex\beforedisplay$$D_i = \epsilon_{abs} s_i + \epsilon_{rel} * (a_{y} |y_i| + a_{dydt} h |y'_i|)$$\afterdisplay@end tex@ifinfo@exampleD_i = eps_abs * s_i + eps_rel * (a_y |y_i| + a_dydt h |y'_i|)@end example@end ifinfo@noindentwhere @math{s_i} is the @math{i}-th component of the array @var{scale_abs}.The same error control heuristic is used by the Matlab @sc{ode} suite. @end deftypefun@deftypefun {gsl_odeiv_control *} gsl_odeiv_control_alloc (const gsl_odeiv_control_type * @var{T})This function returns a pointer to a newly allocated instance of acontrol function of type @var{T}. This function is only needed fordefining new types of control functions. For most purposes the standardcontrol functions described above should be sufficient. @end deftypefun@deftypefun int gsl_odeiv_control_init (gsl_odeiv_control * @var{c}, double @var{eps_abs}, double @var{eps_rel}, double @var{a_y}, double @var{a_dydt})This function initializes the control function @var{c} with theparameters @var{eps_abs} (absolute error), @var{eps_rel} (relativeerror), @var{a_y} (scaling factor for y) and @var{a_dydt} (scalingfactor for derivatives).@end deftypefun@deftypefun void gsl_odeiv_control_free (gsl_odeiv_control * @var{c})This function frees all the memory associated with the control function@var{c}.@end deftypefun@deftypefun int gsl_odeiv_control_hadjust (gsl_odeiv_control * @var{c}, gsl_odeiv_step * @var{s}, const double @var{y0}[], const double @var{yerr}[], const double @var{dydt}[], double * @var{h})This function adjusts the step-size @var{h} using the control function@var{c}, and the current values of @var{y}, @var{yerr} and @var{dydt}.The stepping function @var{step} is also needed to determine the orderof the method. If the error in the y-values @var{yerr} is found to betoo large then the step-size @var{h} is reduced and the function returns@code{GSL_ODEIV_HADJ_DEC}. If the error is sufficiently small then@var{h} may be increased and @code{GSL_ODEIV_HADJ_INC} is returned. Thefunction returns @code{GSL_ODEIV_HADJ_NIL} if the step-size isunchanged. The goal of the function is to estimate the largeststep-size which satisfies the user-specified accuracy requirements forthe current point.@end deftypefun@deftypefun {const char *} gsl_odeiv_control_name (const gsl_odeiv_control * @var{c})This function returns a pointer to the name of the control function.For example,@exampleprintf ("control method is '%s'\n", gsl_odeiv_control_name (c));@end example@noindentwould print something like @code{control method is 'standard'}@end deftypefun@node Evolution@section EvolutionThe highest level of the system is the evolution function which combinesthe results of a stepping function and control function to reliablyadvance the solution forward over an interval @math{(t_0, t_1)}. If thecontrol function signals that the step-size should be decreased theevolution function backs out of the current step and tries the proposedsmaller step-size. This process is continued until an acceptablestep-size is found.@deftypefun {gsl_odeiv_evolve *} gsl_odeiv_evolve_alloc (size_t @var{dim})This function returns a pointer to a newly allocated instance of anevolution function for a system of @var{dim} dimensions.@end deftypefun@deftypefun int gsl_odeiv_evolve_apply (gsl_odeiv_evolve * @var{e}, gsl_odeiv_control * @var{con}, gsl_odeiv_step * @var{step}, const gsl_odeiv_system * @var{dydt}, double * @var{t}, double @var{t1}, double * @var{h}, double @var{y}[])This function advances the system (@var{e}, @var{dydt}) from time@var{t} and position @var{y} using the stepping function @var{step}.The new time and position are stored in @var{t} and @var{y} on output.The initial step-size is taken as @var{h}, but this will be modifiedusing the control function @var{c} to achieve the appropriate errorbound if necessary. The routine may make several calls to @var{step} inorder to determine the optimum step-size. If the step-size has beenchanged the value of @var{h} will be modified on output. The maximumtime @var{t1} is guaranteed not to be exceeded by the time-step. On thefinal time-step the value of @var{t} will be set to @var{t1} exactly.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, @var{t} and @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_evolve_apply} itself, any user-defined returnvalues should be distinct from the standard GSL error codes.@end deftypefun@deftypefun int gsl_odeiv_evolve_reset (gsl_odeiv_evolve * @var{e})This function resets the evolution function @var{e}. It should be usedwhenever the next use of @var{e} will not be a continuation of aprevious step.@end deftypefun@deftypefun void gsl_odeiv_evolve_free (gsl_odeiv_evolve * @var{e})This function frees all the memory associated with the evolution function@var{e}.@end deftypefun@node ODE Example programs@section Examples@cindex Van der Pol oscillator, exampleThe following program solves the second-order nonlinear Van der Poloscillator equation,@tex\beforedisplay$$x''(t) + \mu x'(t) (x(t)^2 - 1) + x(t) = 0$$\afterdisplay@end tex@ifinfo@examplex''(t) + \mu x'(t) (x(t)^2 - 1) + x(t) = 0@end example@end ifinfo@noindentThis can be converted into a first order system suitable for use withthe routines described in this chapter by introducing a separatevariable for the velocity, @math{y = x'(t)},@tex\beforedisplay$$\eqalign{x' &= y\cry' &= -x + \mu y (1-x^2)}$$\afterdisplay@end tex@ifinfo@examplex' = yy' = -x + \mu y (1-x^2)@end example@end ifinfo@noindentThe program begins by defining functions for these derivatives andtheir Jacobian,@example@verbatiminclude examples/ode-initval.c@end example@noindentFor functions with multiple parameters, the appropriate informationcan be passed in through the @var{params} argument using a pointer toa struct.The main loop of the program evolves the solution from @math{(y, y') =(1, 0)} at @math{t=0} to @math{t=100}. The step-size @math{h} isautomatically adjusted by the controller to maintain an absoluteaccuracy of @c{$10^{-6}$} @math{10^@{-6@}} in the function values @var{y}.@iftex@sp 1@center @image{vdp,3.4in}@center Numerical solution of the Van der Pol oscillator equation @center using Prince-Dormand 8th order Runge-Kutta.@end iftex@noindentTo obtain the values at regular intervals, rather than the variablespacings chosen by the control function, the main loop can be modifiedto advance the solution from one point to the next. For example, thefollowing main loop prints the solution at the fixed points @math{t = 0,1, 2, \dots, 100},@example for (i = 1; i <= 100; i++) @{ double ti = i * t1 / 100.0; while (t < ti) @{ gsl_odeiv_evolve_apply (e, c, s, &sys, &t, ti, &h, y); @} printf ("%.5e %.5e %.5e\n", t, y[0], y[1]); @}@end example@noindentIt is also possible to work with a non-adaptive integrator, using onlythe stepping function itself. The following program uses the @code{rk4}fourth-order Runge-Kutta stepping function with a fixed stepsize of0.01,@example@verbatiminclude examples/odefixed.c@end example@noindentThe derivatives must be initialized for the starting point @math{t=0}before the first step is taken. Subsequent steps use the outputderivatives @var{dydt_out} as inputs to the next step by copying theirvalues into @var{dydt_in}.@node ODE References and Further Reading@section References and Further ReadingMany of the basic Runge-Kutta formulas can be found in the Handbook ofMathematical Functions,@itemize @asis@itemAbramowitz & Stegun (eds.), @cite{Handbook of Mathematical Functions},Section 25.5.@end itemize@noindentThe implicit Bulirsch-Stoer algorithm @code{bsimp} is described in thefollowing paper,@itemize @asis@itemG. Bader and P. Deuflhard, ``A Semi-Implicit Mid-Point Rule for StiffSystems of Ordinary Differential Equations.'', Numer.@: Math.@: 41, 373--398,1983.@end itemize
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -