-
Notifications
You must be signed in to change notification settings - Fork 2
/
MathGold.h
55 lines (42 loc) · 1.21 KB
/
MathGold.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef _MATHGOLD_H_
#define _MATHGOLD_H_
#include "MathConstant.h"
#include "MathVector.h"
// Minimizes functions of one variable in one dimension
class ScalarMinimizer
{
public:
double(*func)(double); // function to be minimized
double a, b, c, min;
double fa, fb, fc, fmin;
ScalarMinimizer()
{
func = NULL;
};
virtual ~ScalarMinimizer() { }
virtual double f(double x);
void Bracket(double a, double b); // bracket a minimum near a and b
virtual double Brent(double tol = TOL); // return minimum, to precision TOL
// result stored in min
};
class LineMinimizer : public ScalarMinimizer
// Minimizes f(P) along the line define by P = point + x * line
// Stores the best point (in point) along the line
// and the displacement from the original (in line)
{
private:
bool garbage;
public:
VectorFunc * func; // function to be minimized
Vector line, point, temp;
LineMinimizer();
LineMinimizer(VectorFunc & vfunc);
LineMinimizer(double(*vfunc)(Vector & v));
virtual ~LineMinimizer()
{
if (garbage) delete func;
}
virtual double f(double x);
virtual double Brent(double tol = TOL);
};
#endif