Loading...
Searching...
No Matches
VectorFunc Class Reference
Collaboration diagram for VectorFunc:
[legend]

## Public Member Functions

| VectorFunc (double(*func)(Vector &))
virtual double | Evaluate (Vector &v)
virtual void | Derivative (Vector &point, Vector &d, double delta=1.0)

## Public Attributes

double | dfmin
Vector | dpmin

## Detailed Description

Definition at line 281 of file MathVector.h.

## Constructor & Destructor Documentation

## VectorFunc() [1/2]

VectorFunc::VectorFunc | ( |  | ) |

Definition at line 465 of file MathVector.cpp.

{
f = NULL;
}

## VectorFunc() [2/2]

VectorFunc::VectorFunc | ( | double(*)(Vector &) | func | ) |

Definition at line 470 of file MathVector.cpp.

{
f = func;
}

## ~VectorFunc()

virtual VectorFunc::~VectorFunc | ( |  | ) |

inline virtual

Definition at line 296 of file MathVector.h.

{ }

## Member Function Documentation

## Derivative()

void VectorFunc::Derivative | ( | Vector & | point,
|  | Vector & | d,
|  | double | delta = `1.0`
| ) |  |

virtual

Definition at line 488 of file MathVector.cpp.

{
double a[MAXROUNDS][MAXROUNDS];
// Calculate derivatives along each direction ...
for (int k = 0; k < x.dim; k++)
{
double left, right;
double save_x = x[k];
double h = h_start;
// Evaluate function to the left of x along direction k
x[k] = save_x - h;
left = Evaluate(x);
// Initialize or update dfmin if appropriate...
if (k == 0 || left < dfmin)
dfmin = left, dpmin = x;
// Evaluate function to the right of x along direction k
x[k] = save_x + h;
right = Evaluate(x);
// Update dfmin
if (right < dfmin)
dfmin = left, dpmin = x;
// Initial crude estimate
a[0][0] = (right - left) / (2.0 * h);
// Initial guess of error is large
double err = 1e30;
// At each round, update Neville tableau with smaller stepsize and higher
// order extrapolation ...
for (int i = 1; i < MAXROUNDS; i++)
{
// Decrease h
h *= SQRT_HALF;
// Re-evaluate function and update dfmin as required
x[k] = save_x - h;
left = Evaluate(x);
if (left < dfmin) dfmin = left, dpmin = x;
x[k] = save_x + h;
right = Evaluate(x);
if (right < dfmin) dfmin = right, dpmin = x;
// Improved estimate of derivative
a[0][i] = (right - left) / (2.0 * h);
// Calculate extrapolations of various orders ...
double factor = TWO;
for (int j = 1; j <= i; j++)
{
a[j][i] = (a[j-1][i] * factor - a[j-1][i-1])/(factor - 1.0);
factor *= TWO;
double error = max(fabs(a[j][i] - a[j-1][i]), fabs(a[j][i] - a[j-1][i-1]));
// Did we improve solution?
if (error < err)
{
err = error;
d[k] = a[j][i];
}
}
// Stop if solution is deteriorating ...
if (fabs(a[i][i] - a[i-1][i-1]) >= 2.0 * err)
{
x[k] = save_x;
break;
}
}
x[k] = save_x;
}
}

## Evaluate()

double VectorFunc::Evaluate | ( | Vector & | v | ) |

virtual

Definition at line 475 of file MathVector.cpp.

{
return f(v);
}

## Member Data Documentation

## dfmin

double VectorFunc::dfmin

Definition at line 306 of file MathVector.h.

## dpmin

Vector VectorFunc::dpmin

Definition at line 307 of file MathVector.h.

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

- general/MathVector.h
- general/MathVector.cpp