Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTrigonometric.hh
Go to the documentation of this file.
1 #ifndef __JMATH__JTRIGONOMETRIC__
2 #define __JMATH__JTRIGONOMETRIC__
3 
4 #include <istream>
5 #include <ostream>
6 #include <cmath>
7 
8 #include "JLang/JException.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JMATH {}
16 namespace JPP { using namespace JMATH; }
17 
18 namespace JMATH {
19 
20  using JLANG::JException;
21 
22 
23  /**
24  * Trigonometric function object for <tt>sin</tt> and <tt>cos</tt>.
25  *
26  * Evaluation of function, derivative and integral values.
27  */
29  public:
30  /**
31  * Type definition of pointer to trigonometric function.
32  */
33  typedef double (*pF)(double);
34 
35 
36  /**
37  * Constructor.
38  *
39  * \param f1 pointer to function
40  * \param factor multiplication factor
41  */
42  JTrigonometric(pF f1, const double factor = 1.0)
43  {
44  if (f1 != sin && f1 != cos) {
45  THROW(JException, "Invalid trigonometric function.");
46  }
47 
48  this->f1 = f1;
49  this->factor = factor;
50  }
51 
52 
53  /**
54  * Function value.
55  *
56  * \param x abscissa value
57  * \return function value
58  */
59  double getValue(const double x) const
60  {
61  return factor * f1(x);
62  }
63 
64 
65  /**
66  * Derivative value.
67  *
68  * \param x abscissa value
69  * \return derivative value
70  */
71  double getDerivative(const double x) const
72  {
73  return getDerivative().getValue(x);
74  }
75 
76 
77  /**
78  * Integral value.
79  *
80  * \param x abscissa value
81  * \return integral value
82  */
83  double getIntegral(const double x) const
84  {
85  return getIntegral().getValue(x);
86  }
87 
88 
89  /**
90  * Function value.
91  *
92  * \param x abscissa value
93  * \return function value
94  */
95  double operator()(const double x) const
96  {
97  return getValue(x);
98  }
99 
100 
101  /**
102  * Derivative function.
103  *
104  * \return derivative function
105  */
107  {
108  if (f1 == sin)
109  return JTrigonometric(cos, +factor);
110  else if (f1 == cos)
111  return JTrigonometric(sin, -factor);
112  else
113  THROW(JException, "Invalid trigonometric function.");
114  }
115 
116 
117  /**
118  * Integral function.
119  *
120  * \return integral function
121  */
123  {
124  if (f1 == sin)
125  return JTrigonometric(cos, -factor);
126  else if (f1 == cos)
127  return JTrigonometric(sin, +factor);
128  else
129  THROW(JException, "Invalid trigonometric function.");
130  }
131 
132 
133  /**
134  * Read trigonometric from input.
135  *
136  * \param in input stream
137  * \param object trigonometric
138  * \return input stream
139  */
140  friend inline std::istream& operator>>(std::istream& in, JTrigonometric& object)
141  {
142  std::string buffer;
143 
144  if (in >> object.factor >> buffer) {
145  if (buffer == "sin")
146  object.f1 = sin;
147  else if (buffer == "cos")
148  object.f1 = cos;
149  else
150  THROW(JException, "Invalid trigonometric function.");
151  }
152 
153  return in;
154  }
155 
156 
157  /**
158  * Write trigonometric to output.
159  *
160  * \param out output stream
161  * \param object trigonometric
162  * \return output stream
163  */
164  friend inline std::ostream& operator<<(std::ostream& out, const JTrigonometric& object)
165  {
166  out << object.factor;
167 
168  if (object.f1 == sin)
169  out << ' ' << "sin";
170  else if (object.f1 == cos)
171  out << ' ' << "cos";
172  else
173  THROW(JException, "Invalid trigonometric function.");
174 
175  return out;
176  }
177 
178  protected:
180  double factor;
181  };
182 }
183 
184 #endif
double operator()(const double x) const
Function value.
General exception.
Definition: JException.hh:24
Exceptions.
double(* pF)(double)
Type definition of pointer to trigonometric function.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
double getIntegral(const double x) const
Integral value.
JTrigonometric(pF f1, const double factor=1.0)
Constructor.
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[*]
friend std::istream & operator>>(std::istream &in, JTrigonometric &object)
Read trigonometric from input.
JTrigonometric getIntegral() const
Integral function.
Trigonometric function object for sin and cos.
double getValue(const double x) const
Function value.
double getDerivative(const double x) const
Derivative value.
friend std::ostream & operator<<(std::ostream &out, const JTrigonometric &object)
Write trigonometric to output.
JTrigonometric getDerivative() const
Derivative function.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48