Added a functor to interface with newton

This commit is contained in:
Your Name 2011-02-09 14:32:01 -05:00
parent bf1e581ce9
commit 5b3bef64b1
2 changed files with 41 additions and 0 deletions

View File

@ -1,3 +1,4 @@
#include <cassert>
#include <cmath>
#include <algorithm>
#include "interpolate.hpp"
@ -48,6 +49,31 @@ double Interpolate::compute(double x)
return y;
}
double Interpolate::derivative(double x)
throw (InvalidRangeException)
{
double y, dy, x0 = x;
if (logx)
x0 = log(x0);
int err = gsl_spline_eval_deriv_e(spline, x0, accel_interp, &dy);
if (err)
throw InvalidRangeException("Interpolate argument outside range");
if (logy)
{
int err = gsl_spline_eval_e(spline, x0, accel_interp, &y);
assert(err == 0);
return dy*exp(y)/x0;
}
else
return dy;
}
uint32_t Interpolate::getNumPoints() const
{
return spline->size;

View File

@ -21,6 +21,9 @@ namespace CosmoTool
double compute(double x)
throw (InvalidRangeException);
double derivative(double x)
throw (InvalidRangeException);
const Interpolate& operator=(const Interpolate& a);
uint32_t getNumPoints() const;
@ -41,6 +44,18 @@ namespace CosmoTool
Interpolate buildInterpolateFromColumns(const char *fname, uint32_t col1, uint32_t col2, bool logx = false, bool logy = false)
throw (NoSuchFileException,InvalidRangeException);
Interpolate buildFromVector(const InterpolatePairs& v);
class FunctorInterpolate
{
public:
FunctorInterpolate(Interpolate& i) : m_i(i) {}
double eval(double x) { return m_i.compute(x); }
double derivative(double x) { return m_i.derivative(x); }
private:
Interpolate& m_i;
};
};