Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Go to the documentation of this file.
1 /*
2  * vector.h - vector class definitions
3  *
4  * Copyright (C) 2003, 2004, 2005, 2006, 2007 Stefan Jahn <stefan@lkcc.org>
5  * Copyright (C) 2006 Gunther Kraut <gn.kraut@t-online.de>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this package; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * $Id$
23  *
24  */
26 #ifndef __VECTOR_H__
27 #define __VECTOR_H__
29 #include "consts.h"
30 #include "precision.h"
31 #include "complex.h"
33 #ifdef log2
34 #undef log2
35 #endif
37 namespace qucs {
39 class strlist;
40 class vector;
42 qucs::vector linspace (nr_double_t, nr_double_t, int);
43 qucs::vector logspace (nr_double_t, nr_double_t, int);
44 qucs::vector runavg (qucs::vector, const int);
45 qucs::vector runavg (const nr_complex_t, const int);
47 class vector : public object
48 {
49  public:
50  vector ();
51  vector (const char *);
52  vector (int);
53  vector (int, nr_complex_t);
54  vector (const char *, int);
55  vector (const vector &);
56  const vector& operator = (const vector &);
57  ~vector ();
58  void add (nr_complex_t);
59  void add (vector *);
60  nr_complex_t get (int);
61  void set (nr_double_t, int);
62  void set (const nr_complex_t, int);
63  int getSize (void) const;
64  int checkSizes (vector, vector);
65  int getRequested (void) { return requested; }
66  void setRequested (int n) { requested = n; }
67  void reverse (void);
68  strlist * getDependencies (void);
69  void setDependencies (strlist *);
70  void setOrigin (char *);
71  char * getOrigin (void);
72  int contains (nr_complex_t, nr_double_t eps = NR_EPSI);
73  void sort (bool ascending = true);
74  void print (void);
76  nr_double_t maximum (void);
77  nr_double_t minimum (void);
78  nr_double_t rms (void);
79  nr_double_t variance (void);
80  nr_double_t stddev (void);
82  friend nr_complex_t sum (vector);
83  friend nr_complex_t prod (vector);
84  friend nr_complex_t avg (vector);
85  friend vector cumsum (vector);
86  friend vector cumprod (vector);
87  friend vector cumavg (vector);
88  friend vector dbm (vector, const nr_complex_t);
89  friend nr_complex_t integrate (vector v, const nr_complex_t);
90  friend nr_double_t integrate (vector v, const nr_double_t);
92  // vector manipulations
93  friend vector real (vector); // the real part
94  friend vector imag (vector); // the imaginary part
95  friend vector conj (vector); // the complex conjugate
96  friend vector norm (vector); // the square of the magnitude
97  friend vector arg (vector); // the angle in the plane
98  friend vector dB (vector);
99  friend vector log (vector);
100  friend vector log2 (vector);
101  friend vector pow (vector, const nr_complex_t);
102  friend vector pow (vector, const nr_double_t);
103  friend vector pow (const nr_complex_t, vector);
104  friend vector pow (const nr_double_t, vector);
105  friend vector pow (vector, vector);
106  friend vector ztor (vector, nr_complex_t);
107  friend vector rtoz (vector, nr_complex_t);
108  friend vector ytor (vector, nr_complex_t);
109  friend vector rtoy (vector, nr_complex_t);
110  friend vector diff (vector, vector, int);
111  friend vector unwrap (vector, nr_double_t, nr_double_t);
113  friend vector polar (vector, const nr_complex_t);
114  friend vector polar (const nr_complex_t, vector);
115  friend vector polar (vector, vector);
116  friend vector atan2 (vector, const nr_double_t);
117  friend vector atan2 (const nr_double_t, vector);
118  friend vector atan2 (vector, vector);
119  friend vector dbm2w (vector);
120  friend vector w2dbm (vector);
121  friend vector xhypot (vector, vector);
122  friend vector xhypot (vector, const nr_complex_t);
123  friend vector xhypot (vector, const nr_double_t);
124  friend vector xhypot (const nr_complex_t, vector);
125  friend vector xhypot (const nr_double_t, vector);
127  // overloaded math functions
128  friend vector abs (vector);
129  friend vector log10 (vector);
130  friend vector exp (vector);
131  friend vector limexp (vector);
132  friend vector sqrt (vector);
133  friend vector sin (vector);
134  friend vector asin (vector);
135  friend vector cos (vector);
136  friend vector acos (vector);
137  friend vector tan (vector);
138  friend vector atan (vector);
139  friend vector cot (vector);
140  friend vector acot (vector);
141  friend vector sinh (vector);
142  friend vector asinh (vector);
143  friend vector cosh (vector);
144  friend vector sech (vector);
145  friend vector cosech (vector);
146  friend vector acosh (vector);
147  friend vector asech (vector);
148  friend vector tanh (vector);
149  friend vector atanh (vector);
150  friend vector coth (vector);
151  friend vector acoth (vector);
152  friend vector signum (vector);
153  friend vector sign (vector);
154  friend vector sinc (vector);
155  friend vector ceil (vector);
156  friend vector floor (vector);
157  friend vector fix (vector);
158  friend vector round (vector);
159  friend vector sqr (vector);
160  friend vector step (vector);
161  friend vector jn (const int, vector);
162  friend vector yn (const int, vector);
163  friend vector i0 (vector);
164  friend vector erf (vector);
165  friend vector erfc (vector);
166  friend vector erfinv (vector);
167  friend vector erfcinv (vector);
169  // operator functions
170  friend vector operator + (vector, vector);
171  friend vector operator + (vector, const nr_complex_t);
172  friend vector operator + (vector, const nr_double_t);
173  friend vector operator + (const nr_complex_t, vector);
174  friend vector operator + (const nr_double_t, vector);
175  friend vector operator - (vector, vector);
176  friend vector operator - (vector, const nr_complex_t);
177  friend vector operator - (vector, const nr_double_t);
178  friend vector operator - (const nr_complex_t, vector);
179  friend vector operator - (const nr_double_t, vector);
180  friend vector operator * (vector, vector);
181  friend vector operator * (vector, const nr_complex_t);
182  friend vector operator * (vector, const nr_double_t);
183  friend vector operator * (const nr_complex_t, vector);
184  friend vector operator * (const nr_double_t, vector);
185  friend vector operator / (vector, vector);
186  friend vector operator / (vector, const nr_complex_t);
187  friend vector operator / (vector, const nr_double_t);
188  friend vector operator / (const nr_complex_t, vector);
189  friend vector operator / (const nr_double_t, vector);
190  friend vector operator % (vector, vector);
191  friend vector operator % (vector, const nr_complex_t);
192  friend vector operator % (vector, const nr_double_t);
193  friend vector operator % (const nr_complex_t, vector);
194  friend vector operator % (const nr_double_t, vector);
196  // comparisons
197  // friend int operator == (const vector *, const vector *);
198  // friend int operator != (const vector *, const vector *);
200  // assignment operations
203  vector operator = (const nr_double_t);
206  vector operator += (const nr_double_t);
209  vector operator -= (const nr_double_t);
212  vector operator *= (const nr_double_t);
215  vector operator /= (const nr_double_t);
217  // easy accessor operators
218  nr_complex_t operator () (int i) const { return data[i]; }
219  nr_complex_t& operator () (int i) { return data[i]; }
221  private:
222  int requested;
223  int size;
224  int capacity;
226  nr_complex_t * data;
227  char * origin;
228 };
230 /* declarations of friend functions to make them available in the
231  qucs namespace without argument-dependent lookup, see
233  http://stackoverflow.com/questions/7785886/access-friend-function-defined-in-class
235  for more info
236 */
237 nr_complex_t sum (vector);
238 nr_complex_t prod (vector);
239 nr_complex_t avg (vector);
240 vector cumsum (vector);
241 vector cumprod (vector);
242 vector cumavg (vector);
243 vector dbm (vector, const nr_complex_t z = 50.0);
244 nr_complex_t integrate (vector v, const nr_complex_t);
245 nr_double_t integrate (vector v, const nr_double_t);
246 vector real (vector); // the real part
247 vector imag (vector); // the imaginary part
248 vector conj (vector); // the complex conjugate
249 vector norm (vector); // the square of the magnitude
250 vector arg (vector); // the angle in the plane
251 vector dB (vector);
252 vector log (vector);
253 vector log2 (vector);
254 vector pow (vector, const nr_complex_t);
255 vector pow (vector, const nr_double_t);
256 vector pow (const nr_complex_t, vector);
257 vector pow (const nr_double_t, vector);
258 vector pow (vector, vector);
259 vector ztor (vector, nr_complex_t zref = 50.0);
260 vector rtoz (vector, nr_complex_t zref = 50.0);
261 vector ytor (vector, nr_complex_t zref = 50.0);
262 vector rtoy (vector, nr_complex_t zref = 50.0);
263 vector diff (vector, vector, int n = 1);
264 vector unwrap (vector, nr_double_t tol = M_PI, nr_double_t step = 2 * M_PI);
265 vector polar (vector, const nr_complex_t);
266 vector polar (const nr_complex_t, vector);
267 vector polar (vector, vector);
268 vector atan2 (vector, const nr_double_t);
269 vector atan2 (const nr_double_t, vector);
270 vector atan2 (vector, vector);
271 vector dbm2w (vector);
272 vector w2dbm (vector);
273 vector xhypot (vector, vector);
274 vector xhypot (vector, const nr_complex_t);
275 vector xhypot (vector, const nr_double_t);
276 vector xhypot (const nr_complex_t, vector);
277 vector xhypot (const nr_double_t, vector);
278 vector abs (vector);
279 vector log10 (vector);
280 vector exp (vector);
281 vector limexp (vector);
282 vector sqrt (vector);
283 vector sin (vector);
284 vector asin (vector);
285 vector cos (vector);
286 vector acos (vector);
287 vector tan (vector);
288 vector atan (vector);
289 vector cot (vector);
290 vector acot (vector);
291 vector sinh (vector);
292 vector asinh (vector);
293 vector cosh (vector);
294 vector sech (vector);
295 vector cosech (vector);
296 vector acosh (vector);
297 vector asech (vector);
298 vector tanh (vector);
299 vector atanh (vector);
300 vector coth (vector);
301 vector acoth (vector);
302 vector signum (vector);
303 vector sign (vector);
304 vector sinc (vector);
305 vector ceil (vector);
306 vector floor (vector);
307 vector fix (vector);
308 vector round (vector);
309 vector sqr (vector);
310 vector step (vector);
311 vector jn (const int, vector);
312 vector yn (const int, vector);
313 vector i0 (vector);
314 vector erf (vector);
315 vector erfc (vector);
316 vector erfinv (vector);
317 vector erfcinv (vector);
319 } // namespace qucs
321 #endif /* __VECTOR_H__ */
friend vector diff(vector, vector, int)
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
friend vector round(vector)
friend vector tanh(vector)
friend vector operator%(vector, vector)
vector w2dbm(vector)
Definition: vector.cpp:1186
vector cumavg(vector)
Definition: vector.cpp:1002
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
matrix abs(matrix a)
Computes magnitude of each matrix element.
Definition: matrix.cpp:531
nr_complex_t erf(const nr_complex_t z)
Error function.
Definition: complex.cpp:766
friend vector norm(vector)
vector operator-()
Definition: vector.cpp:689
friend nr_complex_t prod(vector)
friend vector asin(vector)
void setOrigin(char *)
Definition: vector.cpp:913
int getSize(void) const
Definition: vector.cpp:192
nr_complex_t ceil(const nr_complex_t z)
Complex ceil Ceil is the smallest integral value not less than argument Apply ceil to real and imagin...
Definition: complex.cpp:634
friend vector log10(vector)
nr_complex_t coth(const nr_complex_t z)
Compute complex hyperbolic cotangent.
Definition: complex.cpp:320
qucs::vector runavg(qucs::vector, const int)
vector cumsum(vector)
Definition: vector.cpp:992
void reverse(void)
Definition: vector.cpp:903
nr_complex_t pow(const nr_complex_t z, const nr_double_t d)
Compute power function with real exponent.
Definition: complex.cpp:238
friend vector cumsum(vector)
friend vector dbm(vector, const nr_complex_t)
friend vector ztor(vector, nr_complex_t)
nr_complex_t cos(const nr_complex_t z)
Compute complex cosine.
Definition: complex.cpp:57
void sort(bool ascending=true)
Definition: vector.cpp:934
friend vector sqrt(vector)
friend vector acot(vector)
nr_complex_t sum(vector)
Definition: vector.cpp:251
nr_complex_t step(const nr_complex_t z)
Heaviside step function for complex number.
Definition: complex.cpp:691
friend vector sqr(vector)
nr_complex_t avg(vector)
Definition: vector.cpp:263
friend vector arg(vector)
nr_complex_t signum(const nr_complex_t z)
complex signum function
Definition: complex.cpp:416
friend vector atanh(vector)
qucs::vector logspace(nr_double_t, nr_double_t, int)
Definition: vector.cpp:965
friend vector log2(vector)
friend vector sin(vector)
nr_complex_t atan(const nr_complex_t z)
Compute complex arc tangent.
Definition: complex.cpp:117
nr_complex_t cot(const nr_complex_t z)
Compute complex cotangent.
Definition: complex.cpp:298
nr_complex_t asech(const nr_complex_t z)
Compute complex argument hyperbolic secant.
Definition: complex.cpp:354
friend vector sech(vector)
friend nr_complex_t sum(vector)
friend vector tan(vector)
friend vector atan2(vector, const nr_double_t)
strlist * dependencies
Definition: parse_citi.y:225
nr_complex_t acot(const nr_complex_t z)
Compute complex arc cotangent.
Definition: complex.cpp:310
friend vector dB(vector)
Definition: parse_citi.y:147
friend vector acoth(vector)
friend vector operator/(vector, vector)
nr_complex_t acosh(const nr_complex_t z)
Compute complex arc hyperbolic cosine.
Definition: complex.cpp:162
nr_complex_t rtoz(const nr_complex_t r, nr_complex_t zref)
Converts reflexion coefficient to impedance.
Definition: complex.cpp:590
friend vector log(vector)
nr_complex_t sign(const nr_complex_t z)
complex sign function
Definition: complex.cpp:435
friend vector coth(vector)
friend vector floor(vector)
int checkSizes(vector, vector)
Definition: vector.cpp:196
friend vector asech(vector)
nr_complex_t asinh(const nr_complex_t z)
Compute complex arc hyperbolic sine.
Definition: complex.cpp:175
friend vector conj(vector)
nr_complex_t cosh(const nr_complex_t z)
Compute complex hyperbolic cosine.
Definition: complex.cpp:135
char * getOrigin(void)
Definition: vector.cpp:919
vector operator/=(vector)
Definition: vector.cpp:799
friend vector acosh(vector)
void setDependencies(strlist *)
Definition: vector.cpp:143
Definition: parse_mdl.y:516
vector cumprod(vector)
Definition: vector.cpp:1012
friend nr_complex_t avg(vector)
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
friend vector real(vector)
matrix imag(matrix a)
Imaginary part matrix.
Definition: matrix.cpp:581
vector operator*=(vector)
Definition: vector.cpp:749
nr_complex_t fix(const nr_complex_t z)
Complex fix.
Definition: complex.cpp:645
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
nr_double_t xhypot(const nr_complex_t a, const nr_complex_t b)
Euclidean distance function for complex argument.
Definition: complex.cpp:465
nr_double_t variance(void)
Definition: vector.cpp:1071
nr_complex_t acos(const nr_complex_t z)
Compute complex arc cosine.
Definition: complex.cpp:84
nr_complex_t log2(const nr_complex_t z)
Compute principal value of binary logarithm of z.
Definition: complex.cpp:393
double tol
nr_complex_t cosech(const nr_complex_t z)
Compute complex argument hyperbolic cosec.
Definition: complex.cpp:364
nr_complex_t yn(const int n, const nr_complex_t z)
Bessel function of second kind.
Definition: complex.cpp:742
nr_complex_t tanh(const nr_complex_t z)
Compute complex hyperbolic tangent.
Definition: complex.cpp:153
nr_complex_t sin(const nr_complex_t z)
Compute complex sine.
Definition: complex.cpp:66
const vector & operator=(const vector &)
Definition: vector.cpp:117
friend vector erfcinv(vector)
nr_complex_t ztor(const nr_complex_t z, nr_complex_t zref)
Converts impedance to reflexion coefficient.
Definition: complex.cpp:581
nr_double_t dB(const nr_complex_t z)
Magnitude in dB Compute .
Definition: complex.cpp:528
friend vector i0(vector)
void setRequested(int n)
Definition: vector.h:66
int getRequested(void)
Definition: vector.h:65
nr_complex_t asin(const nr_complex_t z)
Compute complex arc sine.
Definition: complex.cpp:102
friend vector imag(vector)
void add(nr_complex_t)
Definition: vector.cpp:151
friend vector atan(vector)
nr_double_t maximum(void)
Definition: vector.cpp:208
friend vector fix(vector)
nr_complex_t * data
Definition: parse_citi.y:226
nr_complex_t acoth(const nr_complex_t z)
Compute complex argument hyperbolic cotangent.
Definition: complex.cpp:332
qucs::vector linspace(nr_double_t, nr_double_t, int)
Definition: vector.cpp:950
Global math constants header file.
vector operator+=(vector)
Definition: vector.cpp:639
void set(nr_double_t, int)
Definition: vector.cpp:183
friend vector cot(vector)
nr_complex_t log10(const nr_complex_t z)
Compute principal value of decimal logarithm of z.
Definition: complex.cpp:225
nr_complex_t floor(const nr_complex_t z)
Complex floor.
Definition: complex.cpp:623
nr_complex_t sech(const nr_complex_t z)
Compute complex hyperbolic secant.
Definition: complex.cpp:343
friend vector erf(vector)
friend vector w2dbm(vector)
friend vector abs(vector)
friend vector operator*(vector, vector)
nr_complex_t integrate(vector v, const nr_complex_t)
Definition: vector.cpp:1207
friend vector polar(vector, const nr_complex_t)
friend vector dbm2w(vector)
nr_complex_t erfc(const nr_complex_t z)
Complementart error function.
Definition: complex.cpp:784
friend vector operator+(vector, vector)
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
vector operator-=(vector)
Definition: vector.cpp:695
nr_complex_t ytor(const nr_complex_t y, nr_complex_t zref)
Converts admittance to reflexion coefficient.
Definition: complex.cpp:599
nr_complex_t operator()(int i) const
Definition: parse_citi.y:218
nr_complex_t erfinv(const nr_complex_t z)
Inverse of error function.
Definition: complex.cpp:802
friend vector cosh(vector)
friend vector acos(vector)
vector diff(vector, vector, int n=1)
Definition: vector.cpp:591
nr_complex_t rtoy(const nr_complex_t r, nr_complex_t zref)
Converts reflexion coefficient to admittance.
Definition: complex.cpp:608
int contains(nr_complex_t, nr_double_t eps=NR_EPSI)
Definition: vector.cpp:925
nr_complex_t i0(const nr_complex_t z)
Modified Bessel function of first kind.
Definition: complex.cpp:754
nr_double_t rms(void)
Definition: vector.cpp:1066
nr_complex_t atan2(const nr_complex_t y, const nr_complex_t x)
Compute complex arc tangent fortran like function.
Definition: complex.cpp:377
friend nr_complex_t integrate(vector v, const nr_complex_t)
nr_complex_t sinc(const nr_complex_t z)
Cardinal sine.
Definition: complex.cpp:448
Definition: parse_zvr.y:141
nr_complex_t erfcinv(const nr_complex_t z)
Inverse of complementart error function.
Definition: complex.cpp:813
nr_complex_t limexp(const nr_complex_t z)
Compute limited complex exponential.
Definition: complex.cpp:539
friend vector pow(vector, const nr_complex_t)
friend vector limexp(vector)
friend vector sinh(vector)
nr_double_t norm(const nr_complex_t z)
Compute euclidian norm of complex number.
Definition: complex.cpp:283
nr_double_t stddev(void)
Definition: vector.cpp:1080
nr_complex_t sinh(const nr_complex_t z)
Compute complex hyperbolic sine.
Definition: complex.cpp:144
List int
Definition: parse_citi.y:183
nr_complex_t jn(const int n, const nr_complex_t z)
Bessel function of first kind.
Definition: complex.cpp:729
friend vector cumprod(vector)
vector dbm2w(vector)
Definition: vector.cpp:1193
friend vector ytor(vector, nr_complex_t)
nr_complex_t tan(const nr_complex_t z)
Compute complex tangent.
Definition: complex.cpp:75
nr_complex_t exp(const nr_complex_t z)
Compute complex exponential.
Definition: complex.cpp:205
nr_complex_t polar(const nr_double_t mag, const nr_double_t ang)
Construct a complex number using polar notation.
Definition: complex.cpp:551
matrix conj(matrix a)
Conjugate complex matrix.
Definition: matrix.cpp:505
nr_complex_t prod(vector)
Definition: vector.cpp:257
friend vector sign(vector)
friend vector erfinv(vector)
friend vector cosech(vector)
friend vector sinc(vector)
friend vector rtoz(vector, nr_complex_t)
nr_double_t minimum(void)
Definition: vector.cpp:222
friend vector yn(const int, vector)
friend vector rtoy(vector, nr_complex_t)
Definition: parse_zvr.y:130
vector dbm(vector, const nr_complex_t z=50.0)
Definition: vector.cpp:1215
nr_complex_t log(const nr_complex_t z)
Compute principal value of natural logarithm of z.
Definition: complex.cpp:215
friend vector signum(vector)
friend vector asinh(vector)
strlist * getDependencies(void)
Definition: vector.cpp:138
nr_complex_t round(const nr_complex_t z)
Complex round Round is the nearest integral value Apply round to real and imaginary part...
Definition: complex.cpp:496
friend vector jn(const int, vector)
friend vector ceil(vector)
char * origin
Definition: parse_citi.y:227
friend vector cos(vector)
matrix arg(matrix a)
Computes the argument of each matrix element.
Definition: matrix.cpp:555
friend vector cumavg(vector)
friend vector exp(vector)
friend vector step(vector)
nr_complex_t atanh(const nr_complex_t z)
Compute complex arc hyperbolic tangent.
Definition: complex.cpp:188
friend vector unwrap(vector, nr_double_t, nr_double_t)
friend vector erfc(vector)
vector unwrap(vector, nr_double_t tol=M_PI, nr_double_t step=2 *M_PI)
Definition: vector.cpp:235
friend vector xhypot(vector, vector)
void print(void)