Solution of one equation in one variable is accomplished by children of the class o2scl::root.
For one-dimensional solving, if the root is bracketed, use o2scl::root_bkt_cern or o2scl::root_brent_gsl. The o2scl::root_bkt_cern class is typically faster (for the same accuracy) than o2scl::root_brent_gsl. If a relatively fast derivative is available, use o2scl::root_stef. If neither a bracket nor a derivative is available, you can use o2scl::root_cern.
The o2scl::root base class provides the structure for three different solving methods:
x
x1
and x2
. The values of the function at x1
and x2
should have different signs.x
and the function's derivative.There is an example using the one-dimensional solver in the Function object example .
The o2scl::root base class also contains the relative tolerance (o2scl::root::tol_rel), absolute tolerance (o2scl::root::tol_abs), the number of iterations (o2scl::root::ntrial), the verbosity parameter (o2scl::root::verbose), and the number of iterations in the last solve (o2scl::root::last_ntrial).
If not all of these three functions are overloaded, then the source code in the o2scl::root base class is designed to try to automatically provide the solution using the remaining functions. Most of the one-dimensional solving routines, in their original form, are written in the second or third form above. For example, o2scl::root_brent_gsl is originally a bracketing routine of the form o2scl::root::solve_bkt(), but calls to either o2scl::root::solve() or o2scl::root::solve_de() will attempt to automatically bracket the function given the initial guess that is provided. Of course, it is frequently most efficient to use the solver in the way it was intended.
Solution of more than one equation is accomplished by descendants of the class o2scl::mroot . The higher-level interface is provided by the function o2scl::mroot::msolve() .
For multi-dimensional solving, you can use either o2scl::mroot_cern or o2scl::mroot_hybrids. While o2scl::mroot_cern cannot utilize user-supplied derivatives, o2scl::mroot_hybrids can use user-supplied derivative information (as in the GSL hybridsj method) using the function o2scl::mroot_hybrids::msolve_de() .
A specialization of o2scl::mroot_hybrids for Armadillo is given in o2scl::mroot_hybrids_arma_qr_econ where the QR decomposition used in the solver is performed by the Armadillo library. A similar specialization for Eigen is in o2scl::mroot_hybrids_eigen . These specializations will be faster than when the number of variables is sufficiently large.
This demonstrates several ways of using the multi-dimensional solvers to solve the equations
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).