#ifndef __JMATH__JMATHLIB2D__ #define __JMATH__JMATHLIB2D__ #include "JMath/JMathlib.hh" /** * \file * Functional algebra in 2D. * * \author mdejong */ namespace JMATH {} namespace JPP { using namespace JMATH; } namespace JMATH { /** * Make 2D function of x from 1D function. */ template struct JMake2X : public JMathlib< JMake2X >, public JF1_t { using JMathlib< JMake2X >::operator(); /** * Default constructor. */ JMake2X() {} /** * Constructor. * * \param f1 function */ JMake2X(const JF1_t& f1) : JF1_t(f1) {} /** * Constructor. * * \param args list of values */ template JMake2X(const Args& ...args) : JF1_t(args...) {} /** * Function value. * * \param x abscissa value * \param y abscissa value * \return function value */ double getValue(const double x, const double y) const { return static_cast(*this).getValue(x); } /** * Get gradient. * * \param x abscissa value * \param y abscissa value * \return gradient */ const JMake2X& getGradient(const double x, const double y) const { static JMake2X gradient; static_cast(gradient) = static_cast(*this).getGradient(x); return gradient; } }; /** * Make 2D function of y from 1D function. */ template struct JMake2Y : public JMathlib< JMake2Y >, public JF1_t { using JMathlib< JMake2Y >::operator(); /** * Default constructor. */ JMake2Y() {} /** * Constructor. * * \param f1 function */ JMake2Y(const JF1_t& f1) : JF1_t(f1) {} /** * Constructor. * * \param args list of values */ template JMake2Y(const Args& ...args) : JF1_t(args...) {} /** * Function value. * * \param x abscissa value * \param y abscissa value * \return function value */ double getValue(const double x, const double y) const { return static_cast(*this).getValue(y); } /** * Get gradient. * * \param x abscissa value * \param y abscissa value * \return gradient */ const JMake2Y& getGradient(const double x, const double y) const { static JMake2Y gradient; static_cast(gradient) = static_cast(*this).getGradient(y); return gradient; } }; template using JPolynome2X = JMake2X< JPolynome >; //!< 2D polynomial function of x. template using JPolynome2Y = JMake2Y< JPolynome >; //!< 2D polynomial function of y. template using JGauss2X = JMake2X< JGauss >; //!< 2D Gauss function of x. template using JGauss2Y = JMake2Y< JGauss >; //!< 2D Gauss function of y. template using JPow2X = JMake2X< JPow >; //!< 2D power of function of x. template using JPow2Y = JMake2Y< JPow >; //!< 2D power of function of y. template using JXn2X = JMake2X< JXn >; //!< 2D fixed power of x. template using JXn2Y = JMake2Y< JXn >; //!< 2D fixed power of y. template using JSqrt2X = JMake2X< JSqrt >; //!< 2D square root of function of x. template using JSqrt2Y = JMake2Y< JSqrt >; //!< 2D square root of function of y. template using JSin2X = JMake2X< JSin >; //!< 2D sine of function of x. template using JSin2Y = JMake2Y< JSin >; //!< 2D sine of function of y. template using JCos2X = JMake2X< JCos >; //!< 2D cosine of function of x. template using JCos2Y = JMake2Y< JCos >; //!< 2D cosine of function of y. template using JExp2X = JMake2X< JExp >; //!< 2D exponent of function of x. template using JExp2Y = JMake2Y< JExp >; //!< 2D exponent of function of y. template using JLog2X = JMake2X< JLog >; //!< 2D logarithm of function of x. template using JLog2Y = JMake2Y< JLog >; //!< 2D logarithm of function of y. /** * 2D correlated Gauss function. */ template struct JGauss2D : public JMathlib< JGauss2D >, public JGauss { using JMathlib< JGauss2D >::operator(); /** * Default constructor. */ JGauss2D() {} /** * Constructor. * * \param mean mean * \param sigma sigma */ JGauss2D(const double mean, const double sigma) : JGauss(mean, sigma) {} /** * Function value. * * \param x abscissa value * \param y abscissa value * \return function value */ double getValue(const double x, const double y) const { typedef JGauss JGauss_t; return (static_cast(*this).getValue(x) * static_cast(*this).getValue(y)); } /** * Get gradient. * * \param x abscissa value * \param y abscissa value * \return gradient */ const JGauss2D& getGradient(const double x, const double y) const { static JGauss2D gradient; typedef JGauss JGauss_t; static_cast(gradient) = JGauss_t(static_cast(*this).getGradient(x)).mul(static_cast(*this).getValue(y)); static_cast(gradient) += JGauss_t(static_cast(*this).getGradient(y)).mul(static_cast(*this).getValue(x)); return gradient; } }; } #endif