Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
JMathlib2D.hh
Go to the documentation of this file.
1 #ifndef __JMATH__JMATHLIB2D__
2 #define __JMATH__JMATHLIB2D__
3 
4 #include "JMath/JMathlib.hh"
5 
6 /**
7  * \file
8  * Functional algebra in 2D.
9  *
10  * \author mdejong
11  */
12 
13 namespace JMATH {}
14 namespace JPP { using namespace JMATH; }
15 
16 namespace JMATH {
17 
18  /**
19  * Make 2D function of x from 1D function.
20  */
21  template<class JF1_t>
22  struct JMake2X :
23  public JMathlib< JMake2X<JF1_t> >,
24  public JF1_t
25  {
26  using JMathlib< JMake2X<JF1_t> >::operator();
27 
28 
29  /**
30  * Default constructor.
31  */
33  {}
34 
35 
36  /**
37  * Constructor.
38  *
39  * \param f1 function
40  */
41  JMake2X(const JF1_t& f1) :
42  JF1_t(f1)
43  {}
44 
45 
46  /**
47  * Constructor.
48  *
49  * \param args list of values
50  */
51  template<class ...Args>
52  JMake2X(const Args& ...args) :
53  JF1_t(args...)
54  {}
55 
56 
57  /**
58  * Function value.
59  *
60  * \param x abscissa value
61  * \param y abscissa value
62  * \return function value
63  */
64  double getValue(const double x, const double y) const
65  {
66  return static_cast<const JF1_t&>(*this).getValue(x);
67  }
68 
69 
70  /**
71  * Get gradient.
72  *
73  * \param x abscissa value
74  * \param y abscissa value
75  * \return gradient
76  */
77  const JMake2X& getGradient(const double x, const double y) const
78  {
79  static JMake2X gradient;
80 
81  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(x);
82 
83  return gradient;
84  }
85  };
86 
87 
88  /**
89  * Make 2D function of y from 1D function.
90  */
91  template<class JF1_t>
92  struct JMake2Y :
93  public JMathlib< JMake2Y<JF1_t> >,
94  public JF1_t
95  {
96  using JMathlib< JMake2Y<JF1_t> >::operator();
97 
98 
99  /**
100  * Default constructor.
101  */
103  {}
104 
105 
106  /**
107  * Constructor.
108  *
109  * \param f1 function
110  */
111  JMake2Y(const JF1_t& f1) :
112  JF1_t(f1)
113  {}
114 
115 
116  /**
117  * Constructor.
118  *
119  * \param args list of values
120  */
121  template<class ...Args>
122  JMake2Y(const Args& ...args) :
123  JF1_t(args...)
124  {}
125 
126 
127  /**
128  * Function value.
129  *
130  * \param x abscissa value
131  * \param y abscissa value
132  * \return function value
133  */
134  double getValue(const double x, const double y) const
135  {
136  return static_cast<const JF1_t&>(*this).getValue(y);
137  }
138 
139 
140  /**
141  * Get gradient.
142  *
143  * \param x abscissa value
144  * \param y abscissa value
145  * \return gradient
146  */
147  const JMake2Y& getGradient(const double x, const double y) const
148  {
149  static JMake2Y gradient;
150 
151  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(y);
152 
153  return gradient;
154  }
155  };
156 
157 
158  template<int ID_t, size_t N> using JPolynome2X = JMake2X< JPolynome<ID_t, N> >; //!< 2D polynomial function of x.
159  template<int ID_t, size_t N> using JPolynome2Y = JMake2Y< JPolynome<ID_t, N> >; //!< 2D polynomial function of y.
160  template<int ID_t, bool normalise = false> using JGauss2X = JMake2X< JGauss<ID_t, normalise> >; //!< 2D Gauss function of x.
161  template<int ID_t, bool normalise = false> using JGauss2Y = JMake2Y< JGauss<ID_t, normalise> >; //!< 2D Gauss function of y.
162  template<int ID_t, class JF1_t = _vF> using JPow2X = JMake2X< JPow<ID_t, JF1_t> >; //!< 2D power of function of x.
163  template<int ID_t, class JF1_t = _vF> using JPow2Y = JMake2Y< JPow<ID_t, JF1_t> >; //!< 2D power of function of y.
164  template<int N> using JXn2X = JMake2X< JXn<N> >; //!< 2D fixed power of x.
165  template<int N> using JXn2Y = JMake2Y< JXn<N> >; //!< 2D fixed power of y.
166  template<class JF1_t = _vF> using JSqrt2X = JMake2X< JSqrt<JF1_t> >; //!< 2D square root of function of x.
167  template<class JF1_t = _vF> using JSqrt2Y = JMake2Y< JSqrt<JF1_t> >; //!< 2D square root of function of y.
168  template<class JF1_t> using JSin2X = JMake2X< JSin<JF1_t> >; //!< 2D sine of function of x.
169  template<class JF1_t> using JSin2Y = JMake2Y< JSin<JF1_t> >; //!< 2D sine of function of y.
170  template<class JF1_t> using JCos2X = JMake2X< JCos<JF1_t> >; //!< 2D cosine of function of x.
171  template<class JF1_t> using JCos2Y = JMake2Y< JCos<JF1_t> >; //!< 2D cosine of function of y.
172  template<class JF1_t> using JExp2X = JMake2X< JExp<JF1_t> >; //!< 2D exponent of function of x.
173  template<class JF1_t> using JExp2Y = JMake2Y< JExp<JF1_t> >; //!< 2D exponent of function of y.
174  template<class JF1_t> using JLog2X = JMake2X< JLog<JF1_t> >; //!< 2D logarithm of function of x.
175  template<class JF1_t> using JLog2Y = JMake2Y< JLog<JF1_t> >; //!< 2D logarithm of function of y.
176 
177 
178  /**
179  * 2D correlated Gauss function.
180  */
181  template<int ID_t, bool normalise = false>
182  struct JGauss2D :
183  public JMathlib< JGauss2D<ID_t, normalise> >,
184  public JGauss<ID_t, normalise>
185  {
186  using JMathlib< JGauss2D<ID_t, normalise> >::operator();
187 
188 
189  /**
190  * Default constructor.
191  */
193  {}
194 
195 
196  /**
197  * Constructor.
198  *
199  * \param mean mean
200  * \param sigma sigma
201  */
202  JGauss2D(const double mean,
203  const double sigma) :
204  JGauss<ID_t, normalise>(mean, sigma)
205  {}
206 
207 
208  /**
209  * Function value.
210  *
211  * \param x abscissa value
212  * \param y abscissa value
213  * \return function value
214  */
215  double getValue(const double x, const double y) const
216  {
218 
219  return (static_cast<const JGauss_t&>(*this).getValue(x) *
220  static_cast<const JGauss_t&>(*this).getValue(y));
221  }
222 
223 
224  /**
225  * Get gradient.
226  *
227  * \param x abscissa value
228  * \param y abscissa value
229  * \return gradient
230  */
231  const JGauss2D& getGradient(const double x, const double y) const
232  {
233  static JGauss2D gradient;
234 
236 
237  static_cast<JGauss_t&>(gradient) = JGauss_t(static_cast<const JGauss_t&>(*this).getGradient(x)).mul(static_cast<const JGauss_t&>(*this).getValue(y));
238  static_cast<JGauss_t&>(gradient) += JGauss_t(static_cast<const JGauss_t&>(*this).getGradient(y)).mul(static_cast<const JGauss_t&>(*this).getValue(x));
239 
240  return gradient;
241  }
242  };
243 }
244 
245 #endif
Functional algebra.
const JPolynome f1(1.0, 2.0, 3.0)
Function.
Auxiliary classes and methods for mathematical operations.
Definition: JEigen3D.hh:88
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
2D correlated Gauss function.
Definition: JMathlib2D.hh:185
const JGauss2D & getGradient(const double x, const double y) const
Get gradient.
Definition: JMathlib2D.hh:231
double getValue(const double x, const double y) const
Function value.
Definition: JMathlib2D.hh:215
JGauss2D()
Default constructor.
Definition: JMathlib2D.hh:192
JGauss2D(const double mean, const double sigma)
Constructor.
Definition: JMathlib2D.hh:202
Gauss model.
Definition: JGauss.hh:32
JGauss_t & mul(const double factor)
Scale gauss.
Definition: JGauss.hh:120
JGauss_t()
Default constructor.
Definition: JGauss.hh:36
double mean
Definition: JGauss.hh:161
Gauss function object.
Definition: JGauss.hh:175
Make 2D function of x from 1D function.
Definition: JMathlib2D.hh:25
JMake2X(const JF1_t &f1)
Constructor.
Definition: JMathlib2D.hh:41
const JMake2X & getGradient(const double x, const double y) const
Get gradient.
Definition: JMathlib2D.hh:77
JMake2X()
Default constructor.
Definition: JMathlib2D.hh:32
double getValue(const double x, const double y) const
Function value.
Definition: JMathlib2D.hh:64
JMake2X(const Args &...args)
Constructor.
Definition: JMathlib2D.hh:52
Make 2D function of y from 1D function.
Definition: JMathlib2D.hh:95
JMake2Y(const Args &...args)
Constructor.
Definition: JMathlib2D.hh:122
JMake2Y(const JF1_t &f1)
Constructor.
Definition: JMathlib2D.hh:111
JMake2Y()
Default constructor.
Definition: JMathlib2D.hh:102
const JMake2Y & getGradient(const double x, const double y) const
Get gradient.
Definition: JMathlib2D.hh:147
double getValue(const double x, const double y) const
Function value.
Definition: JMathlib2D.hh:134
forward declaration for fixed power of function.
Definition: JMathlib.hh:354