mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-10 19:20:44 +01: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,
|
Derivative::Derivative(const DoubleFunction &f, const Index dir,
|
||||||
const double step)
|
const double step)
|
||||||
: DoubleFunction(f.getNArg())
|
: DoubleFunction(f.getNArg())
|
||||||
, f_(f)
|
, f_(&f)
|
||||||
, dir_(dir)
|
, dir_(dir)
|
||||||
, step_(step)
|
, step_(step)
|
||||||
, buffer_(new DVec(f.getNArg()))
|
, buffer_(new DVec(f.getNArg()))
|
||||||
@ -62,6 +62,11 @@ double Derivative::getStep(void) const
|
|||||||
return step_;
|
return step_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Derivative::setFunction(const DoubleFunction &f)
|
||||||
|
{
|
||||||
|
f_ = &f;
|
||||||
|
}
|
||||||
|
|
||||||
void Derivative::setOrderAndPoint(const Index order, const DVec point)
|
void Derivative::setOrderAndPoint(const Index order, const DVec point)
|
||||||
{
|
{
|
||||||
if (order >= point.size())
|
if (order >= point.size())
|
||||||
@ -127,14 +132,14 @@ void Derivative::makeCoefficients(void)
|
|||||||
// function call ///////////////////////////////////////////////////////////////
|
// function call ///////////////////////////////////////////////////////////////
|
||||||
double Derivative::operator()(const double *x) const
|
double Derivative::operator()(const double *x) const
|
||||||
{
|
{
|
||||||
ConstMap<DVec> xMap(x, f_.getNArg());
|
ConstMap<DVec> xMap(x, (*f_).getNArg());
|
||||||
double res = 0.;
|
double res = 0.;
|
||||||
|
|
||||||
*buffer_ = xMap;
|
*buffer_ = xMap;
|
||||||
FOR_VEC(point_, i)
|
FOR_VEC(point_, i)
|
||||||
{
|
{
|
||||||
(*buffer_)(dir_) = x[dir_] + point_(i)*step_;
|
(*buffer_)(dir_) = x[dir_] + point_(i)*step_;
|
||||||
res += coefficient_[i]*f_(*buffer_);
|
res += coefficient_[i]*(*f_)(*buffer_);
|
||||||
}
|
}
|
||||||
res /= pow(step_, order_);
|
res /= pow(step_, order_);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user