Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMathlib.hh
Go to the documentation of this file.
1 #ifndef __JMATH__JMATHLIB__
2 #define __JMATH__JMATHLIB__
3 
4 #include <cstddef>
5 #include <vector>
6 #include <initializer_list>
7 #include <cmath>
8 
9 #include "JMath/JConstants.hh"
10 
11 
12 /**
13  * \file
14  * Functional algebra.
15  *
16  * \author mdejong
17  */
18 
19 namespace JMATH {}
20 namespace JPP { using namespace JMATH; }
21 
22 namespace JMATH {
23 
24  struct _vF; //!< void function
25 
26 
27  /**
28  * Auxiliary data structure to make C-array from list of values.
29  */
30  struct make_carray :
31  public std::vector<double>
32  {
33  /**
34  * Constructor.
35  *
36  * \param args list of values
37  */
38  template<class ...Args>
39  make_carray(const Args& ...args)
40  {
41  add(args...);
42  }
43 
44 
45  /**
46  * Type conversion operator.
47  *
48  * \return pointer to list of values
49  */
50  operator const double*() const
51  {
52  return this->data();
53  }
54 
55  private:
56  /**
57  * Recursive method for adding values to array.
58  *
59  * \param x first value
60  * \param args remaining values
61  */
62  template<class ...Args>
63  void add(const double x, const Args& ...args)
64  {
65  this->push_back(x);
66 
67  add(args...);
68  }
69 
70 
71  /**
72  * Termination method for adding values to array.
73  *
74  * \param x final value
75  */
76  void add(const double x)
77  {
78  this->push_back(x);
79  }
80  };
81 
82 
83  /**
84  * Auxiliary data structure for list of parameters.
85  *
86  * The template argument refers to the function that could be fitted to some data.\n
87  * The parameters of the function should be data members of type <tt>double</tt>.
88  */
89  template<class JF1_t>
90  struct parameter_list :
91  public std::vector<double JF1_t::*>
92  {
93  /**
94  * Default constructor.
95  */
97  {}
98 
99 
100  /**
101  * Constructor.
102  *
103  * \param parameter parameter
104  */
105  parameter_list(double JF1_t::*parameter) :
106  std::vector<double JF1_t::*>(1, parameter)
107  {}
108 
109 
110  /**
111  * Constructor.
112  *
113  * \param parameters parameters
114  */
116  std::vector<double JF1_t::*>(parameters)
117  {}
118 
119 
120  /**
121  * Combine constructor.
122  *
123  * \param parameters parameters
124  * \param parameter parameter
125  */
126  template<class U>
127  parameter_list(const parameter_list<U>& parameters, double JF1_t::* parameter) :
128  std::vector<double JF1_t::*>(parameters.begin(), parameters.end())
129  {
130  this->push_back(parameter);
131  }
132 
133 
134  /**
135  * Combine constructor.
136  *
137  * \param first first parameters
138  * \param second second parameters
139  */
140  template<class U, class V>
142  {
143  for (const auto& i : first) { this->push_back(i); }
144  for (const auto& i : second) { this->push_back(i); }
145  }
146  };
147 
148 
149  /**
150  * Get number of parameters.
151  *
152  * \return number of parameters
153  */
154  template<class JF1_t>
155  inline size_t getNumberOfParameters()
156  {
157  return JF1_t::parameters.size();
158  }
159 
160 
161  /**
162  * Get value of parameter at given index.
163  *
164  * \param f1 function
165  * \param i index
166  * \return value
167  */
168  template<class JF1_t>
169  inline double getParameter(const JF1_t& f1, const size_t i)
170  {
171  return f1.*JF1_t::parameters.at(i);
172  }
173 
174 
175  /**
176  * Set values of all parameters.
177  *
178  * \param f1 pointer to function
179  * \param values pointer to list of values
180  */
181  template<class JF1_t>
182  inline void setParameters(JF1_t* f1, const double* values)
183  {
184  if (f1 != NULL && values != NULL) {
185  for (size_t i = 0; i != JF1_t::parameters.size(); ++i) {
186  f1->*JF1_t::parameters[i] = values[i];
187  }
188  }
189  }
190 
191 
192  /**
193  * Auxiliary base class for mathematical operations on parameters of function.
194  */
195  template<class JF1_t>
196  struct JCalculus
197  {
198  /**
199  * Negate function.
200  *
201  * \return this function
202  */
203  JF1_t& negate()
204  {
205  for (const auto& i : JF1_t::parameters) {
206  static_cast<JF1_t&>(*this).*i = -(static_cast<JF1_t&>(*this).*i);
207  }
208 
209  return static_cast<JF1_t&>(*this);
210  }
211 
212 
213  /**
214  * Add function.
215  *
216  * \param f1 function
217  * \return this function
218  */
219  JF1_t& add(const JF1_t& f1)
220  {
221  for (const auto& i : JF1_t::parameters) {
222  static_cast<JF1_t&>(*this).*i += f1.*i;
223  }
224 
225  return static_cast<JF1_t&>(*this);
226  }
227 
228 
229  /**
230  * Subtract function.
231  *
232  * \param f1 function
233  * \return this function
234  */
235  JF1_t& sub(const JF1_t& f1)
236  {
237  for (const auto& i : JF1_t::parameters) {
238  static_cast<JF1_t&>(*this).*i -= f1.*i;
239  }
240 
241  return static_cast<JF1_t&>(*this);
242  }
243 
244 
245  /**
246  * Scale function.
247  *
248  * \param factor factor
249  * \return this function
250  */
251  JF1_t& mul(const double factor)
252  {
253  for (const auto& i : JF1_t::parameters) {
254  static_cast<JF1_t&>(*this).*i *= factor;
255  }
256 
257  return static_cast<JF1_t&>(*this);
258  }
259 
260 
261  /**
262  * Scale function.
263  *
264  * \param factor factor
265  * \return this function
266  */
267  JF1_t& div(const double factor)
268  {
269  for (const auto& i : JF1_t::parameters) {
270  static_cast<JF1_t&>(*this).*i /= factor;
271  }
272 
273  return static_cast<JF1_t&>(*this);
274  }
275 
276 
277  /**
278  * Add function.
279  *
280  * \param function this function
281  * \param value value
282  * \return this function
283  */
284  friend JF1_t& operator+=(JF1_t& function, const JF1_t& value)
285  {
286  return function.add(value);
287  }
288 
289 
290  /**
291  * Subtract function.
292  *
293  * \param function this function
294  * \param value value
295  * \return this function
296  */
297  friend JF1_t& operator-=(JF1_t& function, const JF1_t& value)
298  {
299  return function.sub(value);
300  }
301 
302 
303  /**
304  * Scale function.
305  *
306  * \param function this function
307  * \param factor factor
308  * \return this function
309  */
310  friend JF1_t& operator*=(JF1_t& function, const double factor)
311  {
312  return function.mul(factor);
313  }
314 
315 
316  /**
317  * Scale function.
318  *
319  * \param function this function
320  * \param factor factor
321  * \return this function
322  */
323  friend JF1_t& operator/=(JF1_t& function, const double factor)
324  {
325  return function.div(factor);
326  }
327  };
328 
329 
330  template<class JF1_t>
331  struct JNegate; //!< forward declaration for negate of function.
332 
333  template<class JF1_t, class JF2_t = double>
334  struct JAdd; //!< forward declaration for addition of fuction.
335 
336  template<class JF1_t, class JF2_t = double>
337  struct JSub; //!< forward declaration for subtraction of fuction.
338 
339  template<class JF1_t, class JF2_t = double>
340  struct JMul; //!< forward declaration for multiplication of fuction.
341 
342  template<class JF1_t, class JF2_t = double>
343  struct JDiv; //!< forward declaration for division of fuction.
344 
345  template<class JF1_t>
346  struct JFn; //!< forward declaration for fixed power of function.
347 
348 
349 
350  /**
351  * Auxiliary base class for mathematical operations on functions.
352  */
353  template<class JF1_t>
354  struct JMathlib {
355  /**
356  * Function value.
357  *
358  * \param args abscissa value(s)
359  * \return function value
360  */
361  template<class ...Args>
362  double operator()(const Args& ...args) const
363  {
364  return static_cast<const JF1_t&>(*this).getValue(args...);
365  }
366 
367 
368  /**
369  * Affirm operator.
370  *
371  * \param function this function
372  * \return result function
373  */
374  friend const JF1_t& operator+(const JF1_t& function)
375  {
376  return function;
377  }
378 
379 
380  /**
381  * Negate operator.
382  *
383  * \param function this function
384  * \return result function
385  */
386  friend JNegate<JF1_t> operator-(const JF1_t& function)
387  {
388  return JNegate<JF1_t>(function);
389  }
390 
391 
392  /**
393  * Addition of constant value.
394  *
395  * \param f1 function
396  * \param value value
397  * \return result function
398  */
399  friend JAdd<JF1_t> operator+(const JF1_t& f1, const double value)
400  {
401  return JAdd<JF1_t>(f1, value);
402  }
403 
404 
405  /**
406  * Addition of constant value.
407  *
408  * \param value value
409  * \param f1 function
410  * \return result function
411  */
412  friend JAdd<JF1_t> operator+(const double value, const JF1_t& f1)
413  {
414  return JAdd<JF1_t>(f1, value);
415  }
416 
417 
418  /**
419  * Subtraction of constant value.
420  *
421  * \param f1 function
422  * \param value value
423  * \return result function
424  */
425  friend JSub<JF1_t> operator-(const JF1_t& f1, const double value)
426  {
427  return JSub<JF1_t>(f1, value);
428  }
429 
430 
431  /**
432  * Subtraction of constant value.
433  *
434  * \param f1 function
435  * \param value value
436  * \return result function
437  */
438  friend JAdd< JNegate<JF1_t> > operator-(const double value, const JF1_t& f1)
439  {
440  return JAdd< JNegate<JF1_t> >(JNegate<JF1_t>(f1), value);
441  }
442 
443 
444  /**
445  * Multiplication of constant value.
446  *
447  * \param f1 function
448  * \param value value
449  * \return result function
450  */
451  friend JMul<JF1_t> operator*(const JF1_t& f1, const double value)
452  {
453  return JMul<JF1_t>(f1, value);
454  }
455 
456 
457  /**
458  * Multiplication of constant value.
459  *
460  * \param value value
461  * \param f1 function
462  * \return result function
463  */
464  friend JMul<JF1_t> operator*(const double value, const JF1_t& f1)
465  {
466  return JMul<JF1_t>(f1, value);
467  }
468 
469 
470  /**
471  * Division of constant value.
472  *
473  * \param f1 function
474  * \param value value
475  * \return result function
476  */
477  friend JDiv<JF1_t> operator/(const JF1_t& f1, const double value)
478  {
479  return JDiv<JF1_t>(f1, value);
480  }
481 
482 
483  /**
484  * Addition of two functions.
485  *
486  * \param f1 first function
487  * \param f2 second function
488  * \return result function
489  */
490  template<class JF2_t>
491  friend JAdd<JF1_t, JF2_t> operator+(const JF1_t& f1, const JF2_t& f2)
492  {
493  return JAdd<JF1_t, JF2_t>(f1, f2);
494  }
495 
496 
497  /**
498  * Subtraction of two functions.
499  *
500  * \param f1 first function
501  * \param f2 second function
502  * \return result function
503  */
504  template<class JF2_t>
505  friend JSub<JF1_t, JF2_t> operator-(const JF1_t& f1, const JF2_t& f2)
506  {
507  return JSub<JF1_t, JF2_t>(f1, f2);
508  }
509 
510 
511  /**
512  * Multiplication of two functions.
513  *
514  * \param f1 first function
515  * \param f2 second function
516  * \return result function
517  */
518  template<class JF2_t>
519  friend JMul<JF1_t, JF2_t> operator*(const JF1_t& f1, const JF2_t& f2)
520  {
521  return JMul<JF1_t, JF2_t>(f1, f2);
522  }
523 
524 
525  /**
526  * Division of two functions.
527  *
528  * \param f1 first function
529  * \param f2 second function
530  * \return result function
531  */
532  template<class JF2_t>
533  friend JDiv<JF1_t, JF2_t> operator/(const JF1_t& f1, const JF2_t& f2)
534  {
535  return JDiv<JF1_t, JF2_t>(f1, f2);
536  }
537 
538 
539  /**
540  * Power of operator.
541  *
542  * \param function this function
543  * \param N power
544  * \return result function
545  */
546  friend JFn<JF1_t> operator^(const JF1_t& function, int N)
547  {
548  return JFn<JF1_t>(function, N);
549  }
550  };
551 
552 
553  /**
554  * Negate of function.
555  */
556  template<class JF1_t>
557  struct JNegate :
558  public JMathlib< JNegate<JF1_t> >,
559  public JF1_t
560  {
561  using JMathlib< JNegate<JF1_t> >::operator();
562 
563 
564  /**
565  * Default constructor.
566  */
568  {}
569 
570 
571  /**
572  * Constructor.
573  *
574  * \param f1 function
575  */
576  JNegate(const JF1_t& f1) :
577  JF1_t(f1)
578  {}
579 
580 
581  /**
582  * Function value.
583  *
584  * \param args abscissa value(s)
585  * \return function value
586  */
587  template<class ...Args>
588  double getValue(const Args& ...args) const
589  {
590  return -static_cast<const JF1_t&>(*this).getValue(args...);
591  }
592 
593 
594  /**
595  * Derivative value.
596  *
597  * \param x abscissa value
598  * \return derivative value
599  */
600  double getDerivative(const double x) const
601  {
602  return -static_cast<const JF1_t&>(*this).getDerivative(x);
603  }
604 
605 
606  /**
607  * Get gradient.
608  *
609  * \param args abscissa value(s)
610  * \return gradient
611  */
612  template<class ...Args>
613  const JNegate& getGradient(const Args& ...args) const
614  {
615  static JNegate gradient;
616 
617  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
618  static_cast<JF1_t&>(gradient).negate();
619 
620  return gradient;
621  }
622  };
623 
624 
625  /**
626  * Addition of constant value.
627  */
628  template<class JF1_t>
629  struct JAdd<JF1_t, double> :
630  public JMathlib< JAdd<JF1_t, double> >,
631  public JF1_t
632  {
633  using JMathlib< JAdd<JF1_t, double> >::operator();
634 
635 
636  /**
637  * Default constructor.
638  */
640  {}
641 
642 
643  /**
644  * Constructor.
645  *
646  * \param f1 function
647  * \param value value
648  */
649  JAdd(const JF1_t& f1, const double value) :
650  JF1_t(f1),
651  value(value)
652  {}
653 
654 
655  /**
656  * Function value.
657  *
658  * \param args abscissa value(s)
659  * \return function value
660  */
661  template<class ...Args>
662  double getValue(const Args& ...args) const
663  {
664  return static_cast<const JF1_t&>(*this).getValue(args...) + value;
665  }
666 
667 
668  /**
669  * Derivative value.
670  *
671  * \param x abscissa value
672  * \return derivative value
673  */
674  double getDerivative(const double x) const
675  {
676  return static_cast<const JF1_t&>(*this).getDerivative(x);
677  }
678 
679 
680  /**
681  * Get gradient.
682  *
683  * \param args abscissa value(s)
684  * \return gradient
685  */
686  template<class ...Args>
687  const JAdd& getGradient(const Args& ...args) const
688  {
689  static JAdd gradient;
690 
691  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
692 
693  return gradient;
694  }
695 
696  private:
697  double value;
698  };
699 
700 
701  /**
702  * Subtraction of constant value.
703  */
704  template<class JF1_t>
705  struct JSub<JF1_t, double> :
706  public JMathlib< JSub<JF1_t, double> >,
707  public JF1_t
708  {
709  using JMathlib< JSub<JF1_t, double> >::operator();
710 
711 
712  /**
713  * Default constructor.
714  */
716  {}
717 
718 
719  /**
720  * Constructor.
721  *
722  * \param f1 function
723  * \param value value
724  */
725  JSub(const JF1_t& f1, const double value) :
726  JF1_t(f1),
727  value(value)
728  {}
729 
730 
731  /**
732  * Function value.
733  *
734  * \param args abscissa value(s)
735  * \return function value
736  */
737  template<class ...Args>
738  double getValue(const Args& ...args) const
739  {
740  return static_cast<const JF1_t&>(*this).getValue(args...) - value;
741  }
742 
743 
744  /**
745  * Derivative value.
746  *
747  * \param x abscissa value
748  * \return derivative value
749  */
750  double getDerivative(const double x) const
751  {
752  return static_cast<const JF1_t&>(*this).getDerivative(x);
753  }
754 
755 
756  /**
757  * Get gradient.
758  *
759  * \param args abscissa value(s)
760  * \return gradient
761  */
762  template<class ...Args>
763  const JSub& getGradient(const Args& ...args) const
764  {
765  static JSub gradient;
766 
767  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
768 
769  return gradient;
770  }
771 
772  private:
773  double value;
774  };
775 
776 
777  /**
778  * Multiplication of constant value.
779  */
780  template<class JF1_t>
781  struct JMul<JF1_t, double> :
782  public JMathlib< JMul<JF1_t, double> >,
783  public JF1_t
784  {
785  using JMathlib< JMul<JF1_t, double> >::operator();
786 
787 
788  /**
789  * Default constructor.
790  */
792  {}
793 
794 
795  /**
796  * Constructor.
797  *
798  * \param f1 function
799  * \param value value
800  */
801  JMul(const JF1_t& f1, const double value) :
802  JF1_t(f1),
803  value(value)
804  {}
805 
806 
807  /**
808  * Function value.
809  *
810  * \param args abscissa value(s)
811  * \return function value
812  */
813  template<class ...Args>
814  double getValue(const Args& ...args) const
815  {
816  return static_cast<const JF1_t&>(*this).getValue(args...) * value;
817  }
818 
819 
820  /**
821  * Derivative value.
822  *
823  * \param x abscissa value
824  * \return derivative value
825  */
826  double getDerivative(const double x) const
827  {
828  return static_cast<const JF1_t&>(*this).getDerivative(x) * value;
829  }
830 
831 
832  /**
833  * Get gradient.
834  *
835  * \param args abscissa value(s)
836  * \return gradient
837  */
838  template<class ...Args>
839  const JMul& getGradient(const Args& ...args) const
840  {
841  static JMul gradient;
842 
843  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
844  static_cast<JF1_t&>(gradient) *= value;
845 
846  return gradient;
847  }
848 
849  private:
850  double value;
851  };
852 
853 
854  /**
855  * Division of constant value.
856  */
857  template<class JF1_t>
858  struct JDiv<JF1_t, double> :
859  public JMathlib< JDiv<JF1_t, double> >,
860  public JF1_t
861  {
862  using JMathlib< JDiv<JF1_t, double> >::operator();
863 
864 
865  /**
866  * Default constructor.
867  */
869  {}
870 
871 
872  /**
873  * Constructor.
874  *
875  * \param f1 function
876  * \param value value
877  */
878  JDiv(const JF1_t& f1, const double value) :
879  JF1_t(f1),
880  value(value)
881  {}
882 
883 
884  /**
885  * Function value.
886  *
887  * \param args abscissa value(s)
888  * \return function value
889  */
890  template<class ...Args>
891  double getValue(const Args& ...args) const
892  {
893  return static_cast<const JF1_t&>(*this).getValue(args...) / value;
894  }
895 
896 
897  /**
898  * Derivative value.
899  *
900  * \param x abscissa value
901  * \return derivative value
902  */
903  double getDerivative(const double x) const
904  {
905  return static_cast<const JF1_t&>(*this).getDerivative(x) / value;
906  }
907 
908 
909  /**
910  * Get gradient.
911  *
912  * \param args abscissa value(s)
913  * \return gradient
914  */
915  template<class ...Args>
916  const JDiv& getGradient(const Args& ...args) const
917  {
918  static JDiv gradient;
919 
920  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
921  static_cast<JF1_t&>(gradient) /= value;
922 
923  return gradient;
924  }
925 
926  private:
927  double value;
928  };
929 
930 
931  /**
932  * Auxiliary data structure for pair of functions.
933  */
934  template<class JF1_t, class JF2_t>
935  struct JPair :
936  public JF1_t,
937  public JF2_t,
938  public JCalculus< JPair<JF1_t, JF2_t> >
939  {
945 
946 
947  /**
948  * Default constructor.
949  */
951  {}
952 
953 
954  /**
955  * Constructor.
956  *
957  * \param f1 first function
958  * \param f2 second function
959  */
960  JPair(const JF1_t& f1, const JF2_t& f2) :
961  JF1_t(f1),
962  JF2_t(f2)
963  {}
964 
965  static const parameter_list<JPair> parameters; //!< parameters
966  };
967 
968  /**
969  * Set parameters.
970  */
971  template<class JF1_t, class JF2_t>
973 
974 
975  /**
976  * Addition of two functions.
977  */
978  template<class JF1_t, class JF2_t>
979  struct JAdd :
980  public JMathlib< JAdd<JF1_t, JF2_t> >,
981  public JPair<JF1_t, JF2_t>
982  {
983  using JMathlib< JAdd<JF1_t, JF2_t> >::operator();
984 
985 
986  /**
987  * Default constructor.
988  */
990  {}
991 
992 
993  /**
994  * Constructor.
995  *
996  * \param f1 first function
997  * \param f2 second function
998  */
999  JAdd(const JF1_t& f1, const JF2_t& f2) :
1000  JPair<JF1_t, JF2_t>(f1, f2)
1001  {}
1002 
1003 
1004  /**
1005  * Function value.
1006  *
1007  * \param args abscissa value(s)
1008  * \return function value
1009  */
1010  template<class ...Args>
1011  double getValue(const Args& ...args) const
1012  {
1013  return (static_cast<const JF1_t&>(*this).getValue(args...) +
1014  static_cast<const JF2_t&>(*this).getValue(args...));
1015  }
1016 
1017 
1018  /**
1019  * Derivative value.
1020  *
1021  * \param x abscissa value
1022  * \return derivative value
1023  */
1024  double getDerivative(const double x) const
1025  {
1026  return (static_cast<const JF1_t&>(*this).getDerivative(x) +
1027  static_cast<const JF2_t&>(*this).getDerivative(x));
1028  }
1029 
1030 
1031  /**
1032  * Get gradient.
1033  *
1034  * \param args abscissa value(s)
1035  * \return gradient
1036  */
1037  template<class ...Args>
1038  const JAdd& getGradient(const Args& ...args) const
1039  {
1040  static JAdd gradient;
1041 
1042  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
1043  static_cast<JF2_t&>(gradient) = static_cast<const JF2_t&>(*this).getGradient(args...);
1044 
1045  return gradient;
1046  }
1047  };
1048 
1049 
1050  /**
1051  * Subtraction of two functions.
1052  */
1053  template<class JF1_t, class JF2_t>
1054  struct JSub :
1055  public JMathlib< JSub<JF1_t, JF2_t> >,
1056  public JPair<JF1_t, JF2_t>
1057  {
1058  using JMathlib< JSub<JF1_t, JF2_t> >::operator();
1059 
1060 
1061  /**
1062  * Default constructor.
1063  */
1065  {}
1066 
1067 
1068  /**
1069  * Constructor.
1070  *
1071  * \param f1 first function
1072  * \param f2 second function
1073  */
1074  JSub(const JF1_t& f1, const JF2_t& f2) :
1075  JPair<JF1_t, JF2_t>(f1, f2)
1076  {}
1077 
1078 
1079  /**
1080  * Function value.
1081  *
1082  * \param args abscissa value(s)
1083  * \return function value
1084  */
1085  template<class ...Args>
1086  double getValue(const Args& ...args) const
1087  {
1088  return (static_cast<const JF1_t&>(*this).getValue(args...) -
1089  static_cast<const JF2_t&>(*this).getValue(args...));
1090  }
1091 
1092 
1093  /**
1094  * Derivative value.
1095  *
1096  * \param x abscissa value
1097  * \return derivative value
1098  */
1099  double getDerivative(const double x) const
1100  {
1101  return (static_cast<const JF1_t&>(*this).getDerivative(x) -
1102  static_cast<const JF2_t&>(*this).getDerivative(x));
1103  }
1104 
1105 
1106  /**
1107  * Get gradient.
1108  *
1109  * \param args abscissa value(s)
1110  * \return gradient
1111  */
1112  template<class ...Args>
1113  const JSub& getGradient(const Args& ...args) const
1114  {
1115  static JSub gradient;
1116 
1117  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
1118  static_cast<JF2_t&>(gradient) = static_cast<const JF2_t&>(*this).getGradient(args...);
1119  static_cast<JF2_t&>(gradient).negate();
1120 
1121  return gradient;
1122  }
1123  };
1124 
1125 
1126  /**
1127  * Multiplication of two functions.
1128  */
1129  template<class JF1_t, class JF2_t>
1130  struct JMul :
1131  public JMathlib< JMul<JF1_t, JF2_t> >,
1132  public JPair<JF1_t, JF2_t>
1133  {
1134  using JMathlib< JMul<JF1_t, JF2_t> >::operator();
1135 
1136 
1137  /**
1138  * Default constructor.
1139  */
1141  {}
1142 
1143 
1144  /**
1145  * Constructor.
1146  *
1147  * \param f1 first function
1148  * \param f2 second function
1149  */
1150  JMul(const JF1_t& f1, const JF2_t& f2) :
1151  JPair<JF1_t, JF2_t>(f1, f2)
1152  {}
1153 
1154 
1155  /**
1156  * Function value.
1157  *
1158  * \param args abscissa value(s)
1159  * \return function value
1160  */
1161  template<class ...Args>
1162  double getValue(const Args& ...args) const
1163  {
1164  return (static_cast<const JF1_t&>(*this).getValue(args...) *
1165  static_cast<const JF2_t&>(*this).getValue(args...));
1166  }
1167 
1168 
1169  /**
1170  * Derivative value.
1171  *
1172  * \param x abscissa value
1173  * \return derivative value
1174  */
1175  double getDerivative(const double x) const
1176  {
1177  return (static_cast<const JF1_t&>(*this).getDerivative(x) * static_cast<const JF2_t&>(*this).getValue(x) +
1178  static_cast<const JF1_t&>(*this).getValue(x) * static_cast<const JF2_t&>(*this).getDerivative(x));
1179  }
1180 
1181 
1182  /**
1183  * Get gradient.
1184  *
1185  * \param args abscissa value(s)
1186  * \return gradient
1187  */
1188  template<class ...Args>
1189  const JMul& getGradient(const Args& ...args) const
1190  {
1191  static JMul gradient;
1192 
1193  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
1194  static_cast<JF1_t&>(gradient) *= static_cast<const JF2_t&>(*this).getValue(args...);
1195  static_cast<JF2_t&>(gradient) = static_cast<const JF2_t&>(*this).getGradient(args...);
1196  static_cast<JF2_t&>(gradient) *= static_cast<const JF1_t&>(*this).getValue(args...);
1197 
1198  return gradient;
1199  }
1200  };
1201 
1202 
1203  /**
1204  * Division of two functions.
1205  */
1206  template<class JF1_t, class JF2_t>
1207  struct JDiv :
1208  public JMathlib< JDiv<JF1_t, JF2_t> >,
1209  public JPair<JF1_t, JF2_t>
1210  {
1211  using JMathlib< JDiv<JF1_t, JF2_t> >::operator();
1212 
1213 
1214  /**
1215  * Default constructor.
1216  */
1218  {}
1219 
1220 
1221  /**
1222  * Constructor.
1223  *
1224  * \param f1 first function
1225  * \param f2 second function
1226  */
1227  JDiv(const JF1_t& f1, const JF2_t& f2) :
1228  JPair<JF1_t, JF2_t>(f1, f2)
1229  {}
1230 
1231 
1232  /**
1233  * Function value.
1234  *
1235  * \param args abscissa value(s)
1236  * \return function value
1237  */
1238  template<class ...Args>
1239  double getValue(const Args& ...args) const
1240  {
1241  return (static_cast<const JF1_t&>(*this).getValue(args...) /
1242  static_cast<const JF2_t&>(*this).getValue(args...));
1243  }
1244 
1245 
1246  /**
1247  * Derivative value.
1248  *
1249  * \param x abscissa value
1250  * \return derivative value
1251  */
1252  double getDerivative(const double x) const
1253  {
1254  const double v = static_cast<const JF1_t&>(*this).getValue(x);
1255  const double w = static_cast<const JF2_t&>(*this).getValue(x);
1256 
1257  return (static_cast<const JF1_t&>(*this).getDerivative(x) * w -
1258  v * static_cast<const JF2_t&>(*this).getDerivative(x)) / (w*w);
1259  }
1260 
1261 
1262  /**
1263  * Get gradient.
1264  *
1265  * \param args abscissa value(s)
1266  * \return gradient
1267  */
1268  template<class ...Args>
1269  const JDiv& getGradient(const Args& ...args) const
1270  {
1271  static JDiv gradient;
1272 
1273  const double v = static_cast<const JF1_t&>(*this).getValue(args...);
1274  const double w = static_cast<const JF2_t&>(*this).getValue(args...);
1275 
1276  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
1277  static_cast<JF1_t&>(gradient) *= 1.0/w;
1278  static_cast<JF2_t&>(gradient) = static_cast<const JF2_t&>(*this).getGradient(args...);
1279  static_cast<JF2_t&>(gradient) *= -v/(w*w);
1280 
1281  return gradient;
1282  }
1283  };
1284 
1285 
1286  /**
1287  * Fixed power of x.
1288  */
1289  template<class JF1_t>
1290  struct JFn :
1291  public JMathlib < JFn<JF1_t> >,
1292  public JF1_t
1293  {
1294 
1295  using JMathlib< JFn<JF1_t> >::operator();
1296 
1297 
1298  /**
1299  * Default constructor.
1300  */
1301  JFn() :
1302  JF1_t(),
1303  N(1)
1304  {}
1305 
1306 
1307  /**
1308  * Constructor.
1309  *
1310  * \param f1 first function
1311  * \param N power
1312  */
1313  JFn(const JF1_t& f1, const int N) :
1314  JF1_t(f1),
1315  N(N)
1316  {}
1317 
1318 
1319  /**
1320  * Function value.
1321  *
1322  * \param args abscissa value(s)
1323  * \return function value
1324  */
1325  template<class ...Args>
1326  double getValue(const Args& ...args) const
1327  {
1328  const double u = static_cast<const JF1_t&>(*this).getValue(args...);
1329 
1330  return pow(u, N);
1331  }
1332 
1333 
1334  /**
1335  * Derivative value.
1336  *
1337  * \param x abscissa value
1338  * \return derivative value
1339  */
1340  double getDerivative(const double x) const
1341  {
1342  const double u = static_cast<const JF1_t&>(*this).getValue(x);
1343  const double v = static_cast<const JF1_t&>(*this).getDerivative(x);
1344 
1345  return N * pow(u, N - 1) * v;
1346  }
1347 
1348 
1349  /**
1350  * Get gradient.
1351  *
1352  * \param args abscissa value(s)
1353  * \return gradient
1354  */
1355  template<class ...Args>
1356  const JFn& getGradient(const Args& ...args) const
1357  {
1358  static JFn gradient;
1359 
1360  const double u = static_cast<const JF1_t&>(*this).getValue(args...);
1361  const double w = N * pow(u, N - 1);
1362 
1363  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(args...);
1364  static_cast<JF1_t&>(gradient) *= w;
1365 
1366  return gradient;
1367  }
1368 
1369  int N;
1370  };
1371 
1372 
1373  /**
1374  * Recursive template class for polynomial function.
1375  */
1376  template<int ID_t, size_t N>
1377  struct JPolynome :
1378  public JMathlib < JPolynome<ID_t, N> >,
1379  public JCalculus< JPolynome<ID_t, N> >,
1380  public JPolynome<ID_t, N - 1>
1381  {
1382  static const int ID = ID_t;
1383 
1384  static const size_t NUMBER_OF_DEGREES = N;
1385 
1391  using JMathlib < JPolynome<ID_t, N> >::operator();
1392 
1393 
1394  /**
1395  * Default constructor.
1396  */
1398  a(0.0)
1399  {}
1400 
1401 
1402  /**
1403  * Constructor.
1404  *
1405  * \param args list of values
1406  */
1407  template<class ...Args>
1408  JPolynome(const Args& ...args) :
1409  JPolynome()
1410  {
1411  set(make_carray(args...));
1412  }
1413 
1414 
1415  /**
1416  * Function value.
1417  *
1418  * \param x abscissa value
1419  * \return function value
1420  */
1421  double getValue(const double x) const
1422  {
1423  return a * pow(x,N) + static_cast<const JPolynome<ID_t, N - 1>&>(*this).getValue(x);
1424  }
1425 
1426 
1427  /**
1428  * Derivative value.
1429  *
1430  * \param x abscissa value
1431  * \return derivative value
1432  */
1433  double getDerivative(const double x) const
1434  {
1435  return N * a * pow(x,N-1) + static_cast<const JPolynome<ID_t, N - 1>&>(*this).getDerivative(x);
1436  }
1437 
1438 
1439  /**
1440  * Get gradient.
1441  *
1442  * \param x abscissa value
1443  * \return gradient
1444  */
1445  const JPolynome& getGradient(const double x) const
1446  {
1447  static JPolynome gradient; // d(f)/d(a)
1448 
1449  gradient.a = pow(x,N);
1450 
1451  static_cast<JPolynome<ID_t, N - 1>&>(gradient) = static_cast<const JPolynome<ID_t, N - 1>&>(*this).getGradient(x);
1452 
1453  return gradient;
1454  }
1455 
1456  double a; //!< a[N]
1457  static const parameter_list<JPolynome> parameters; //!< parameters
1458 
1459  protected:
1460  /**
1461  * Set parameter values.
1462  *
1463  * \param pA pointer to list of values
1464  */
1465  void set(const double* pA)
1466  {
1467  a = pA[N];
1468 
1470  }
1471  };
1472 
1473  /**
1474  * Set parameters.
1475  */
1476  template<int ID_t, size_t N>
1478 
1479 
1480  /**
1481  * Termination class for polynomial function.
1482  */
1483  template<int ID_t>
1484  struct JPolynome<ID_t, 0> :
1485  public JMathlib < JPolynome<ID_t, 0> >,
1486  public JCalculus< JPolynome<ID_t, 0> >
1487  {
1488  static const int ID = ID_t;
1489 
1490  static const size_t NUMBER_OF_DEGREES = 0;
1491 
1492 
1493  /**
1494  * Default constructor.
1495  */
1497  a(0.0)
1498  {}
1499 
1500 
1501  /**
1502  * Constructor.
1503  *
1504  * \param a value
1505  */
1506  JPolynome(const double a) :
1507  a(a)
1508  {}
1509 
1510 
1511  /**
1512  * Function value.
1513  *
1514  * \return function value
1515  */
1516  double getValue(...) const
1517  {
1518  return a;
1519  }
1520 
1521 
1522  /**
1523  * Derivative value.
1524  *
1525  * \return derivative value
1526  */
1527  double getDerivative(...) const
1528  {
1529  return 0.0;
1530  }
1531 
1532 
1533  /**
1534  * Get gradient.
1535  *
1536  * \return gradient
1537  */
1538  const JPolynome& getGradient(...) const
1539  {
1540  static JPolynome gradient; // d(f)/d(a)
1541 
1542  gradient.a = 1.0;
1543 
1544  return gradient;
1545  }
1546 
1547  double a; //!< a[0]
1548  static const parameter_list<JPolynome> parameters; //!< parameters
1549 
1550  protected:
1551  /**
1552  * Set parameter values.
1553  *
1554  * \param array pointer to list of values
1555  */
1556  void set(const double* array)
1557  {
1558  a = array[0];
1559  }
1560  };
1561 
1562  /**
1563  * Set parameters.
1564  */
1565  template<int ID_t>
1567 
1568 
1569  template<int ID_t>
1570  using JP0 = JPolynome<ID_t, 0>; //!< short hand for 0th degree polynome
1571 
1572  template<int ID_t>
1573  using JP1 = JPolynome<ID_t, 1>; //!< short hand for 1st degree polynome
1574 
1575  template<int ID_t>
1576  using JP2 = JPolynome<ID_t, 2>; //!< short hand for 2nd degree polynome
1577 
1578  template<int ID_t>
1579  using JP3 = JPolynome<ID_t, 3>; //!< short hand for 3rd degree polynome
1580 
1581 
1582  /**
1583  * Gauss function.
1584  */
1585  template<int ID_t, bool normalised = false>
1586  struct JGauss :
1587  public JMathlib < JGauss<ID_t> >,
1588  public JCalculus< JGauss<ID_t> >
1589  {
1590  static const int ID = ID_t;
1591 
1592 
1593  /**
1594  * Default constructor.
1595  */
1597  center(0.0),
1598  sigma (0.0)
1599  {}
1600 
1601 
1602  /**
1603  * Constructor.
1604  *
1605  * \param center center
1606  * \param sigma sigma
1607  */
1608  JGauss(const double center,
1609  const double sigma) :
1610  center(center),
1611  sigma (sigma)
1612  {}
1613 
1614 
1615  /**
1616  * Function value.
1617  *
1618  * \param x abscissa value
1619  * \return function value
1620  */
1621  double getValue(const double x) const
1622  {
1623  const double u = (x - center) / sigma;
1624 
1625  return get(u);
1626  }
1627 
1628 
1629  /**
1630  * Derivative value.
1631  *
1632  * \param x abscissa value
1633  * \return derivative value
1634  */
1635  double getDerivative(const double x) const
1636  {
1637  const double w = 1.0 / sigma;
1638  const double u = (x - center) / sigma;
1639 
1640  return get(u) * -u * w;
1641  }
1642 
1643 
1644  /**
1645  * Get gradient.
1646  *
1647  * \param x abscissa value
1648  * \return gradient
1649  */
1650  const JGauss& getGradient(const double x) const
1651  {
1652  static JGauss gradient;
1653 
1654  const double w = 1.0 / sigma;
1655  const double u = (x - center) * w;
1656  const double f0 = get(u);
1657 
1658  gradient.center = f0 * u * w; // d(f)/d(center)
1659  gradient.sigma = f0 * u * u * w; // d(f)/d(sigma)
1660 
1661  return gradient;
1662  }
1663 
1664  double center; //!< center
1665  double sigma; //!< sigma
1666  static const parameter_list<JGauss> parameters; //!< parameters
1667 
1668  private:
1669  /**
1670  * Get ordinate value.
1671  *
1672  * \param u abscissa value
1673  * \return ordinate value
1674  */
1675  inline double get(const double u) const
1676  {
1677  return exp(-0.5*u*u);
1678  }
1679  };
1680 
1681  /**
1682  * Set parameters.
1683  */
1684  template<int ID_t, bool normalised>
1686 
1687 
1688  /**
1689  * Gauss function.
1690  */
1691  template<int ID_t>
1692  struct JGauss<ID_t, true> :
1693  public JMathlib < JGauss<ID_t, true> >,
1694  public JCalculus< JGauss<ID_t, true> >
1695  {
1696  static const int ID = ID_t;
1697 
1698 
1699  /**
1700  * Default constructor.
1701  */
1703  center(0.0),
1704  sigma (0.0)
1705  {}
1706 
1707 
1708  /**
1709  * Constructor.
1710  *
1711  * \param center center
1712  * \param sigma sigma
1713  */
1714  JGauss(const double center,
1715  const double sigma) :
1716  center(center),
1717  sigma (sigma)
1718  {}
1719 
1720 
1721  /**
1722  * Function value.
1723  *
1724  * \param x abscissa value
1725  * \return function value
1726  */
1727  double getValue(const double x) const
1728  {
1729  const double u = (x - center) / sigma;
1730 
1731  return get(u);
1732  }
1733 
1734 
1735  /**
1736  * Derivative value.
1737  *
1738  * \param x abscissa value
1739  * \return derivative value
1740  */
1741  double getDerivative(const double x) const
1742  {
1743  const double w = 1.0 / sigma;
1744  const double u = (x - center) / sigma;
1745 
1746  return get(u) * -u * w;
1747  }
1748 
1749 
1750  /**
1751  * Get gradient.
1752  *
1753  * \param x abscissa value
1754  * \return gradient
1755  */
1756  const JGauss& getGradient(const double x) const
1757  {
1758  static JGauss gradient;
1759 
1760  const double w = 1.0 / sigma;
1761  const double u = (x - center) * w;
1762  const double f0 = get(u);
1763 
1764  gradient.center = f0 * (u) * w; // d(f)/d(center)
1765  gradient.sigma = f0 * (u + 1.0) * (u - 1.0) * w; // d(f)/d(sigma)
1766 
1767  return gradient;
1768  }
1769 
1770  double center; //!< center
1771  double sigma; //!< sigma
1772  static const parameter_list<JGauss> parameters; //!< parameters
1773 
1774  private:
1775  /**
1776  * Get ordinate value.
1777  *
1778  * \param u abscissa value
1779  * \return ordinate value
1780  */
1781  inline double get(const double u) const
1782  {
1783  return exp(-0.5*u*u) / (sqrt(2.0*PI) * sigma);
1784  }
1785  };
1786 
1787  /**
1788  * Set parameters.
1789  */
1790  template<int ID_t>
1792 
1793 
1794  /**
1795  * Power of function.
1796  */
1797  template<int ID_t, class JF1_t = _vF>
1798  struct JPow :
1799  public JMathlib < JPow<ID_t, JF1_t> >,
1800  public JF1_t
1801  {
1802  static const int ID = ID_t;
1803 
1804  using JMathlib< JPow<ID_t, JF1_t> >::operator();
1805 
1806 
1807  /**
1808  * Default constructor.
1809  */
1810  JPow() :
1811  JF1_t(),
1812  alpha(0.0)
1813  {}
1814 
1815 
1816  /**
1817  * Constructor.
1818  *
1819  * \param f1 function
1820  * \param alpha value
1821  */
1822  JPow(const JF1_t& f1, const double alpha) :
1823  JF1_t(f1),
1824  alpha(alpha)
1825  {}
1826 
1827 
1828  /**
1829  * Function value.
1830  *
1831  * \param x abscissa value
1832  * \return function value
1833  */
1834  double getValue(const double x) const
1835  {
1836  const double u = static_cast<const JF1_t&>(*this).getValue(x);
1837 
1838  return pow(u, alpha);
1839  }
1840 
1841 
1842  /**
1843  * Derivative value.
1844  *
1845  * \param x abscissa value
1846  * \return derivative value
1847  */
1848  double getDerivative(const double x) const
1849  {
1850  const double u = static_cast<const JF1_t&>(*this).getValue(x);
1851  const double v = static_cast<const JF1_t&>(*this).getDerivative(x);
1852 
1853  return alpha * pow(u, alpha - 1) * v;
1854  }
1855 
1856 
1857  /**
1858  * Get gradient.
1859  *
1860  * \param x abscissa value
1861  * \return gradient
1862  */
1863  const JPow& getGradient(const double x) const
1864  {
1865  static JPow gradient; // d(f)/d(a)
1866 
1867  const double u = static_cast<const JF1_t&>(*this).getValue(x);
1868  const double w = pow(u, alpha);
1869 
1870  gradient.alpha = w * log(u);
1871 
1872  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(x);
1873  static_cast<JF1_t&>(gradient) *= alpha * w / u;
1874 
1875  return gradient;
1876  }
1877 
1878  double alpha; //!< f(x)^alpha
1879  static const parameter_list<JPow> parameters; //!< parameters
1880  };
1881 
1882  /**
1883  * Set parameters.
1884  */
1885  template<int ID_t, class JF1_t>
1887 
1888 
1889  /**
1890  * Power of function.
1891  *
1892  * \param f1 function
1893  * \param alpha alpha
1894  * \return result
1895  */
1896  template<class JF1_t>
1897  JPow<JF1_t::ID, JF1_t> Pow(const JF1_t& f1, const double alpha)
1898  {
1899  return JPow<JF1_t::ID, JF1_t>(f1, alpha);
1900  }
1901 
1902 
1903  /**
1904  * Power of x.
1905  */
1906  template<int ID_t>
1907  struct JPow<ID_t, _vF> :
1908  public JMathlib < JPow<ID_t> >,
1909  public JCalculus< JPow<ID_t> >
1910  {
1911  static const int ID = ID_t;
1912 
1913 
1914  /**
1915  * Default constructor.
1916  */
1917  JPow() :
1918  alpha(0.0)
1919  {}
1920 
1921 
1922  /**
1923  * Constructor.
1924  *
1925  * \param alpha value
1926  */
1927  JPow(const double alpha) :
1928  alpha(alpha)
1929  {}
1930 
1931 
1932  /**
1933  * Function value.
1934  *
1935  * \param x abscissa value
1936  * \return function value
1937  */
1938  double getValue(const double x) const
1939  {
1940  return pow(x, alpha);
1941  }
1942 
1943 
1944  /**
1945  * Derivative value.
1946  *
1947  * \param x abscissa value
1948  * \return derivative value
1949  */
1950  double getDerivative(const double x) const
1951  {
1952  return alpha * pow(x, alpha - 1);
1953  }
1954 
1955 
1956  /**
1957  * Get gradient.
1958  *
1959  * \param x abscissa value
1960  * \return gradient
1961  */
1962  const JPow& getGradient(const double x) const
1963  {
1964  static JPow gradient; // d(f)/d(a)
1965 
1966  gradient.alpha = this->getValue(x) * log(x);
1967 
1968  return gradient;
1969  }
1970 
1971  double alpha; //!< x^alpha
1972  static const parameter_list<JPow> parameters; //!< parameters
1973  };
1974 
1975  /**
1976  * Set parameters.
1977  */
1978  template<int ID_t>
1980 
1981 
1982  /**
1983  * Fixed power of x.
1984  */
1985  template<int N>
1986  struct JXn :
1987  public JMathlib < JXn<N> >,
1988  public JCalculus< JXn<N> >
1989  {
1990  /**
1991  * Default constructor.
1992  */
1994  {}
1995 
1996 
1997  /**
1998  * Function value.
1999  *
2000  * \param x abscissa value
2001  * \return function value
2002  */
2003  double getValue(const double x) const
2004  {
2005  return pow(x, N);
2006  }
2007 
2008 
2009  /**
2010  * Derivative value.
2011  *
2012  * \param x abscissa value
2013  * \return derivative value
2014  */
2015  double getDerivative(const double x) const
2016  {
2017  return N * pow(x, N - 1);
2018  }
2019 
2020 
2021  /**
2022  * Get gradient.
2023  *
2024  * \param x abscissa value
2025  * \return gradient
2026  */
2027  const JXn& getGradient(const double x) const
2028  {
2029  static JXn gradient;
2030 
2031  return gradient;
2032  }
2033 
2034  static const parameter_list<JXn> parameters; //!< parameters
2035  };
2036 
2037  /**
2038  * Set parameters.
2039  */
2040  template<int N>
2042 
2043 
2044  /**
2045  * Fixed power of x.
2046  */
2047  template<>
2048  struct JXn<0>;
2049 
2050 
2051  /**
2052  * Square root of function.
2053  */
2054  template<class JF1_t = _vF>
2055  struct JSqrt :
2056  public JMathlib < JSqrt<JF1_t> >,
2057  public JF1_t
2058  {
2059  using JMathlib< JSqrt<JF1_t> >::operator();
2060 
2061 
2062  /**
2063  * Default constructor.
2064  */
2065  JSqrt() :
2066  JF1_t()
2067  {}
2068 
2069 
2070  /**
2071  * Constructor.
2072  *
2073  * \param f1 function
2074  */
2075  JSqrt(const JF1_t& f1) :
2076  JF1_t(f1)
2077  {}
2078 
2079 
2080  /**
2081  * Function value.
2082  *
2083  * \param x abscissa value
2084  * \return function value
2085  */
2086  double getValue(const double x) const
2087  {
2088  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2089 
2090  return sqrt(u);
2091  }
2092 
2093 
2094  /**
2095  * Derivative value.
2096  *
2097  * \param x abscissa value
2098  * \return derivative value
2099  */
2100  double getDerivative(const double x) const
2101  {
2102  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2103  const double v = static_cast<const JF1_t&>(*this).getDerivative(x);
2104 
2105  return 0.5 * v / sqrt(u);
2106  }
2107 
2108 
2109  /**
2110  * Get gradient.
2111  *
2112  * \param x abscissa value
2113  * \return gradient
2114  */
2115  const JSqrt& getGradient(const double x) const
2116  {
2117  static JSqrt gradient; // d(f)/d(a)
2118 
2119  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2120 
2121  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(x);
2122  static_cast<JF1_t&>(gradient) *= 0.5 / sqrt(u);
2123 
2124  return gradient;
2125  }
2126  };
2127 
2128 
2129  /**
2130  * Square root of function.
2131  *
2132  * \param f1 function
2133  * \return result
2134  */
2135  template<class JF1_t>
2136  JSqrt<JF1_t> Sqrt(const JF1_t& f1)
2137  {
2138  return JSqrt<JF1_t>(f1);
2139  }
2140 
2141 
2142  /**
2143  * Square root of x.
2144  */
2145  template<>
2146  struct JSqrt<_vF> :
2147  public JMathlib < JSqrt<_vF> >,
2148  public JCalculus< JSqrt<_vF> >
2149  {
2150  using JMathlib< JSqrt<_vF> >::operator();
2151 
2152 
2153  /**
2154  * Default constructor.
2155  */
2157  {}
2158 
2159 
2160  /**
2161  * Function value.
2162  *
2163  * \param x abscissa value
2164  * \return function value
2165  */
2166  double getValue(const double x) const
2167  {
2168  return sqrt(x);
2169  }
2170 
2171 
2172  /**
2173  * Derivative value.
2174  *
2175  * \param x abscissa value
2176  * \return derivative value
2177  */
2178  double getDerivative(const double x) const
2179  {
2180  return 0.5 / sqrt(x);
2181  }
2182 
2183 
2184  /**
2185  * Get gradient.
2186  *
2187  * \param x abscissa value
2188  * \return gradient
2189  */
2190  const JSqrt& getGradient(const double x) const
2191  {
2192  static JSqrt gradient;
2193 
2194  return gradient;
2195  }
2196 
2197  static const parameter_list<JSqrt> parameters; //!< parameters
2198  };
2199 
2200  /**
2201  * Set parameters.
2202  */
2204 
2205 
2206  /**
2207  * Square root of x.
2208  *
2209  * \return result
2210  */
2212  {
2213  return JSqrt<>();
2214  }
2215 
2216 
2217  /**
2218  * Sine of function.
2219  */
2220  template<class JF1_t>
2221  struct JSin :
2222  public JMathlib < JSin<JF1_t> >,
2223  public JF1_t
2224  {
2225  using JMathlib< JSin<JF1_t> >::operator();
2226 
2227 
2228  /**
2229  * Default constructor.
2230  */
2231  JSin() :
2232  JF1_t()
2233  {}
2234 
2235 
2236  /**
2237  * Constructor.
2238  *
2239  * \param f1 function
2240  */
2241  JSin(const JF1_t& f1) :
2242  JF1_t(f1)
2243  {}
2244 
2245 
2246  /**
2247  * Function value.
2248  *
2249  * \param x abscissa value
2250  * \return function value
2251  */
2252  double getValue(const double x) const
2253  {
2254  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2255 
2256  return sin(u);
2257  }
2258 
2259 
2260  /**
2261  * Derivative value.
2262  *
2263  * \param x abscissa value
2264  * \return derivative value
2265  */
2266  double getDerivative(const double x) const
2267  {
2268  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2269  const double v = static_cast<const JF1_t&>(*this).getDerivative(x);
2270 
2271  return v * cos(u);
2272  }
2273 
2274 
2275  /**
2276  * Get gradient.
2277  *
2278  * \param x abscissa value
2279  * \return gradient
2280  */
2281  const JSin& getGradient(const double x) const
2282  {
2283  static JSin gradient; // d(f)/d(a)
2284 
2285  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2286 
2287  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(x);
2288  static_cast<JF1_t&>(gradient) *= cos(u);
2289 
2290  return gradient;
2291  }
2292  };
2293 
2294 
2295  /**
2296  * Sine of function.
2297  *
2298  * \param f1 function
2299  * \return result
2300  */
2301  template<class JF1_t>
2302  JSin<JF1_t> Sin(const JF1_t& f1)
2303  {
2304  return JSin<JF1_t>(f1);
2305  }
2306 
2307 
2308  /**
2309  * Cosine of function.
2310  */
2311  template<class JF1_t>
2312  struct JCos :
2313  public JMathlib < JCos<JF1_t> >,
2314  public JF1_t
2315  {
2316  using JMathlib< JCos<JF1_t> >::operator();
2317 
2318 
2319  /**
2320  * Default constructor.
2321  */
2322  JCos() :
2323  JF1_t()
2324  {}
2325 
2326 
2327  /**
2328  * Constructor.
2329  *
2330  * \param f1 function
2331  */
2332  JCos(const JF1_t& f1) :
2333  JF1_t(f1)
2334  {}
2335 
2336 
2337  /**
2338  * Function value.
2339  *
2340  * \param x abscissa value
2341  * \return function value
2342  */
2343  double getValue(const double x) const
2344  {
2345  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2346 
2347  return cos(u);
2348  }
2349 
2350 
2351  /**
2352  * Derivative value.
2353  *
2354  * \param x abscissa value
2355  * \return derivative value
2356  */
2357  double getDerivative(const double x) const
2358  {
2359  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2360  const double v = static_cast<const JF1_t&>(*this).getDerivative(x);
2361 
2362  return v * -sin(u);
2363  }
2364 
2365 
2366  /**
2367  * Get gradient.
2368  *
2369  * \param x abscissa value
2370  * \return gradient
2371  */
2372  const JCos& getGradient(const double x) const
2373  {
2374  static JCos gradient; // d(f)/d(a)
2375 
2376  const double u = static_cast<const JF1_t&>(*this).getValue(x);
2377 
2378  static_cast<JF1_t&>(gradient) = static_cast<const JF1_t&>(*this).getGradient(x);
2379  static_cast<JF1_t&>(gradient) *= -sin(u);
2380 
2381  return gradient;
2382  }
2383  };
2384 
2385 
2386  /**
2387  * Cosine function.
2388  *
2389  * \param f1 function
2390  * \return result
2391  */
2392  template<class JF1_t>
2393  JCos<JF1_t> Cos(const JF1_t& f1)
2394  {
2395  return JCos<JF1_t>(f1);
2396  }
2397 
2398 
2399  /**
2400  * Exponent of function.
2401  */
2402  template<class JF1_t>
2403  struct JExp :
2404  public JMathlib< JExp<JF1_t> >,
2405  public JF1_t
2406  {
2407  using JMathlib< JExp<JF1_t> >::operator();
2408 
2409 
2410  /**
2411  * Default constructor.
2412  */
2413  JExp() :
2414  JF1_t()
2415  {}
2416 
2417 
2418  /**
2419  * Constructor.
2420  *
2421  * \param f1 function
2422  */
2423  JExp(const JF1_t& f1) :
2424  JF1_t(f1)
2425  {}
2426 
2427 
2428  /**
2429  * Function value.
2430  *
2431  * \param x abscissa value
2432  * \return function value
2433  */
2434  double getValue(const double x) const
2435  {
2436  return exp(static_cast<const JF1_t&>(*this).getValue(x));
2437  }
2438 
2439 
2440  /**
2441  * Derivative value.
2442  *
2443  * \param x abscissa value
2444  * \return derivative value
2445  */
2446  double getDerivative(const double x) const
2447  {
2448  return static_cast<const JF1_t&>(*this).getDerivative(x) * getValue(x);
2449  }
2450 
2451 
2452  /**
2453  * Get gradient.
2454  *
2455  * \param x abscissa value
2456  * \return gradient
2457  */
2458  const JExp& getGradient(const double x) const
2459  {
2460  static JExp gradient;
2461 
2462  gradient = static_cast<const JF1_t&>(*this).getGradient(x);
2463  gradient *= getValue(x);
2464 
2465  return gradient;
2466  }
2467  };
2468 
2469 
2470  /**
2471  * Exponent of zero degree polynomial function.
2472  */
2473  template<int ID_t>
2474  struct JExp< JPolynome<ID_t, 0> > :
2475  public JMathlib< JExp< JPolynome<ID_t, 0> > >,
2476  public JPolynome<ID_t, 0>
2477  {
2478  using JMathlib< JExp< JPolynome<ID_t, 0> > >::operator();
2479 
2480 
2481  /**
2482  * Default constructor.
2483  */
2484  JExp() :
2485  JPolynome<ID_t, 0>()
2486  {}
2487 
2488 
2489  /**
2490  * Constructor.
2491  *
2492  * \param f1 function
2493  */
2495  JPolynome<ID_t, 0>(f1)
2496  {}
2497 
2498 
2499  /**
2500  * Function value.
2501  *
2502  * \return function value
2503  */
2504  double getValue(...) const
2505  {
2506  return exp(static_cast<const JPolynome<ID_t, 0>&>(*this).getValue());
2507  }
2508 
2509 
2510  /**
2511  * Derivative value.
2512  *
2513  * \return derivative value
2514  */
2515  double getDerivative(...) const
2516  {
2517  return static_cast<const JPolynome<ID_t, 0>&>(*this).getDerivative() * getValue();
2518  }
2519 
2520 
2521  /**
2522  * Get gradient.
2523  *
2524  * \return gradient
2525  */
2526  const JExp& getGradient(...) const
2527  {
2528  static JExp gradient;
2529 
2530  gradient = static_cast<const JPolynome<ID_t, 0>&>(*this).getGradient();
2531  gradient *= getValue();
2532 
2533  return gradient;
2534  }
2535  };
2536 
2537 
2538  /**
2539  * Exponent of function.
2540  *
2541  * \param f1 function
2542  * \return result
2543  */
2544  template<class JF1_t>
2545  JExp<JF1_t> Exp(const JF1_t& f1)
2546  {
2547  return JExp<JF1_t>(f1);
2548  }
2549 
2550 
2551  /**
2552  * Logarithm of function.
2553  */
2554  template<class JF1_t>
2555  struct JLog :
2556  public JMathlib< JLog<JF1_t> >,
2557  public JF1_t
2558  {
2559  using JMathlib< JLog<JF1_t> >::operator();
2560 
2561 
2562  /**
2563  * Default constructor.
2564  */
2565  JLog() :
2566  JF1_t()
2567  {}
2568 
2569 
2570  /**
2571  * Constructor.
2572  *
2573  * \param f1 function
2574  */
2575  JLog(const JF1_t& f1) :
2576  JF1_t(f1)
2577  {}
2578 
2579 
2580  /**
2581  * Function value.
2582  *
2583  * \param x abscissa value
2584  * \return function value
2585  */
2586  double getValue(const double x) const
2587  {
2588  return log(static_cast<const JF1_t&>(*this).getValue(x));
2589  }
2590 
2591 
2592  /**
2593  * Derivative value.
2594  *
2595  * \param x abscissa value
2596  * \return derivative value
2597  */
2598  double getDerivative(const double x) const
2599  {
2600  return static_cast<const JF1_t&>(*this).getDerivative(x) / static_cast<const JF1_t&>(*this).getValue(x);
2601  }
2602 
2603 
2604  /**
2605  * Get gradient.
2606  *
2607  * \param x abscissa value
2608  * \return gradient
2609  */
2610  const JLog& getGradient(const double x) const
2611  {
2612  static JLog gradient;
2613 
2614  gradient = static_cast<const JF1_t&>(*this).getGradient(x);
2615  gradient /= (static_cast<const JF1_t&>(*this).getValue(x));
2616 
2617  return gradient;
2618  }
2619  };
2620 
2621 
2622  /**
2623  * Logarithm of function.
2624  *
2625  * \param f1 function
2626  * \return result
2627  */
2628  template<class JF1_t>
2629  JLog<JF1_t> Log(const JF1_t& f1)
2630  {
2631  return JLog<JF1_t>(f1);
2632  }
2633 }
2634 
2635 #endif
friend JSub< JF1_t > operator-(const JF1_t &f1, const double value)
Subtraction of constant value.
Definition: JMathlib.hh:425
JSqrt()
Default constructor.
Definition: JMathlib.hh:2065
JPow()
Default constructor.
Definition: JMathlib.hh:1917
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1433
JMul()
Default constructor.
Definition: JMathlib.hh:1140
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:1621
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:2003
JPow(const JF1_t &f1, const double alpha)
Constructor.
Definition: JMathlib.hh:1822
JF1_t & mul(const double factor)
Scale function.
Definition: JMathlib.hh:251
JPolynome_t & mul(const double factor)
Scale polynome.
Definition: JPolynome.hh:113
data_type w[N+1][M+1]
Definition: JPolint.hh:867
friend JSub< JF1_t, JF2_t > operator-(const JF1_t &f1, const JF2_t &f2)
Subtraction of two functions.
Definition: JMathlib.hh:505
Termination class for polynomial function.
Definition: JMathlib.hh:1484
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:2446
forward declaration for multiplication of fuction.
Definition: JMathlib.hh:343
Fixed power of x.
Definition: JMathlib.hh:1986
Exponent of function.
Definition: JMathlib.hh:2403
static const parameter_list< JPow > parameters
parameters
Definition: JMathlib.hh:1972
int getParameter(const std::string &text)
Get parameter number from text string.
friend JDiv< JF1_t > operator/(const JF1_t &f1, const double value)
Division of constant value.
Definition: JMathlib.hh:477
const JGauss & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:1756
friend JMul< JF1_t, JF2_t > operator*(const JF1_t &f1, const JF2_t &f2)
Multiplication of two functions.
Definition: JMathlib.hh:519
JAdd(const JF1_t &f1, const double value)
Constructor.
Definition: JMathlib.hh:649
JNegate()
Default constructor.
Definition: JMathlib.hh:567
const JExp & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:2458
JMul(const JF1_t &f1, const double value)
Constructor.
Definition: JMathlib.hh:801
friend JF1_t & operator*=(JF1_t &function, const double factor)
Scale function.
Definition: JMathlib.hh:310
const JGauss & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:1650
const JNegate & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:613
const JLog & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:2610
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:1938
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:2598
JAdd()
Default constructor.
Definition: JMathlib.hh:989
double getValue(...) const
Function value.
Definition: JMathlib.hh:1516
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:1834
Auxiliary data structure for list of parameters.
Definition: JMathlib.hh:90
friend JAdd< JF1_t > operator+(const JF1_t &f1, const double value)
Addition of constant value.
Definition: JMathlib.hh:399
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:1326
JPolynome()
Default constructor.
Definition: JMathlib.hh:1496
JLog(const JF1_t &f1)
Constructor.
Definition: JMathlib.hh:2575
JPolynome_t & sub(const JPolynome_t &polynome)
Subtract polynome.
Definition: JPolynome.hh:93
JPow()
Default constructor.
Definition: JMathlib.hh:1810
const JPolynome & getGradient(...) const
Get gradient.
Definition: JMathlib.hh:1538
friend JF1_t & operator-=(JF1_t &function, const JF1_t &value)
Subtract function.
Definition: JMathlib.hh:297
void add(const double x)
Termination method for adding values to array.
Definition: JMathlib.hh:76
void set(const double *pA)
Set parameter values.
Definition: JMathlib.hh:1465
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:1727
forward declaration for negate of function.
Definition: JMathlib.hh:334
const JAdd & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:687
parameter_list(const parameter_list< U > &parameters, double JF1_t::*parameter)
Combine constructor.
Definition: JMathlib.hh:127
JSub()
Default constructor.
Definition: JMathlib.hh:715
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
const JDiv & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:916
JAdd(const JF1_t &f1, const JF2_t &f2)
Constructor.
Definition: JMathlib.hh:999
JExp< JF1_t > Exp(const JF1_t &f1)
Exponent of function.
Definition: JMathlib.hh:2545
JMul(const JF1_t &f1, const JF2_t &f2)
Constructor.
Definition: JMathlib.hh:1150
JPolynome(const Args &...args)
Constructor.
Definition: JMathlib.hh:1408
Sine of function.
Definition: JMathlib.hh:2221
JGauss()
Default constructor.
Definition: JMathlib.hh:1596
void add(const double x, const Args &...args)
Recursive method for adding values to array.
Definition: JMathlib.hh:63
static const parameter_list< JPolynome > parameters
parameters
Definition: JMathlib.hh:1457
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:814
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1175
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:2252
friend const JF1_t & operator+(const JF1_t &function)
Affirm operator.
Definition: JMathlib.hh:374
parameter_list(double JF1_t::*parameter)
Constructor.
Definition: JMathlib.hh:105
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1252
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Auxiliary data structure for pair of functions.
Definition: JMathlib.hh:935
double alpha
x^alpha
Definition: JMathlib.hh:1971
void setParameters(JF1_t *f1, const double *values)
Set values of all parameters.
Definition: JMathlib.hh:182
Gauss function object.
Definition: JGauss.hh:173
const JPow & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:1863
const JMul & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:839
then usage set_variable ACOUSTICS_WORKDIR $WORKDIR set_variable FORMULA sin([0]+2 *$PI *([1]+[2]*x)*x)" set_variable DY 1.0e-8 mkdir $WORKDIR for DETECTOR in $DETECTORS[*]
JSqrt< JF1_t > Sqrt(const JF1_t &f1)
Square root of function.
Definition: JMathlib.hh:2136
Square root of function.
Definition: JMathlib.hh:2055
const JPolynome f1(1.0, 2.0, 3.0)
Function.
JPolynome_t & add(const JPolynome_t &polynome)
Add polynome.
Definition: JPolynome.hh:73
JPow< JF1_t::ID, JF1_t > Pow(const JF1_t &f1, const double alpha)
Power of function.
Definition: JMathlib.hh:1897
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1340
JF1_t & sub(const JF1_t &f1)
Subtract function.
Definition: JMathlib.hh:235
JF1_t & negate()
Negate function.
Definition: JMathlib.hh:203
static const parameter_list< JGauss > parameters
parameters
Definition: JMathlib.hh:1666
static const parameter_list< JPolynome > parameters
parameters
Definition: JMathlib.hh:1548
friend JNegate< JF1_t > operator-(const JF1_t &function)
Negate operator.
Definition: JMathlib.hh:386
const JPow & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:1962
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:600
Power of function.
Definition: JMathlib.hh:1798
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:2100
JDiv()
Default constructor.
Definition: JMathlib.hh:868
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:903
Auxiliary base class for mathematical operations on parameters of function.
Definition: JMathlib.hh:196
parameter_list(const parameter_list< U > &first, const parameter_list< V > &second)
Combine constructor.
Definition: JMathlib.hh:141
double alpha
f(x)^alpha
Definition: JMathlib.hh:1878
Mathematical constants.
JSqrt()
Default constructor.
Definition: JMathlib.hh:2156
JGauss(const double center, const double sigma)
Constructor.
Definition: JMathlib.hh:1608
JF1_t & add(const JF1_t &f1)
Add function.
Definition: JMathlib.hh:219
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:662
JCos< JF1_t > Cos(const JF1_t &f1)
Cosine function.
Definition: JMathlib.hh:2393
friend JDiv< JF1_t, JF2_t > operator/(const JF1_t &f1, const JF2_t &f2)
Division of two functions.
Definition: JMathlib.hh:533
void function
Definition: JMathlib.hh:30
const JSqrt & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:2190
static const parameter_list< JGauss > parameters
parameters
Definition: JMathlib.hh:1772
JDiv()
Default constructor.
Definition: JMathlib.hh:1217
const JCos & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:2372
forward declaration for fixed power of function.
Definition: JMathlib.hh:354
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:674
JGauss()
Default constructor.
Definition: JMathlib.hh:1702
static const parameter_list< JPow > parameters
parameters
Definition: JMathlib.hh:1879
JFn()
Default constructor.
Definition: JMathlib.hh:1301
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
double center
center
Definition: JMathlib.hh:1664
static const parameter_list< JPair > parameters
parameters
Definition: JMathlib.hh:965
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:738
static const double PI
Mathematical constants.
JSin()
Default constructor.
Definition: JMathlib.hh:2231
const JSin & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:2281
parameter_list()
Default constructor.
Definition: JMathlib.hh:96
friend JAdd< JF1_t, JF2_t > operator+(const JF1_t &f1, const JF2_t &f2)
Addition of two functions.
Definition: JMathlib.hh:491
friend JAdd< JNegate< JF1_t > > operator-(const double value, const JF1_t &f1)
Subtraction of constant value.
Definition: JMathlib.hh:438
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:750
Cosine of function.
Definition: JMathlib.hh:2312
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:826
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1099
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:2015
double a
a[N]
Definition: JMathlib.hh:1456
JLog< JF1_t > Log(const JF1_t &f1)
Logarithm of function.
Definition: JMathlib.hh:2629
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:588
double getDerivative(...) const
Derivative value.
Definition: JMathlib.hh:1527
friend JMul< JF1_t > operator*(const double value, const JF1_t &f1)
Multiplication of constant value.
Definition: JMathlib.hh:464
JPair(const JF1_t &f1, const JF2_t &f2)
Constructor.
Definition: JMathlib.hh:960
JSin(const JF1_t &f1)
Constructor.
Definition: JMathlib.hh:2241
Negate of function.
Definition: JMathlib.hh:331
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1848
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:2343
JDiv(const JF1_t &f1, const double value)
Constructor.
Definition: JMathlib.hh:878
make_carray(const Args &...args)
Constructor.
Definition: JMathlib.hh:39
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:2166
const JPolynome & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:1445
const JDiv & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:1269
JExp()
Default constructor.
Definition: JMathlib.hh:2484
JGauss(const double center, const double sigma)
Constructor.
Definition: JMathlib.hh:1714
JSub()
Default constructor.
Definition: JMathlib.hh:1064
JSqrt(const JF1_t &f1)
Constructor.
Definition: JMathlib.hh:2075
friend JFn< JF1_t > operator^(const JF1_t &function, int N)
Power of operator.
Definition: JMathlib.hh:546
friend JMul< JF1_t > operator*(const JF1_t &f1, const double value)
Multiplication of constant value.
Definition: JMathlib.hh:451
const JSqrt & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:2115
JSub(const JF1_t &f1, const double value)
Constructor.
Definition: JMathlib.hh:725
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:1011
JDiv(const JF1_t &f1, const JF2_t &f2)
Constructor.
Definition: JMathlib.hh:1227
JPow(const double alpha)
Constructor.
Definition: JMathlib.hh:1927
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
friend JF1_t & operator/=(JF1_t &function, const double factor)
Scale function.
Definition: JMathlib.hh:323
static const parameter_list< JSqrt > parameters
parameters
Definition: JMathlib.hh:2197
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:2434
JMul()
Default constructor.
Definition: JMathlib.hh:791
JExp(const JPolynome< ID_t, 0 > &f1)
Constructor.
Definition: JMathlib.hh:2494
JSin< JF1_t > Sin(const JF1_t &f1)
Sine of function.
Definition: JMathlib.hh:2302
void set(const double *array)
Set parameter values.
Definition: JMathlib.hh:1556
Logarithm of function.
Definition: JMathlib.hh:2555
friend JF1_t & operator+=(JF1_t &function, const JF1_t &value)
Add function.
Definition: JMathlib.hh:284
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:1239
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:1162
const JMul & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:1189
forward declaration for addition of fuction.
Definition: JMathlib.hh:337
const JSub & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:1113
const JXn & getGradient(const double x) const
Get gradient.
Definition: JMathlib.hh:2027
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:1421
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:2178
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1741
JAdd()
Default constructor.
Definition: JMathlib.hh:639
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:2086
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:1086
const JAdd & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:1038
double getValue(const double x) const
Function value.
Definition: JMathlib.hh:2586
possible values
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1635
Recursive template class for polynomial function.
Definition: JMathlib.hh:1377
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1024
const JSub & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:763
JLog()
Default constructor.
Definition: JMathlib.hh:2565
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:2266
double getDerivative(...) const
Derivative value.
Definition: JMathlib.hh:2515
double sigma
sigma
Definition: JMathlib.hh:1665
const JExp & getGradient(...) const
Get gradient.
Definition: JMathlib.hh:2526
double getValue(const Args &...args) const
Function value.
Definition: JMathlib.hh:891
data_type v[N+1][M+1]
Definition: JPolint.hh:866
double u[N+1]
Definition: JPolint.hh:865
forward declaration for subtraction of fuction.
Definition: JMathlib.hh:340
parameter_list(const std::initializer_list< double JF1_t::* > &parameters)
Constructor.
Definition: JMathlib.hh:115
JNegate(const JF1_t &f1)
Constructor.
Definition: JMathlib.hh:576
JPair()
Default constructor.
Definition: JMathlib.hh:950
JGauss_t gradient
Definition: JGauss.hh:289
JFn(const JF1_t &f1, const int N)
Constructor.
Definition: JMathlib.hh:1313
JExp()
Default constructor.
Definition: JMathlib.hh:2413
static const size_t NUMBER_OF_DEGREES
Definition: JMathlib.hh:1384
JCos(const JF1_t &f1)
Constructor.
Definition: JMathlib.hh:2332
JPolynome(const double a)
Constructor.
Definition: JMathlib.hh:1506
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable STRING $argv[2] set_array QUANTILES set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))" set_variable MODULE `getModule -a $DETECTOR -L "$STRING 0"` source JAcousticsToolkit.sh typeset -A TRIPODS get_tripods $WORKDIR/tripod.txt TRIPODS XMEAN
JF1_t & div(const double factor)
Scale function.
Definition: JMathlib.hh:267
double operator()(const Args &...args) const
Function value.
Definition: JMathlib.hh:362
JXn()
Default constructor.
Definition: JMathlib.hh:1993
JPolynome()
Default constructor.
Definition: JMathlib.hh:1397
friend JAdd< JF1_t > operator+(const double value, const JF1_t &f1)
Addition of constant value.
Definition: JMathlib.hh:412
JCos()
Default constructor.
Definition: JMathlib.hh:2322
JExp(const JF1_t &f1)
Constructor.
Definition: JMathlib.hh:2423
forward declaration for division of fuction.
Definition: JMathlib.hh:346
const JFn & getGradient(const Args &...args) const
Get gradient.
Definition: JMathlib.hh:1356
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:2357
size_t getNumberOfParameters()
Get number of parameters.
Definition: JMathlib.hh:155
double getValue(...) const
Function value.
Definition: JMathlib.hh:2504
double getDerivative(const double x) const
Derivative value.
Definition: JMathlib.hh:1950
JSub(const JF1_t &f1, const JF2_t &f2)
Constructor.
Definition: JMathlib.hh:1074
static const parameter_list< JXn > parameters
parameters
Definition: JMathlib.hh:2034