My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vector.h
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
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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: vector.h 1825 2011-03-11 20:42:14Z ela $
23  *
24  */
25 
26 #ifndef __VECTOR_H__
27 #define __VECTOR_H__
28 
29 #include "consts.h"
30 #include "precision.h"
31 
32 #ifdef log2
33 #undef log2
34 #endif
35 
36 class strlist;
37 class vector;
38 
39 vector linspace (nr_double_t, nr_double_t, int);
40 vector logspace (nr_double_t, nr_double_t, int);
41 vector runavg (vector, const int);
42 vector runavg (const nr_complex_t, const int);
43 
44 class vector : public object
45 {
46  public:
47  vector ();
48  vector (const char *);
49  vector (int);
50  vector (int, nr_complex_t);
51  vector (const char *, int);
52  vector (const vector &);
53  const vector& operator = (const vector &);
54  ~vector ();
55  void add (nr_complex_t);
56  void add (vector *);
57  nr_complex_t get (int);
58  void set (nr_double_t, int);
59  void set (const nr_complex_t, int);
60  int getSize (void);
61  int checkSizes (vector, vector);
62  int getRequested (void) { return requested; }
63  void setRequested (int n) { requested = n; }
64  void reverse (void);
65  strlist * getDependencies (void);
66  void setDependencies (strlist *);
67  void setOrigin (char *);
68  char * getOrigin (void);
69  int contains (nr_complex_t, nr_double_t eps = NR_EPSI);
70  void sort (bool ascending = true);
71  void print (void);
72 
73  nr_double_t maximum (void);
74  nr_double_t minimum (void);
75  nr_double_t rms (void);
76  nr_double_t variance (void);
77  nr_double_t stddev (void);
78 
79  friend nr_complex_t sum (vector);
80  friend nr_complex_t prod (vector);
81  friend nr_complex_t avg (vector);
82  friend vector cumsum (vector);
83  friend vector cumprod (vector);
84  friend vector cumavg (vector);
85  friend vector dbm (vector, const nr_complex_t z = 50.0);
86  friend nr_complex_t integrate (vector v, const nr_complex_t);
87  friend nr_double_t integrate (vector v, const nr_double_t);
88 
89  // vector manipulations
90  friend vector real (vector); // the real part
91  friend vector imag (vector); // the imaginary part
92  friend vector conj (vector); // the complex conjugate
93  friend vector norm (vector); // the square of the magnitude
94  friend vector arg (vector); // the angle in the plane
95  friend vector dB (vector);
96  friend vector log (vector);
97  friend vector log2 (vector);
98  friend vector pow (vector, const nr_complex_t);
99  friend vector pow (vector, const nr_double_t);
100  friend vector pow (const nr_complex_t, vector);
101  friend vector pow (const nr_double_t, vector);
102  friend vector pow (vector, vector);
103  friend vector ztor (vector, nr_complex_t zref = 50.0);
104  friend vector rtoz (vector, nr_complex_t zref = 50.0);
105  friend vector ytor (vector, nr_complex_t zref = 50.0);
106  friend vector rtoy (vector, nr_complex_t zref = 50.0);
107  friend vector diff (vector, vector, int n = 1);
108  friend vector unwrap (vector,
109  nr_double_t tol = M_PI, nr_double_t step = 2 * M_PI);
110 
111  friend vector polar (vector, const nr_complex_t);
112  friend vector polar (const nr_complex_t, vector);
113  friend vector polar (vector, vector);
114  friend vector atan2 (vector, const nr_double_t);
115  friend vector atan2 (const nr_double_t, vector);
116  friend vector atan2 (vector, vector);
117  friend vector dbm2w (vector);
118  friend vector w2dbm (vector);
119  friend vector xhypot (vector, vector);
120  friend vector xhypot (vector, const nr_complex_t);
121  friend vector xhypot (vector, const nr_double_t);
122  friend vector xhypot (const nr_complex_t, vector);
123  friend vector xhypot (const nr_double_t, vector);
124 
125  // overloaded math functions
126  friend vector abs (vector);
127  friend vector log10 (vector);
128  friend vector exp (vector);
129  friend vector limexp (vector);
130  friend vector sqrt (vector);
131  friend vector sin (vector);
132  friend vector asin (vector);
133  friend vector cos (vector);
134  friend vector acos (vector);
135  friend vector tan (vector);
136  friend vector atan (vector);
137  friend vector cot (vector);
138  friend vector acot (vector);
139  friend vector sinh (vector);
140  friend vector asinh (vector);
141  friend vector cosh (vector);
142  friend vector acosh (vector);
143  friend vector asech (vector);
144  friend vector tanh (vector);
145  friend vector atanh (vector);
146  friend vector coth (vector);
147  friend vector acoth (vector);
148  friend vector signum (vector);
149  friend vector sign (vector);
150  friend vector sinc (vector);
151  friend vector ceil (vector);
152  friend vector floor (vector);
153  friend vector fix (vector);
154  friend vector round (vector);
155  friend vector sqr (vector);
156  friend vector step (vector);
157  friend vector jn (const int, vector);
158  friend vector yn (const int, vector);
159  friend vector i0 (vector);
160  friend vector erf (vector);
161  friend vector erfc (vector);
162  friend vector erfinv (vector);
163  friend vector erfcinv (vector);
164 
165  // operator functions
166  friend vector operator + (vector, vector);
167  friend vector operator + (vector, const nr_complex_t);
168  friend vector operator + (vector, const nr_double_t);
169  friend vector operator + (const nr_complex_t, vector);
170  friend vector operator + (const nr_double_t, vector);
171  friend vector operator - (vector, vector);
172  friend vector operator - (vector, const nr_complex_t);
173  friend vector operator - (vector, const nr_double_t);
174  friend vector operator - (const nr_complex_t, vector);
175  friend vector operator - (const nr_double_t, vector);
176  friend vector operator * (vector, vector);
177  friend vector operator * (vector, const nr_complex_t);
178  friend vector operator * (vector, const nr_double_t);
179  friend vector operator * (const nr_complex_t, vector);
180  friend vector operator * (const nr_double_t, vector);
181  friend vector operator / (vector, vector);
182  friend vector operator / (vector, const nr_complex_t);
183  friend vector operator / (vector, const nr_double_t);
184  friend vector operator / (const nr_complex_t, vector);
185  friend vector operator / (const nr_double_t, vector);
186  friend vector operator % (vector, vector);
187  friend vector operator % (vector, const nr_complex_t);
188  friend vector operator % (vector, const nr_double_t);
189  friend vector operator % (const nr_complex_t, vector);
190  friend vector operator % (const nr_double_t, vector);
191 
192  // comparisons
193  // friend int operator == (const vector *, const vector *);
194  // friend int operator != (const vector *, const vector *);
195 
196  // assignment operations
199  vector operator = (const nr_double_t);
202  vector operator += (const nr_double_t);
205  vector operator -= (const nr_double_t);
208  vector operator *= (const nr_double_t);
211  vector operator /= (const nr_double_t);
212 
213  // easy accessor operators
214  nr_complex_t operator () (int i) const { return data[i]; }
215  nr_complex_t& operator () (int i) { return data[i]; }
216 
217  private:
218  int requested;
219  int size;
220  int capacity;
221  strlist * dependencies;
222  nr_complex_t * data;
223  char * origin;
224 };
225 
226 #endif /* __VECTOR_H__ */