#ifndef __JMATH__JPOWER__ #define __JMATH__JPOWER__ #include #include /** * \author mdejong */ namespace JMATH {} namespace JPP { using namespace JMATH; } namespace JMATH { /** * Power law function object. * * Evaluation of function, derivative and integral values. */ class JPower { public: /** * Constructor. * * \param alpha spectral index * \param factor multiplication factor */ JPower(const double alpha, const double factor = 1.0) { this->alpha = alpha; this->factor = factor; } /** * Function value. * * \param x abscissa value * \return function value */ double getValue(const double x) const { return factor * pow(x, alpha); } /** * Derivative value. * * \param x abscissa value * \return derivative value */ double getDerivative(const double x) const { return factor * alpha * pow(x, alpha - 1); } /** * Integral value. * * \param x abscissa value * \return integral value */ double getIntegral(const double x) const { if (alpha != -1.0) return factor * pow(x, alpha + 1) / (alpha + 1); else return factor * log(x); } /** * Function value. * * \param x abscissa value * \return function value */ double operator()(const double x) const { return getValue(x); } /** * Read power from input. * * \param in input stream * \param object power * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JPower& object) { in >> object.alpha >> object.factor; return in; } /** * Write power to output. * * \param out output stream * \param object trigonometric * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JPower& object) { return out << object.alpha << ' ' << object.factor; } protected: double alpha; double factor; }; } #endif