📄 ode-initval.texi
字号:
\afterdisplay
@end tex
@ifinfo
@example
h_new = h_old * S * (E/D)^(1/(q+1))
@end example
@end ifinfo
@noindent
This encompasses all the standard error scaling methods.
@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 local
error on each step within an absolute error of @var{eps_abs} and
relative 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 local
error on each step within an absolute error of @var{eps_abs} and
relative error of @var{eps_rel} with respect to the derivatives of the
solution @math{y'_i(t)} . This is equivalent to the standard control
object 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 algorithm
as @code{gsl_odeiv_control_standard_new} but with an absolute error
which 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
@example
D_i = eps_abs * s_i + eps_rel * (a_y |y_i| + a_dydt h |y'_i|)
@end example
@end ifinfo
@noindent
where @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 a
control function of type @var{T}. This function is only needed for
defining new types of control functions. For most purposes the standard
control 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 the
parameters @var{eps_abs} (absolute error), @var{eps_rel} (relative
error), @var{a_y} (scaling factor for y) and @var{a_dydt} (scaling
factor 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 order
of the method. If the error in the y-values @var{yerr} is found to be
too 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. The
function returns @code{GSL_ODEIV_HADJ_NIL} if the step-size is
unchanged. The goal of the function is to estimate the largest
step-size which satisfies the user-specified accuracy requirements for
the 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,
@example
printf ("control method is '%s'\n",
gsl_odeiv_control_name (c));
@end example
@noindent
would print something like @code{control method is 'standard'}
@end deftypefun
@node Evolution
@section Evolution
The highest level of the system is the evolution function which combines
the results of a stepping function and control function to reliably
advance the solution forward over an interval @math{(t_0, t_1)}. If the
control function signals that the step-size should be decreased the
evolution function backs out of the current step and tries the proposed
smaller step-size. This process is continued until an acceptable
step-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 an
evolution 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 modified
using the control function @var{c} to achieve the appropriate error
bound if necessary. The routine may make several calls to @var{step} in
order to determine the optimum step-size. If the step-size has been
changed the value of @var{h} will be modified on output. The maximum
time @var{t1} is guaranteed not to be exceeded by the time-step. On the
final time-step the value of @var{t} will be set to @var{t1} exactly.
@end deftypefun
@deftypefun int gsl_odeiv_evolve_reset (gsl_odeiv_evolve * @var{e})
This function resets the evolution function @var{e}. It should be used
whenever the next use of @var{e} will not be a continuation of a
previous 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, example
The following program solves the second-order nonlinear Van der Pol
oscillator equation,
@tex
\beforedisplay
$$
x''(t) + \mu x'(t) (x(t)^2 - 1) + x(t) = 0
$$
\afterdisplay
@end tex
@ifinfo
@example
x''(t) + \mu x'(t) (x(t)^2 - 1) + x(t) = 0
@end example
@end ifinfo
@noindent
This can be converted into a first order system suitable for use with
the routines described in this chapter by introducing a separate
variable for the velocity, @math{y = x'(t)},
@tex
\beforedisplay
$$
\eqalign{
x' &= y\cr
y' &= -x + \mu y (1-x^2)
}
$$
\afterdisplay
@end tex
@ifinfo
@example
x' = y
y' = -x + \mu y (1-x^2)
@end example
@end ifinfo
@noindent
The program begins by defining functions for these derivatives and
their Jacobian,
@example
@verbatiminclude examples/ode-initval.c
@end example
@noindent
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} is
automatically adjusted by the controller to maintain an absolute
accuracy 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
@noindent
To obtain the values at regular intervals, rather than the variable
spacings chosen by the control function, the main loop can be modified
to advance the solution from one point to the next. For example, the
following 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
@noindent
It is also possible to work with a non-adaptive integrator, using only
the stepping function itself. The following program uses the @code{rk4}
fourth-order Runge-Kutta stepping function with a fixed stepsize of
0.01,
@example
@verbatiminclude examples/odefixed.c
@end example
@noindent
The derivatives and jacobian must be initialised for the starting point
@math{t=0} before the first step is taken. Subsequent steps use the
output derivatives @var{dydt_out} as inputs to the next step by copying
their values into @var{dydt_in}.
@node ODE References and Further Reading
@section References and Further Reading
@noindent
Many of the basic Runge-Kutta formulas can be found in the Handbook of
Mathematical Functions,
@itemize @asis
@item
Abramowitz & Stegun (eds.), @cite{Handbook of Mathematical Functions},
Section 25.5.
@end itemize
@noindent
The implicit Bulirsch-Stoer algorithm @code{bsimp} is described in the
following paper,
@itemize @asis
@item
G. Bader and P. Deuflhard, ``A Semi-Implicit Mid-Point Rule for Stiff
Systems of Ordinary Differential Equations.'', Numer. Math. 41, 373-398,
1983.
@end itemize
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -