FEDRA emulsion software from the OPERA Collaboration
minfc.hh File Reference
#include "Functions.hh"
Include dependency graph for minfc.hh:

Go to the source code of this file.

Functions

template<class T , class P >
bool Rminfc (T(*f)(P), P a, P b, double eps, double delta, P &x, P &y)
 
template<class C , class T , class P >
bool RminfcM (const C &part, T(C::*f)(P) const, P a, P b, double eps, double delta, P &x, P &y)
 

Function Documentation

◆ Rminfc()

template<class T , class P >
bool Rminfc ( T(*)(P)  f,
a,
b,
double  eps,
double  delta,
P &  x,
P &  y 
)

Rminfc. Function which finds a single, local minimum of a function with one variable in a given interval. The "golden section search" is applied. The method uses a fixed number $n$ of function evaluations, where $n = [2.08\cdot\ln(|a-b|/\epsilon)+1/2] + 1$.

Parameters
fone-dimensional function
a,bend-points of search interval
epsaccuracy parameter $\epsilon$
deltatolerance interval $\delta$ near $a$ and $b$. Suggested value: $\delta = 10\epsilon$
xcomputed approximation to the abscissa of a minimum of the function $f$
yvalue of $f(x)$
44 {
45
46 // Local variables
47 static P c, d, h;
48 static int n;
49 static P v, w, fv, fw;
50 bool lge = true, llt = true;
51
52
53 n = -1;
54 if (a != b) {
55 n = round(log(fabs(a - b) / eps) * 2.08);
56 }
57 c = a;
58 d = b;
59 if (a > b) {
60 c = b;
61 d = a;
62 }
63
64 do {
65 h = d - c;
66 if (llt == true) {
67 v = c + h * 0.3819660112501051;
68 fv = (*f)(v);
69 }
70 if (lge == true) {
71 w = c + h * 0.6180339887498949;
72 fw = (*f)(w);
73 }
74 if (fv < fw) {
75 llt = true;
76 lge = false;
77 d = w;
78 w = v;
79 fw = fv;
80 } else {
81 llt = false;
82 lge = true;
83 c = v;
84 v = w;
85 fv = fw;
86 }
87 --n;
88 } while (n >= 0);
89
90 x = (c + d) * .5;
91 y = (*f)(x);
92 return (fabs(x - a) > delta) && (fabs(x - b) > delta);
93} // Rminfc
int round(const T &x)
Definition: Functions.hh:83
void d()
Definition: RecDispEX.C:381
FILE * log
Expr< UnaryOp< Fabs< T >, Expr< A, T, D >, T >, T, D > fabs(const Expr< A, T, D > &rhs)
Definition: UnaryOperators.hh:96
void a()
Definition: check_aligned.C:59
void w(int rid=2, int nviews=2)
Definition: test.C:27

◆ RminfcM()

template<class C , class T , class P >
bool RminfcM ( const C &  part,
T(C::*)(P) const  f,
a,
b,
double  eps,
double  delta,
P &  x,
P &  y 
)

RminfcM. Rminfc version for const class member functions.

Function which finds a single, local minimum of a function with one variable in a given interval. The "golden section search" is applied. The method uses a fixed number $n$ of function evaluations, where $n = [2.08\cdot\ln(|a-b|/\epsilon)+1/2] + 1$.

Parameters
fone-dimensional function
a,bend-points of search interval
epsaccuracy parameter $\epsilon$
deltatolerance interval $\delta$ near $a$ and $b$. Suggested value: $\delta = 10\epsilon$
xcomputed approximation to the abscissa of a minimum of the function $f$
yvalue of $f(x)$
112 {
113
114 // Local variables
115 static P c, d, h;
116 static int n;
117 static P v, w, fv, fw;
118 bool lge = true, llt = true;
119
120
121 n = -1;
122 if (a != b) {
123 n = round(log(fabs(a - b) / eps) * 2.08);
124 }
125 c = a;
126 d = b;
127 if (a > b) {
128 c = b;
129 d = a;
130 }
131
132 do {
133 h = d - c;
134 if (llt == true) {
135 v = c + h * 0.3819660112501051;
136 fv = (part.*f)(v);
137 }
138 if (lge == true) {
139 w = c + h * 0.6180339887498949;
140 fw = (part.*f)(w);
141 }
142 if (fv < fw) {
143 llt = true;
144 lge = false;
145 d = w;
146 w = v;
147 fw = fv;
148 } else {
149 llt = false;
150 lge = true;
151 c = v;
152 v = w;
153 fv = fw;
154 }
155 --n;
156 } while (n >= 0);
157
158 x = (c + d) * .5;
159 y = (part.*f)(x);
160 return (fabs(x - a) > delta) && (fabs(x - b) > delta);
161} // Rminfc
FILE * f
Definition: RecDispMC.C:150