UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils::Zeros< Real > Class Template Reference

Class for solving the equation \( f(x) = 0 \) using various numerical methods. More...

#include <Utils_zeros.hh>

Public Member Functions

 Zeros ()=default
 
 ~Zeros ()=default
 
void set_max_iterations (Integer mit)
 
void set_max_fun_evaluation (Integer mfev)
 
void set_tolerance (Real tol)
 
Real solve_Newton (Real x_guess, Zeros_base_fun< Real > *fun)
 
Real solve_Chebyshev (Real x_guess, Zeros_base_fun< Real > *fun)
 
Real solve_Halley (Real x_guess, Zeros_base_fun< Real > *fun)
 
Real solve_Order4 (Real x_guess, Zeros_base_fun< Real > *fun)
 
Real solve_Order8 (Real x_guess, Zeros_base_fun< Real > *fun)
 
Real solve_Order16 (Real x_guess, Zeros_base_fun< Real > *fun)
 
Real solve_Order32 (Real x_guess, Zeros_base_fun< Real > *fun)
 
Integer used_iter () const
 
Integer num_fun_eval () const
 
Real tolerance () const
 
bool converged () const
 

Detailed Description

template<typename Real>
class Utils::Zeros< Real >

Class for solving the equation \( f(x) = 0 \) using various numerical methods.

This class implements multiple solvers to find the roots of a given function. The available methods include:

  • Newton-Raphson Method: A widely used iterative method for finding successively better approximations to the roots of a real-valued function. Learn more.
  • Chebyshev Method: A higher-order root-finding method that offers faster convergence compared to the Newton-Raphson method.
  • Halley Method: An iterative method that is a generalization of the Newton-Raphson method and provides faster convergence. Learn more.
  • Methods by Juan Luis Varona: A series of methods developed for enhanced convergence properties:
    • Order 4 method
    • Order 8 method
    • Order 16 method
    • Order 32 method

For a detailed exploration of these methods, refer to the paper:

  • An Optimal Thirty-Second-Order Iterative Method for Solving Nonlinear Equations and a Conjecture, Juan Luis Varona, Qualitative Theory of Dynamical Systems (2022). Link to the paper.
Note
This class is designed to work with user-defined functions that extend from Utils::Zeros_base_fun.

Usage Example

To use this class, first wrap your function in a derived class. For instance, for the function \( f(x) = x^2 - 2 \), you can define:

class Fun1 : public Utils::Zeros_base_fun<real_type> {
public:
real_type eval(real_type x) const override { return x*x - 2; }
real_type eval_D(real_type x) const override { return 2*x; }
real_type eval_DD(real_type x) const override { return 2; }
real_type eval_DDD(real_type x) const override { return 0; }
};
Abstract base class for defining mathematical functions used in root-finding algorithms.
Definition Utils_zeros.hh:87
virtual Real eval(Real x) const =0
virtual Real eval_D(Real x) const =0
virtual Real eval_DD(Real x) const =0
virtual Real eval_DDD(Real x) const =0

Next, instantiate the function and the solver. Then, call the desired method to find the root:

Fun1 f;
real_type x_guess = 1.0; // Initial guess
real_type x_solution = solver.solve_Newton(x_guess, f);
Zeros()=default
Real solve_Newton(Real x_guess, Zeros_base_fun< Real > *fun)
Definition Utils_zeros.cc:87

If the method converges, x_solution will contain the computed solution.


The documentation for this class was generated from the following files: