📄 roots.texi
字号:
double t = exp (2 * x);
*f = t;
*df = 2 * t; /* uses existing value */
@}
gsl_function_fdf FDF;
FDF.f = &my_f;
FDF.df = &my_df;
FDF.fdf = &my_fdf;
FDF.params = 0;
@end example
@noindent
The function @math{f(x)} can be evaluated using the following macro,
@example
#define GSL_FN_FDF_EVAL_F(FDF,x)
(*((FDF)->f))(x,(FDF)->params)
@end example
@noindent
The derivative @math{f'(x)} can be evaluated using the following macro,
@example
#define GSL_FN_FDF_EVAL_DF(FDF,x)
(*((FDF)->df))(x,(FDF)->params)
@end example
@noindent
and both the function @math{y = f(x)} and its derivative @math{dy = f'(x)}
can be evaluated at the same time using the following macro,
@example
#define GSL_FN_FDF_EVAL_F_DF(FDF,x,y,dy)
(*((FDF)->fdf))(x,(FDF)->params,(y),(dy))
@end example
@noindent
The macro stores @math{f(x)} in its @var{y} argument and @math{f'(x)} in
its @var{dy} argument -- both of these should be pointers to
@code{double}.
@node Search Bounds and Guesses
@section Search Bounds and Guesses
@cindex root finding, search bounds
@cindex root finding, initial guess
You provide either search bounds or an initial guess; this section
explains how search bounds and guesses work and how function arguments
control them.
A guess is simply an @math{x} value which is iterated until it is within
the desired precision of a root. It takes the form of a @code{double}.
Search bounds are the endpoints of a interval which is iterated until
the length of the interval is smaller than the requested precision. The
interval is defined by two values, the lower limit and the upper limit.
Whether the endpoints are intended to be included in the interval or not
depends on the context in which the interval is used.
@node Root Finding Iteration
@section Iteration
The following functions drive the iteration of each algorithm. Each
function performs one iteration to update the state of any solver of the
corresponding type. The same functions work for all solvers so that
different methods can be substituted at runtime without modifications to
the code.
@deftypefun int gsl_root_fsolver_iterate (gsl_root_fsolver * @var{s})
@deftypefunx int gsl_root_fdfsolver_iterate (gsl_root_fdfsolver * @var{s})
These functions perform a single iteration of the solver @var{s}. If the
iteration encounters an unexpected problem then an error code will be
returned,
@table @code
@item GSL_EBADFUNC
the iteration encountered a singular point where the function or its
derivative evaluated to @code{Inf} or @code{NaN}.
@item GSL_EZERODIV
the derivative of the function vanished at the iteration point,
preventing the algorithm from continuing without a division by zero.
@end table
@end deftypefun
The solver maintains a current best estimate of the root at all
times. The bracketing solvers also keep track of the current best
interval bounding the root. This information can be accessed with the
following auxiliary functions,
@deftypefun double gsl_root_fsolver_root (const gsl_root_fsolver * @var{s})
@deftypefunx double gsl_root_fdfsolver_root (const gsl_root_fdfsolver * @var{s})
These functions return the current estimate of the root for the solver @var{s}.
@end deftypefun
@deftypefun double gsl_root_fsolver_x_lower (const gsl_root_fsolver * @var{s})
@deftypefunx double gsl_root_fsolver_x_upper (const gsl_root_fsolver * @var{s})
These functions return the current bracketing interval for the solver @var{s}.
@end deftypefun
@node Search Stopping Parameters
@section Search Stopping Parameters
@cindex root finding, stopping parameters
A root finding procedure should stop when one of the following conditions is
true:
@itemize @bullet
@item
A root has been found to within the user-specified precision.
@item
A user-specified maximum number of iterations has been reached.
@item
An error has occurred.
@end itemize
@noindent
The handling of these conditions is under user control. The functions
below allow the user to test the precision of the current result in
several standard ways.
@deftypefun int gsl_root_test_interval (double @var{x_lower}, double @var{x_upper}, double @var{epsabs}, double @var{epsrel})
This function tests for the convergence of the interval [@var{x_lower},
@var{x_upper}] with absolute error @var{epsabs} and relative error
@var{epsrel}. The test returns @code{GSL_SUCCESS} if the following
condition is achieved,
@tex
\beforedisplay
$$
|a - b| < \hbox{\it epsabs} + \hbox{\it epsrel\/}\, \min(|a|,|b|)
$$
\afterdisplay
@end tex
@ifinfo
@example
|a - b| < epsabs + epsrel min(|a|,|b|)
@end example
@end ifinfo
@noindent
when the interval @math{x = [a,b]} does not include the origin. If the
interval includes the origin then @math{\min(|a|,|b|)} is replaced by
zero (which is the minimum value of @math{|x|} over the interval). This
ensures that the relative error is accurately estimated for roots close
to the origin.
This condition on the interval also implies that any estimate of the
root @math{r} in the interval satisfies the same condition with respect
to the true root @math{r^*},
@tex
\beforedisplay
$$
|r - r^*| < \hbox{\it epsabs} + \hbox{\it epsrel\/}\, r^*
$$
\afterdisplay
@end tex
@ifinfo
@example
|r - r^*| < epsabs + epsrel r^*
@end example
@end ifinfo
@noindent
assuming that the true root @math{r^*} is contained within the interval.
@end deftypefun
@deftypefun int gsl_root_test_delta (double @var{x1}, double @var{x0}, double @var{epsrel}, double @var{epsabs})
This function tests for the convergence of the sequence @dots{}, @var{x0},
@var{x1} with absolute error @var{epsabs} and relative error
@var{epsrel}. The test returns @code{GSL_SUCCESS} if the following
condition is achieved,
@tex
\beforedisplay
$$
|x_1 - x_0| < \hbox{\it epsabs} + \hbox{\it epsrel\/}\, |x_1|
$$
\afterdisplay
@end tex
@ifinfo
@example
|x_1 - x_0| < epsabs + epsrel |x_1|
@end example
@end ifinfo
@noindent
and returns @code{GSL_CONTINUE} otherwise.
@end deftypefun
@deftypefun int gsl_root_test_residual (double @var{f}, double @var{epsabs})
This function tests the residual value @var{f} against the absolute
error bound @var{epsabs}. The test returns @code{GSL_SUCCESS} if the
following condition is achieved,
@tex
\beforedisplay
$$
|f| < \hbox{\it epsabs}
$$
\afterdisplay
@end tex
@ifinfo
@example
|f| < epsabs
@end example
@end ifinfo
@noindent
and returns @code{GSL_CONTINUE} otherwise. This criterion is suitable
for situations where the precise location of the root, @math{x}, is
unimportant provided a value can be found where the residual,
@math{|f(x)|}, is small enough.
@end deftypefun
@comment ============================================================
@node Root Bracketing Algorithms
@section Root Bracketing Algorithms
The root bracketing algorithms described in this section require an
initial interval which is guaranteed to contain a root -- if @math{a}
and @math{b} are the endpoints of the interval then @math{f(a)} must
differ in sign from @math{f(b)}. This ensures that the function crosses
zero at least once in the interval. If a valid initial interval is used
then these algorithm cannot fail, provided the function is well-behaved.
Note that a bracketing algorithm cannot find roots of even degree, since
these do not cross the @math{x}-axis.
@deffn {Solver} gsl_root_fsolver_bisection
@cindex bisection algorithm for finding roots
@cindex root finding, bisection algorithm
The @dfn{bisection algorithm} is the simplest method of bracketing the
roots of a function. It is the slowest algorithm provided by
the library, with linear convergence.
On each iteration, the interval is bisected and the value of the
function at the midpoint is calculated. The sign of this value is used
to determine which half of the interval does not contain a root. That
half is discarded to give a new, smaller interval containing the
root. This procedure can be continued indefinitely until the interval is
sufficiently small.
At any time the current estimate of the root is taken as the midpoint of
the interval.
@comment eps file "roots-bisection.eps"
@iftex
@sp 1
@center @image{roots-bisection,3.4in}
@quotation
Four iterations of bisection, where @math{a_n} is @math{n}th position of
the beginning of the interval and @math{b_n} is the @math{n}th position
of the end. The midpoint of each interval is also indicated.
@end quotation
@end iftex
@end deffn
@comment ============================================================
@deffn {Solver} gsl_root_fsolver_falsepos
@cindex false position algorithm for finding roots
@cindex root finding, false position algorithm
The @dfn{false position algorithm} is a method of finding roots based on
linear interpolation. Its convergence is linear, but it is usually
faster than bisection.
On each iteration a line is drawn between the endpoints @math{(a,f(a))}
and @math{(b,f(b))} and the point where this line crosses the
@math{x}-axis taken as a ``midpoint''. The value of the function at
this point is calculated and its sign is used to determine which side of
the interval does not contain a root. That side is discarded to give a
new, smaller interval containing the root. This procedure can be
continued indefinitely until the interval is sufficiently small.
The best estimate of the root is taken from the linear interpolation of
the interval on the current iteration.
@comment eps file "roots-false-position.eps"
@comment @iftex
@comment @image{roots-false-position,4in}
@comment @quotation
@comment Several iterations of false position, where @math{a_n} is @math{n}th
@comment position of the beginning of the interval and @math{b_n} is the
@comment @math{n}th position of the end.
@comment @end quotation
@comment @end iftex
@end deffn
@comment ============================================================
@deffn {Solver} gsl_root_fsolver_brent
@cindex brent's method for finding roots
@cindex root finding, brent's method
The @dfn{Brent-Dekker method} (referred to here as @dfn{Brent's method})
combines an interpolation strategy with the bisection algorithm. This
produces a fast algorithm which is still robust.
On each iteration Brent's method approximates the function using an
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -