Next: , Previous: Root Finding Caveats, Up: One dimensional Root-Finding


32.3 Initializing the Solver

— Function: gsl_root_fsolver * gsl_root_fsolver_alloc (const gsl_root_fsolver_type * T)

This function returns a pointer to a newly allocated instance of a solver of type T. For example, the following code creates an instance of a bisection solver,

          const gsl_root_fsolver_type * T
            = gsl_root_fsolver_bisection;
          gsl_root_fsolver * s
            = gsl_root_fsolver_alloc (T);

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_root_fdfsolver * gsl_root_fdfsolver_alloc (const gsl_root_fdfsolver_type * T)

This function returns a pointer to a newly allocated instance of a derivative-based solver of type T. For example, the following code creates an instance of a Newton-Raphson solver,

          const gsl_root_fdfsolver_type * T
            = gsl_root_fdfsolver_newton;
          gsl_root_fdfsolver * s
            = gsl_root_fdfsolver_alloc (T);

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_root_fsolver_set (gsl_root_fsolver * s, gsl_function * f, double x_lower, double x_upper)

This function initializes, or reinitializes, an existing solver s to use the function f and the initial search interval [x_lower, x_upper].

— Function: int gsl_root_fdfsolver_set (gsl_root_fdfsolver * s, gsl_function_fdf * fdf, double root)

This function initializes, or reinitializes, an existing solver s to use the function and derivative fdf and the initial guess root.

— Function: void gsl_root_fsolver_free (gsl_root_fsolver * s)
— Function: void gsl_root_fdfsolver_free (gsl_root_fdfsolver * s)

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

— Function: const char * gsl_root_fsolver_name (const gsl_root_fsolver * s)
— Function: const char * gsl_root_fdfsolver_name (const gsl_root_fdfsolver * s)

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

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

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