6#ifndef THEORETICA_EXTREMA_H
7#define THEORETICA_EXTREMA_H
23 template<
typename RealFunction>
39 unsigned int iter = 0;
43 while(
abs(x2 - x1) > tolerance && iter <= max_iter) {
51 x3 = x2 - (x2 - x1) /
PHI;
52 x4 = x1 + (x2 - x1) /
PHI;
73 template<
typename RealFunction>
89 unsigned int iter = 0;
91 while(
abs(x2 - x1) > tolerance && iter <= max_iter) {
99 x3 = x2 - (x2 - x1) /
PHI;
100 x4 = x1 + (x2 - x1) /
PHI;
105 if(iter > max_iter) {
123 template<
typename RealFunction>
125 RealFunction f, RealFunction Df, RealFunction D2f,
158 template<
typename RealFunction>
160 RealFunction f, RealFunction Df,
161 RealFunction D2f,
real guess = 0,
194 template<
typename RealFunction>
196 RealFunction f, RealFunction Df,
231 template<
typename RealFunction>
233 RealFunction f, RealFunction Df,
real a,
real b,
Mathematical constants and default algorithm parameters.
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compilation op...
Definition error.h:219
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
iter_result< real > maximize_bisect(RealFunction f, RealFunction Df, real a, real b, real tolerance=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_BISECTION_ITER)
Approximate a function maximum inside an interval given the function and its first derivative using b...
Definition extrema.h:195
iter_result< real > maximize_golden(RealFunction f, real a, real b, real tolerance=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_GOLDENSECTION_ITER)
Approximate a function maximum using the Golden Section search algorithm.
Definition extrema.h:24
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:242
double real
A real number, defined as a floating point type.
Definition constants.h:207
constexpr real OPTIMIZATION_TOL
Approximation tolerance for root finding.
Definition constants.h:297
constexpr unsigned int OPTIMIZATION_GOLDENSECTION_ITER
Maximum number of iterations for the golden section search algorithm.
Definition constants.h:303
iter_result< real > maximize_newton(RealFunction f, RealFunction Df, RealFunction D2f, real guess=0.0, real tolerance=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_NEWTON_ITER)
Approximate a function maximum given the function and its first two derivatives using Newton-Raphson'...
Definition extrema.h:124
iter_result< real > minimize_newton(RealFunction f, RealFunction Df, RealFunction D2f, real guess=0, real tolerance=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_NEWTON_ITER)
Approximate a function minimum given the function and its first two derivatives using Newton-Raphson'...
Definition extrema.h:159
iter_result< real > root_bisect(RealFunction f, real a, real b, real tol=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_BISECTION_ITER)
Find the root of a univariate real function using bisection inside a compact interval [a,...
Definition roots.h:62
@ InvalidArgument
Invalid argument.
Definition error.h:32
@ NoConvergence
Algorithm did not converge.
Definition error.h:31
real deriv_central(RealFunction f, real x, real h=CALCULUS_DERIV_STEP)
Approximate the first derivative of a real function using the central method.
Definition deriv.h:71
constexpr unsigned int OPTIMIZATION_BISECTION_ITER
Maximum number of iterations for the bisection algorithm.
Definition constants.h:300
constexpr unsigned int OPTIMIZATION_NEWTON_ITER
Maximum number of iterations for the Newton-Raphson algorithm.
Definition constants.h:309
constexpr real PHI
The Phi (Golden Section) mathematical constant.
Definition constants.h:219
iter_result< real > root_newton(RealFunction f, RealFunction Df, real guess=0.0, real tol=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_NEWTON_ITER)
Find a root of a univariate real function using Newton's method.
Definition roots.h:223
iter_result< real > minimize_golden(RealFunction f, real a, real b, real tolerance=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_GOLDENSECTION_ITER)
Approximate a function minimum using the Golden Section search algorithm.
Definition extrema.h:74
@ Success
Algorithm converged successfully.
Definition iter_result.h:22
@ Diverged
Algorithm diverged.
Definition iter_result.h:34
@ MaxIterations
Maximum iterations exceeded.
Definition iter_result.h:25
@ InvalidInput
Invalid input provided.
Definition iter_result.h:31
iter_result< real > minimize_bisect(RealFunction f, RealFunction Df, real a, real b, real tolerance=OPTIMIZATION_TOL, unsigned int max_iter=OPTIMIZATION_BISECTION_ITER)
Approximate a function minimum inside an interval given the function and its first derivative using b...
Definition extrema.h:232
Root approximation of real functions.
A structure returned by iterative algorithms containing the computed value, convergence information,...
Definition iter_result.h:45
real residual
Final error or residual norm (exact meaning depends on the algorithm).
Definition iter_result.h:57
unsigned int iterations
Number of iterations performed.
Definition iter_result.h:54
ConvergenceStatus status
Status code indicating reason for termination.
Definition iter_result.h:51