Next: , Previous: Overview of Multidimensional Root Finding, Up: Multidimensional Root-Finding


35.2 Initializing the Solver

The following functions initialize a multidimensional solver, either with or without derivatives. The solver itself depends only on the dimension of the problem and the algorithm and can be reused for different problems.

— Function: gsl_multiroot_fsolver * gsl_multiroot_fsolver_alloc (const gsl_multiroot_fsolver_type * T, size_t n)

This function returns a pointer to a newly allocated instance of a solver of type T for a system of n dimensions. For example, the following code creates an instance of a hybrid solver, to solve a 3-dimensional system of equations.

          const gsl_multiroot_fsolver_type * T
              = gsl_multiroot_fsolver_hybrid;
          gsl_multiroot_fsolver * s
              = gsl_multiroot_fsolver_alloc (T, 3);

If there is insufficient memory to create the solver then the function returns a null pointer and the error handler is invoked with an error code of GSL_ENOMEM.

— Function: gsl_multiroot_fdfsolver * gsl_multiroot_fdfsolver_alloc (const gsl_multiroot_fdfsolver_type * T, size_t n)

This function returns a pointer to a newly allocated instance of a derivative solver of type T for a system of n dimensions. For example, the following code creates an instance of a Newton-Raphson solver, for a 2-dimensional system of equations.

          const gsl_multiroot_fdfsolver_type * T
              = gsl_multiroot_fdfsolver_newton;
          gsl_multiroot_fdfsolver * s =
              gsl_multiroot_fdfsolver_alloc (T, 2);

If there is insufficient memory to create the solver then the function returns a null pointer and the error handler is invoked with an error code of GSL_ENOMEM.

— Function: int gsl_multiroot_fsolver_set (gsl_multiroot_fsolver * s, gsl_multiroot_function * f, const gsl_vector * x)
— Function: int gsl_multiroot_fdfsolver_set (gsl_multiroot_fdfsolver * s, gsl_multiroot_function_fdf * fdf, const gsl_vector * x)

These functions set, or reset, an existing solver s to use the function f or function and derivative fdf, and the initial guess x. Note that the initial position is copied from x, this argument is not modified by subsequent iterations.

— Function: void gsl_multiroot_fsolver_free (gsl_multiroot_fsolver * s)
— Function: void gsl_multiroot_fdfsolver_free (gsl_multiroot_fdfsolver * s)

These functions free all the memory associated with the solver s.

— Function: const char * gsl_multiroot_fsolver_name (const gsl_multiroot_fsolver * s)
— Function: const char * gsl_multiroot_fdfsolver_name (const gsl_multiroot_fdfsolver * s)

These functions return a pointer to the name of the solver. For example,

          printf ("s is a '%s' solver\n",
                  gsl_multiroot_fdfsolver_name (s));

would print something like s is a 'newton' solver.