mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
Derivative: function is now just a pointer
This commit is contained in:
parent
ee8be4f004
commit
c0d717bcb6
@ -33,7 +33,7 @@ using namespace Math;
|
||||
Derivative::Derivative(const DoubleFunction &f, const Index dir,
|
||||
const double step)
|
||||
: DoubleFunction(f.getNArg())
|
||||
, f_(f)
|
||||
, f_(&f)
|
||||
, dir_(dir)
|
||||
, step_(step)
|
||||
, buffer_(new DVec(f.getNArg()))
|
||||
@ -62,6 +62,11 @@ double Derivative::getStep(void) const
|
||||
return step_;
|
||||
}
|
||||
|
||||
void Derivative::setFunction(const DoubleFunction &f)
|
||||
{
|
||||
f_ = &f;
|
||||
}
|
||||
|
||||
void Derivative::setOrderAndPoint(const Index order, const DVec point)
|
||||
{
|
||||
if (order >= point.size())
|
||||
@ -127,14 +132,14 @@ void Derivative::makeCoefficients(void)
|
||||
// function call ///////////////////////////////////////////////////////////////
|
||||
double Derivative::operator()(const double *x) const
|
||||
{
|
||||
ConstMap<DVec> xMap(x, f_.getNArg());
|
||||
ConstMap<DVec> xMap(x, (*f_).getNArg());
|
||||
double res = 0.;
|
||||
|
||||
*buffer_ = xMap;
|
||||
FOR_VEC(point_, i)
|
||||
{
|
||||
(*buffer_)(dir_) = x[dir_] + point_(i)*step_;
|
||||
res += coefficient_[i]*f_(*buffer_);
|
||||
res += coefficient_[i]*(*f_)(*buffer_);
|
||||
}
|
||||
res /= pow(step_, order_);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user