Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JMatrix1D.hh
Go to the documentation of this file.
1#ifndef __JMATRIX1D__
2#define __JMATRIX1D__
3
4#include <limits>
5#include <cmath>
6#include <ostream>
7#include <iomanip>
8
10#include "JLang/JEquals.hh"
11#include "JLang/JManip.hh"
12#include "JMath/JMath.hh"
13
14
15/**
16 * \author mdejong
17 */
18
19namespace JMATH {}
20namespace JPP { using namespace JMATH; }
21
22namespace JMATH {
23
24 using JIO::JReader;
25 using JIO::JWriter;
26 using JLANG::JEquals;
27
28
29 /**
30 * 1 x 1 matrix
31 */
32 class JMatrix1D :
33 public JMath <JMatrix1D>,
34 public JEquals<JMatrix1D>
35 {
36 public:
37
38 using JMath<JMatrix1D>::mul;
39
40
41 /**
42 * Default constructor.
43 */
45 a00(0.0)
46 {}
47
48
49 /**
50 * Contructor.
51 *
52 * \param __a00 (0,0)
53 */
54 JMatrix1D(const double __a00) :
55 a00(__a00)
56 {}
57
58
59 /**
60 * Get reference to unique instance of this class object.
61 *
62 * \return zero matrix
63 */
64 static const JMatrix1D& getInstance()
65 {
66 static JMatrix1D matrix;
67
68 return matrix;
69 }
70
71
72 /**
73 * Set to identity matrix.
74 *
75 * \return this matrix
76 */
78 {
79 a00 = 1.0;
80
81 return *this;
82 }
83
84
85 /**
86 * Get reference to unique instance of this class object.
87 *
88 * \return identity matrix
89 */
90 static const JMatrix1D& getIdentity()
91 {
92 static JMatrix1D matrix(JMatrix1D().setIdentity());
93
94 return matrix;
95 }
96
97
98 /**
99 * Set matrix.
100 *
101 * \param A matrix
102 */
103 void set(const JMatrix1D& A)
104 {
105 static_cast<JMatrix1D&>(*this) = A;
106 }
107
108
109 /**
110 * Set matrix to the null matrix.
111 *
112 * \return this matrix
113 */
115 {
116 *this = JMatrix1D();
117
118 return *this;
119 }
120
121
122 /**
123 * Transpose.
124 *
125 * \return this matrix
126 */
128 {
129 return *this;
130 }
131
132
133 /**
134 * Negate matrix.
135 *
136 * \return -this matrix
137 */
139 {
140 a00 = -a00;
141
142 return *this;
143 }
144
145
146 /**
147 * Matrix addition.
148 *
149 * \param A matrix
150 * \return this matrix + A
151 */
153 {
154 a00 += A.a00;
155
156 return *this;
157 }
158
159
160 /**
161 * Matrix subtraction.
162 *
163 * \param A matrix
164 * \return this matrix - A
165 */
167 {
168 a00 -= A.a00;
169
170 return *this;
171 }
172
173
174 /**
175 * Scale matrix.
176 *
177 * \param factor factor
178 * \return this matrix * factor
179 */
180 JMatrix1D& mul(const double factor)
181 {
182 a00 *= factor;
183
184 return *this;
185 }
186
187
188 /**
189 * Scale matrix.
190 *
191 * \param factor factor
192 * \return this matrix / factor
193 */
194 JMatrix1D& div(const double factor)
195 {
196 a00 /= factor;
197
198 return *this;
199 }
200
201
202 /**
203 * Matrix multiplication.
204 *
205 * \param A matrix
206 * \param B matrix
207 * \return this matrix
208 */
210 const JMatrix1D& B)
211 {
212 a00 = A.a00 * B.a00;
213
214 return *this;
215 }
216
217
218 /**
219 * Equality.
220 *
221 * \param A matrix
222 * \param eps numerical precision
223 * \return true if matrices identical; else false
224 */
225 bool equals(const JMatrix1D& A,
226 const double eps = std::numeric_limits<double>::min()) const
227 {
228 return (fabs(a00 - A.a00) <= eps);
229 }
230
231
232 /**
233 * Test identity.
234 *
235 * \param eps numerical precision
236 * \return true if identity matrix; else false
237 */
238 bool isIdentity(const double eps = std::numeric_limits<double>::min()) const
239 {
240 return equals(getIdentity(), eps);
241 }
242
243
244 /**
245 * Get determinant of matrix.
246 *
247 * \return determinant of matrix
248 */
249 double getDeterminant() const
250 {
251 return a00;
252 }
253
254
255 /**
256 * Transform.
257 *
258 * \param __x x value
259 */
260 void transform(double& __x) const
261 {
262 __x = a00 * __x;
263 }
264
265
266 /**
267 * Read matrix from input.
268 *
269 * \param in reader
270 * \param matrix matrix
271 * \return reader
272 */
273 friend inline JReader& operator>>(JReader& in, JMatrix1D& matrix)
274 {
275 in >> matrix.a00;
276
277 return in;
278 }
279
280
281 /**
282 * Write matrix to output.
283 *
284 * \param out writer
285 * \param matrix matrix
286 * \return writer
287 */
288 friend inline JWriter& operator<<(JWriter& out, const JMatrix1D& matrix)
289 {
290 out << matrix.a00;
291
292 return out;
293 }
294
295
296 /**
297 * Print ASCII formatted output.
298 *
299 * \param out output stream
300 * \param A matrix
301 * \return output stream
302 */
303 friend inline std::ostream& operator<<(std::ostream& out, const JMatrix1D& A)
304 {
305 using namespace std;
306
307 const JFormat format(out, getFormat<JMatrix1D>(JFormat_t(10, 3, std::ios::fixed | std::ios::showpos)));
308
309 out << format << A.a00 << endl;
310
311 return out;
312 }
313
314
315 double a00;
316 };
317}
318
319#endif
I/O manipulators.
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Base class for data structures with artithmetic capabilities.
Interface for binary input.
Interface for binary output.
1 x 1 matrix
Definition JMatrix1D.hh:35
JMatrix1D & reset()
Set matrix to the null matrix.
Definition JMatrix1D.hh:114
JMatrix1D & sub(const JMatrix1D &A)
Matrix subtraction.
Definition JMatrix1D.hh:166
bool isIdentity(const double eps=std::numeric_limits< double >::min()) const
Test identity.
Definition JMatrix1D.hh:238
JMatrix1D & mul(const JMatrix1D &A, const JMatrix1D &B)
Matrix multiplication.
Definition JMatrix1D.hh:209
JMatrix1D & mul(const double factor)
Scale matrix.
Definition JMatrix1D.hh:180
bool equals(const JMatrix1D &A, const double eps=std::numeric_limits< double >::min()) const
Equality.
Definition JMatrix1D.hh:225
JMatrix1D & add(const JMatrix1D &A)
Matrix addition.
Definition JMatrix1D.hh:152
friend JWriter & operator<<(JWriter &out, const JMatrix1D &matrix)
Write matrix to output.
Definition JMatrix1D.hh:288
JMatrix1D & setIdentity()
Set to identity matrix.
Definition JMatrix1D.hh:77
JMatrix1D & transpose()
Transpose.
Definition JMatrix1D.hh:127
JMatrix1D()
Default constructor.
Definition JMatrix1D.hh:44
double getDeterminant() const
Get determinant of matrix.
Definition JMatrix1D.hh:249
static const JMatrix1D & getIdentity()
Get reference to unique instance of this class object.
Definition JMatrix1D.hh:90
JMatrix1D & negate()
Negate matrix.
Definition JMatrix1D.hh:138
void transform(double &__x) const
Transform.
Definition JMatrix1D.hh:260
friend JReader & operator>>(JReader &in, JMatrix1D &matrix)
Read matrix from input.
Definition JMatrix1D.hh:273
JMatrix1D(const double __a00)
Contructor.
Definition JMatrix1D.hh:54
friend std::ostream & operator<<(std::ostream &out, const JMatrix1D &A)
Print ASCII formatted output.
Definition JMatrix1D.hh:303
void set(const JMatrix1D &A)
Set matrix.
Definition JMatrix1D.hh:103
static const JMatrix1D & getInstance()
Get reference to unique instance of this class object.
Definition JMatrix1D.hh:64
JMatrix1D & div(const double factor)
Scale matrix.
Definition JMatrix1D.hh:194
Auxiliary classes and methods for mathematical operations.
Definition JEigen3D.hh:88
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636
Template definition of auxiliary base class for comparison of data structures.
Definition JEquals.hh:84
Auxiliary base class for aritmetic operations of derived class types.
Definition JMath.hh:347