⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multiroots.texi

📁 开放gsl矩阵运算
💻 TEXI
📖 第 1 页 / 共 3 页
字号:
@cindex solving nonlinear systems of equations@cindex nonlinear systems of equations, solution of@cindex systems of equations, nonlinearThis chapter describes functions for multidimensional root-finding(solving nonlinear systems with @math{n} equations in @math{n}unknowns).  The library provides low level components for a variety ofiterative solvers and convergence tests.  These can be combined by theuser to achieve the desired solution, with full access to theintermediate steps of the iteration.  Each class of methods uses thesame framework, so that you can switch between solvers at runtimewithout needing to recompile your program.  Each instance of a solverkeeps track of its own state, allowing the solvers to be used inmulti-threaded programs.  The solvers are based on the original Fortranlibrary @sc{minpack}.The header file @file{gsl_multiroots.h} contains prototypes for themultidimensional root finding functions and related declarations.@menu* Overview of Multidimensional Root Finding::  * Initializing the Multidimensional Solver::  * Providing the multidimensional system of equations to solve::  * Iteration of the multidimensional solver::  * Search Stopping Parameters for the multidimensional solver::  * Algorithms using Derivatives::  * Algorithms without Derivatives::  * Example programs for Multidimensional Root finding::  * References and Further Reading for Multidimensional Root Finding::  @end menu@node Overview of Multidimensional Root Finding@section Overview@cindex multidimensional root finding, overviewThe problem of multidimensional root finding requires the simultaneoussolution of @math{n} equations, @math{f_i}, in @math{n} variables,@math{x_i},@tex\beforedisplay$$f_i (x_1, \dots, x_n) = 0 \qquad\hbox{for}~i = 1 \dots n.$$\afterdisplay@end tex@ifinfo@examplef_i (x_1, ..., x_n) = 0    for i = 1 ... n.@end example@end ifinfo@noindentIn general there are no bracketing methods available for @math{n}dimensional systems, and no way of knowing whether any solutionsexist.  All algorithms proceed from an initial guess using a variant ofthe Newton iteration,@tex\beforedisplay$$x \to x' = x - J^{-1} f(x)$$\afterdisplay@end tex@ifinfo@examplex -> x' = x - J^@{-1@} f(x)@end example@end ifinfo@noindentwhere @math{x}, @math{f} are vector quantities and @math{J} is theJacobian matrix @c{$J_{ij} = \partial f_i / \partial x_j$} @math{J_@{ij@} = d f_i / d x_j}.Additional strategies can be used to enlarge the region ofconvergence.  These include requiring a decrease in the norm @math{|f|} oneach step proposed by Newton's method, or taking steepest-descent steps inthe direction of the negative gradient of @math{|f|}.Several root-finding algorithms are available within a single framework.The user provides a high-level driver for the algorithms, and thelibrary provides the individual functions necessary for each of thesteps.  There are three main phases of the iteration.  The steps are,@itemize @bullet@iteminitialize solver state, @var{s}, for algorithm @var{T}@itemupdate @var{s} using the iteration @var{T}@itemtest @var{s} for convergence, and repeat iteration if necessary@end itemize@noindentThe evaluation of the Jacobian matrix can be problematic, either becauseprogramming the derivatives is intractable or because computation of the@math{n^2} terms of the matrix becomes too expensive.  For these reasonsthe algorithms provided by the library are divided into two classes accordingto whether the derivatives are available or not.The state for solvers with an analytic Jacobian matrix is held in a@code{gsl_multiroot_fdfsolver} struct.  The updating procedure requiresboth the function and its derivatives to be supplied by the user.The state for solvers which do not use an analytic Jacobian matrix isheld in a @code{gsl_multiroot_fsolver} struct.  The updating procedureuses only function evaluations (not derivatives).  The algorithmsestimate the matrix @math{J} or @c{$J^{-1}$} @math{J^@{-1@}} by approximate methods.@node Initializing the Multidimensional Solver@section Initializing the SolverThe following functions initialize a multidimensional solver, eitherwith or without derivatives.  The solver itself depends only on thedimension of the problem and the algorithm and can be reused fordifferent problems.@deftypefun {gsl_multiroot_fsolver *} gsl_multiroot_fsolver_alloc (const gsl_multiroot_fsolver_type * @var{T}, size_t @var{n})This function returns a pointer to a a newly allocated instance of asolver of type @var{T} for a system of @var{n} dimensions.For example, the following code creates an instance of a hybrid solver, to solve a 3-dimensional system of equations.@exampleconst gsl_multiroot_fsolver_type * T     = gsl_multiroot_fsolver_hybrid;gsl_multiroot_fsolver * s     = gsl_multiroot_fsolver_alloc (T, 3);@end example@noindentIf there is insufficient memory to create the solver then the functionreturns a null pointer and the error handler is invoked with an errorcode of @code{GSL_ENOMEM}.@end deftypefun@deftypefun {gsl_multiroot_fdfsolver *} gsl_multiroot_fdfsolver_alloc (const gsl_multiroot_fdfsolver_type * @var{T}, size_t @var{n})This function returns a pointer to a a newly allocated instance of aderivative solver of type @var{T} for a system of @var{n} dimensions.For example, the following code creates an instance of a Newton-Raphson solver,for a 2-dimensional system of equations.@exampleconst gsl_multiroot_fdfsolver_type * T     = gsl_multiroot_fdfsolver_newton;gsl_multiroot_fdfsolver * s =     gsl_multiroot_fdfsolver_alloc (T, 2);@end example@noindentIf there is insufficient memory to create the solver then the functionreturns a null pointer and the error handler is invoked with an errorcode of @code{GSL_ENOMEM}.@end deftypefun@deftypefun int gsl_multiroot_fsolver_set (gsl_multiroot_fsolver * @var{s}, gsl_multiroot_function * @var{f}, gsl_vector * @var{x})This function sets, or resets, an existing solver @var{s} to use thefunction @var{f} and the initial guess @var{x}.@end deftypefun@deftypefun int gsl_multiroot_fdfsolver_set (gsl_multiroot_fdfsolver * @var{s}, gsl_function_fdf * @var{fdf}, gsl_vector * @var{x})This function sets, or resets, an existing solver @var{s} to use thefunction and derivative @var{fdf} and the initial guess @var{x}.@end deftypefun@deftypefun void gsl_multiroot_fsolver_free (gsl_multiroot_fsolver * @var{s})@deftypefunx void gsl_multiroot_fdfsolver_free (gsl_multiroot_fdfsolver * @var{s})These functions free all the memory associated with the solver @var{s}.@end deftypefun@deftypefun {const char *} gsl_multiroot_fsolver_name (const gsl_multiroot_fsolver * @var{s})@deftypefunx {const char *} gsl_multiroot_fdfsolver_name (const gsl_multiroot_fdfsolver * @var{s})These functions return a pointer to the name of the solver.  For example,@exampleprintf("s is a '%s' solver\n",        gsl_multiroot_fdfsolver_name (s));@end example@noindentwould print something like @code{s is a 'newton' solver}.@end deftypefun@node Providing the multidimensional system of equations to solve@section Providing the function to solve@cindex multidimensional root finding, providing a function to solveYou must provide @math{n} functions of @math{n} variables for the rootfinders to operate on.  In order to allow for general parameters thefunctions are defined by the following data types:@deftp {Data Type} gsl_multiroot_function This data type defines a general system of functions with parameters.@table @code@item int (* f) (const gsl_vector * @var{x}, void * @var{params}, gsl_vector * @var{f})this function should store the vector result@c{$f(x,\hbox{\it params})$}@math{f(x,params)} in @var{f} for argument @var{x} and parameters @var{params},returning an appropriate error code if the function cannot be computed.@item size_t @var{n}the dimension of the system, i.e. the number of components of thevectors @var{x} and @var{f}.@item void * @var{params}a pointer to the parameters of the function.@end table@end deftp@noindentHere is an example using Powell's test function,@tex\beforedisplay$$f_1(x) = A x_0 x_1 - 1,f_2(x) = \exp(-x_0) + \exp(-x_1) - (1 + 1/A)$$\afterdisplay@end tex@ifinfo@examplef_1(x) = A x_0 x_1 - 1,f_2(x) = exp(-x_0) + exp(-x_1) - (1 + 1/A)@end example@end ifinfo@noindentwith @math{A = 10^4}.  The following code defines a@code{gsl_multiroot_function} system @code{F} which you could pass to asolver:@examplestruct powell_params @{ double A; @};intpowell (gsl_vector * x, void * p, gsl_vector * f) @{   struct powell_params * params      = *(struct powell_params *)p;   double A = (params->A);   double x0 = gsl_vector_get(x,0);   double x1 = gsl_vector_get(x,1);   gsl_vector_set (f, 0, A * x0 * x1 - 1)   gsl_vector_set (f, 1, (exp(-x0) + exp(-x1)                           - (1.0 + 1.0/A)))   return GSL_SUCCESS@}gsl_multiroot_function F;struct powell_params params = @{ 10000.0 @};F.function = &powell;F.n = 2;F.params = &params;@end example@deftp {Data Type} gsl_multiroot_function_fdfThis data type defines a general system of functions with parameters andthe corresponding Jacobian matrix of derivatives,@table @code@item int (* f) (const gsl_vector * @var{x}, void * @var{params}, gsl_vector * @var{f})this function should store the vector result@c{$f(x,\hbox{\it params})$}@math{f(x,params)} in @var{f} for argument @var{x} and parameters @var{params},returning an appropriate error code if the function cannot be computed.@item int (* df) (const gsl_vector * @var{x}, void * @var{params}, gsl_matrix * @var{J})this function should store the @var{n}-by-@var{n} matrix result@c{$J_{ij} = \partial f_i(x,\hbox{\it params}) / \partial x_j$}@math{J_ij = d f_i(x,params) / d x_j} in @var{J} for argument @var{x} and parameters @var{params}, returning an appropriate error code if thefunction cannot be computed.@item int (* fdf) (const gsl_vector * @var{x}, void * @var{params}, gsl_vector * @var{f}, gsl_matrix * @var{J})This function should set the values of the @var{f} and @var{J} as above,for arguments @var{x} and parameters @var{params}.  This function providesan optimization of the separate functions for @math{f(x)} and @math{J(x)} -- it is always faster to compute the function and its derivative at thesame time. @item size_t @var{n}the dimension of the system, i.e. the number of components of thevectors @var{x} and @var{f}.@item void * @var{params}a pointer to the parameters of the function.@end table@end deftp@noindentThe example of Powell's test function defined above can be extended toinclude analytic derivatives using the following code,@exampleintpowell_df (gsl_vector * x, void * p, gsl_matrix * J) @{   struct powell_params * params      = *(struct powell_params *)p;   double A = (params->A);   double x0 = gsl_vector_get(x,0);   double x1 = gsl_vector_get(x,1);   gsl_vector_set (J, 0, 0, A * x1)   gsl_vector_set (J, 0, 1, A * x0)   gsl_vector_set (J, 1, 0, -exp(-x0))   gsl_vector_set (J, 1, 1, -exp(-x1))   return GSL_SUCCESS@}intpowell_fdf (gsl_vector * x, void * p,             gsl_matrix * f, gsl_matrix * J) @{   struct powell_params * params      = *(struct powell_params *)p;   double A = (params->A);   double x0 = gsl_vector_get(x,0);   double x1 = gsl_vector_get(x,1);   double u0 = exp(-x0);   double u1 = exp(-x1);   gsl_vector_set (f, 0, A * x0 * x1 - 1)   gsl_vector_set (f, 1, u0 + u1 - (1 + 1/A))   gsl_vector_set (J, 0, 0, A * x1)   gsl_vector_set (J, 0, 1, A * x0)   gsl_vector_set (J, 1, 0, -u0)   gsl_vector_set (J, 1, 1, -u1)   return GSL_SUCCESS@}gsl_multiroot_function_fdf FDF;FDF.f = &powell_f;FDF.df = &powell_df;FDF.fdf = &powell_fdf;FDF.n = 2;FDF.params = 0;@end example@noindentNote that the function @code{powell_fdf} is able to reuse existing termsfrom the function when calculating the Jacobian, thus saving time.@node Iteration of the multidimensional solver@section IterationThe following functions drive the iteration of each algorithm.  Eachfunction performs one iteration to update the state of any solver of the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -