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

Class for minimize the function \( f(x) \) without the usew of derivative. More...

#include <Utils_Trichotomy.hh>

Public Member Functions

 Trichotomy ()=default
 
 ~Trichotomy ()=default
 
Real eval (Real a, Real b, Trichotomy_base_fun< Real > *fun)
 
template<typename PFUN>
Real eval2 (Real a, Real b, PFUN pfun)
 
Real search (Real x, Real delta, Trichotomy_base_fun< Real > *fun)
 
template<typename PFUN>
Real search2 (Real x, Real delta, PFUN pfun)
 
Integer used_iter () const
 
Integer num_fun_eval () const
 
Real tolerance () const
 
bool converged () const
 
void set_max_iterations (Integer mit)
 
void set_max_fun_evaluation (Integer mfev)
 

Detailed Description

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

Class for minimize the function \( f(x) \) without the usew of derivative.

Note
The used algorithm is described in: A new zero-order 1-D optimization algorithm: trichotomy method, by Alena Antonova, Olga Ibryaeva, link

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 Trichotomy_base_fun<double> {
public:
double eval(double x) const override { return x*x - 2; }
};
Abstract base class for defining mathematical functions used in the minimization algorithm.
Definition Utils_Trichotomy.hh:71
virtual Real eval(Real x) const =0

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

Fun1 f;
real_type a=-1,b=2;
real_type x_solution = solver.eval2(a,b,f);
Real eval2(Real a, Real b, PFUN pfun)
Definition Utils_Trichotomy.hh:188
Trichotomy()=default

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

Constructor & Destructor Documentation

◆ Trichotomy()

template<typename Real>
Utils::Trichotomy< Real >::Trichotomy ( )
default

◆ ~Trichotomy()

template<typename Real>
Utils::Trichotomy< Real >::~Trichotomy ( )
default

Member Function Documentation

◆ converged()

template<typename Real>
bool Utils::Trichotomy< Real >::converged ( ) const
inline
Returns
true if the last computation was successfull

◆ eval()

template<typename Real>
Real Utils::Trichotomy< Real >::eval ( Real a,
Real b,
Trichotomy_base_fun< Real > * fun )
inline

Find the minimum of a function wrapped in the class Trichotomy_base_fun<Real> starting from guess interval [a,b]

Parameters
alower bound search interval
bupper bound search interval
funthe pointer to base class Trichotomy_base_fun<Real> wrapping the user function

◆ eval2()

template<typename Real>
template<typename PFUN>
Real Utils::Trichotomy< Real >::eval2 ( Real a,
Real b,
PFUN pfun )
inline

Find the minimum of a function pfun starting from guess interval [a,b]

Parameters
alower bound search interval
bupper bound search interval
pfunthe pointer to base class Trichotomy_base_fun<Real> wrapping the user function

◆ num_fun_eval()

template<typename Real>
Integer Utils::Trichotomy< Real >::num_fun_eval ( ) const
inline
Returns
the number of evaluation used in the last computation

◆ search()

template<typename Real>
Real Utils::Trichotomy< Real >::search ( Real x,
Real delta,
Trichotomy_base_fun< Real > * fun )
inline

Find the minimum of a function wrapped in the class Trichotomy_base_fun<Real> starting from guess interval [x-delta,x+delta]

Parameters
xcenter of the search interval
deltaray of th eseaerch interval
funthe pointer to base class Trichotomy_base_fun<Real> wrapping the user function

◆ search2()

template<typename Real>
template<typename PFUN>
Real Utils::Trichotomy< Real >::search2 ( Real x,
Real delta,
PFUN pfun )
inline

Find the minimum of a function object starting from guess interval [x-delta,x+delta]

Parameters
xcenter of the search interval
deltaray of th eseaerch interval
pfunthe function object

◆ set_max_fun_evaluation()

template<typename Real>
void Utils::Trichotomy< Real >::set_max_fun_evaluation ( Integer mfev)

Fix the maximum number of evaluation.

Parameters
mfevthe maximum number of evaluation of \( f(x) \)

◆ set_max_iterations()

template<typename Real>
void Utils::Trichotomy< Real >::set_max_iterations ( Integer mit)

Fix the maximum number of iteration.

Parameters
mitthe maximum number of iteration

◆ tolerance()

template<typename Real>
Real Utils::Trichotomy< Real >::tolerance ( ) const
inline
Returns
the tolerance set for computation

◆ used_iter()

template<typename Real>
Integer Utils::Trichotomy< Real >::used_iter ( ) const
inline
Returns
the number of iterations used in the last computation

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