📄 roots.texi
字号:
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 untilthe length of the interval is smaller than the requested precision. Theinterval is defined by two values, the lower limit and the upper limit.Whether the endpoints are intended to be included in the interval or notdepends on the context in which the interval is used.@node Root Finding Iteration@section IterationThe following functions drive the iteration of each algorithm. Eachfunction performs one iteration to update the state of any solver of thecorresponding type. The same functions work for all solvers so thatdifferent methods can be substituted at runtime without modifications tothe 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 theiteration encounters an unexpected problem then an error code will bereturned,@table @code@item GSL_EBADFUNCthe iteration encountered a singular point where the function or itsderivative evaluated to @code{Inf} or @code{NaN}.@item GSL_EZERODIVthe derivative of the function vanished at the iteration point,preventing the algorithm from continuing without a division by zero.@end table@end deftypefunThe solver maintains a current best estimate of the root at alltimes. The bracketing solvers also keep track of the current bestinterval bounding the root. This information can be accessed with thefollowing 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 parametersA root finding procedure should stop when one of the following conditions istrue:@itemize @bullet@itemA root has been found to within the user-specified precision.@itemA user-specified maximum number of iterations has been reached.@itemAn error has occurred.@end itemize@noindentThe handling of these conditions is under user control. The functionsbelow allow the user to test the precision of the current result inseveral standard ways.@deftypefun int gsl_root_test_interval (double @var{x_lower}, double @var{x_upper}, double @var{epsrel}, double @var{epsabs})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 followingcondition 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@noindentwhen the interval @math{x = [a,b]} does not include the origin. If theinterval includes the origin then @math{\min(|a|,|b|)} is replaced byzero (which is the minimum value of @math{|x|} over the interval). Thisensures that the relative error is accurately estimated for roots closeto the origin.This condition on the interval also implies that any estimate of theroot @math{r} in the interval satisfies the same condition with respectto 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@noindentassuming 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 followingcondition 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@noindentand 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 absoluteerror bound @var{epsabs}. The test returns @code{GSL_SUCCESS} if thefollowing condition is achieved,@tex\beforedisplay$$|f| < \hbox{\it epsabs}$$\afterdisplay@end tex@ifinfo@example|f| < epsabs@end example@end ifinfo@noindentand returns @code{GSL_CONTINUE} otherwise. This criterion is suitablefor situations where the the precise location of the root, @math{x}, isunimportant 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 AlgorithmsThe root bracketing algorithms described in this section require aninitial interval which is guaranteed to contain a root -- if @math{a}and @math{b} are the endpoints of the interval then @math{f(a)} mustdiffer in sign from @math{f(b)}. This ensures that the function crosseszero at least once in the interval. If a valid initial interval is usedthen these algorithm cannot fail, provided the function is well-behaved.Note that a bracketing algorithm cannot find roots of even degree, sincethese do not cross the @math{x}-axis.@deffn {Solver} gsl_root_fsolver_bisection@cindex bisection algorithm for finding roots@cindex root finding, bisection algorithmThe @dfn{bisection algorithm} is the simplest method of bracketing theroots of a function. It is the slowest algorithm provided bythe library, with linear convergence.On each iteration, the interval is bisected and the value of thefunction at the midpoint is calculated. The sign of this value is usedto determine which half of the interval does not contain a root. Thathalf is discarded to give a new, smaller interval containing theroot. This procedure can be continued indefinitely until the interval issufficiently small.At any time the current estimate of the root is taken as the midpoint ofthe interval.@comment eps file "roots-bisection.eps"@iftex@sp 1@center @image{roots-bisection,4in}@quotationFour iterations of bisection, where @math{a_n} is @math{n}th position ofthe beginning of the interval and @math{b_n} is the @math{n}th positionof 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 algorithmThe @dfn{false position algorithm} is a method of finding roots based onlinear interpolation. Its convergence is linear, but it is usuallyfaster 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 atthis point is calculated and its sign is used to determine which side ofthe interval does not contain a root. That side is discarded to give anew, smaller interval containing the root. This procedure can becontinued indefinitely until the interval is sufficiently small.The best estimate of the root is taken from the linear interpolation ofthe 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 methodThe @dfn{Brent-Dekker method} (referred to here as @dfn{Brent's method})combines an interpolation strategy with the bisection algorithm. Thisproduces a fast algorithm which is still robust.On each iteration Brent's method approximates the function using aninterpolating curve. On the first iteration this is a linearinterpolation of the two endpoints. For subsequent iterations thealgorithm uses an inverse quadratic fit to the last three points, forhigher accuracy. The intercept of the interpolating curve with the@math{x}-axis is taken as a guess for the root. If it lies within thebounds of the current interval then the interpolating point is accepted,and used to generate a smaller interval. If the interpolating point isnot accepted then the algorithm falls back to an ordinary bisectionstep.The best estimate of the root is taken from the most recentinterpolation or bisection.@end deffn@comment ============================================================@node Root Finding Algorithms using Derivatives@section Root Finding Algorithms using DerivativesThe root polishing algorithms described in this section require aninitial guess for the location of the root. There is no absoluteguarantee of convergence -- the function must be suitable for thistechnique and the initial guess must be sufficiently close to the rootfor it to work. When these conditions are satisfied then convergence isquadratic.These algorithms make use of both the function and its derivative. @deffn {Derivative Solver} gsl_root_fdfsolver_newton@cindex Newton's Method algorithm for finding roots@cindex root finding, Newton's Method algorithmNewton's Method is the standard root-polishing algorithm. The algorithmbegins with an initial guess for the location of the root. On eachiteration, a line tangent to the function @math{f} is drawn at thatposition. The point where this line crosses the @math{x}-axis becomesthe new guess. The iteration is defined by the following sequence,@tex\beforedisplay$$x_{i+1} = x_i - {f(x_i) \over f'(x_i)}$$\afterdisplay@end tex@ifinfo@examplex_@{i+1@} = x_i - f(x_i)/f'(x_i)@end example@end ifinfo@noindentNewton's method converges quadratically for single roots, and linearlyfor multiple roots.@comment eps file "roots-newtons-method.eps"@iftex@sp 1@center @image{roots-newtons-method,4in}@quotationSeveral iterations of Newton's Method, where @math{g_n} is the@math{n}th guess.@end quotation@end iftex@end deffn@comment ============================================================@deffn {Derivative Solver} gsl_root_fdfsolver_secant@cindex Secant Method algorithm for finding roots@cindex root finding, Secant Method algorithmThe @dfn{secant method} is a simplified version of Newton's method doesnot require the computation of the derivative on every step.On its first iteration the algorithm begins with Newton's method, usingthe derivative to compute a first step,@tex\beforedisplay$$x_1 = x_0 - {f(x_0) \over f'(x_0)}$$\afterdisplay@end tex@ifinfo@examplex_1 = x_0 - f(x_0)/f'(x_0)@end example@end ifinfo@noindentSubsequent iterations avoid the evaluation of the derivative byreplacing it with a numerical estimate, the slope through the previoustwo points,@tex\beforedisplay$$
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -