Qucs-core
0.0.19
|
00001 /* 00002 * vector.h - vector class definitions 00003 * 00004 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Stefan Jahn <stefan@lkcc.org> 00005 * Copyright (C) 2006 Gunther Kraut <gn.kraut@t-online.de> 00006 * 00007 * This is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2, or (at your option) 00010 * any later version. 00011 * 00012 * This software is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this package; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 00020 * Boston, MA 02110-1301, USA. 00021 * 00022 * $Id$ 00023 * 00024 */ 00025 00026 #ifndef __VECTOR_H__ 00027 #define __VECTOR_H__ 00028 00029 #include <limits> 00030 00031 #include "consts.h" 00032 #include "precision.h" 00033 #include "complex.h" 00034 00035 #ifdef log2 00036 #undef log2 00037 #endif 00038 00039 namespace qucs { 00040 00041 class strlist; 00042 class vector; 00043 00044 qucs::vector linspace (nr_double_t, nr_double_t, int); 00045 qucs::vector logspace (nr_double_t, nr_double_t, int); 00046 qucs::vector runavg (qucs::vector, const int); 00047 qucs::vector runavg (const nr_complex_t, const int); 00048 00049 class vector : public object 00050 { 00051 public: 00052 vector * getNext (void) const { return this->next; } 00053 void setNext (vector * const o) { this->next = o; } 00054 vector * getPrev (void) const { return prev; } 00055 void setPrev (vector * const o) { this->prev = o; } 00056 private: 00057 vector * next; 00058 vector * prev; 00059 00060 public: 00061 vector (); 00062 vector (const std::string &); 00063 vector (int); 00064 vector (int, nr_complex_t); 00065 vector (const std::string &, int); 00066 vector (const vector &); 00067 const vector& operator = (const vector &); 00068 ~vector (); 00069 void add (nr_complex_t); 00070 void add (vector *); 00071 nr_complex_t get (int); 00072 void set (nr_double_t, int); 00073 void set (const nr_complex_t, int); 00074 int getSize (void) const; 00075 int checkSizes (vector, vector); 00076 int getRequested (void) { return requested; } 00077 void setRequested (int n) { requested = n; } 00078 void reverse (void); 00079 strlist * getDependencies (void); 00080 void setDependencies (strlist *); 00081 void setOrigin (const char *); 00082 char * getOrigin (void); 00083 int contains (nr_complex_t, nr_double_t eps = std::numeric_limits<nr_double_t>::epsilon()); 00084 void sort (bool ascending = true); 00085 void print (void); 00086 00087 nr_double_t maximum (void); 00088 nr_double_t minimum (void); 00089 nr_double_t rms (void); 00090 nr_double_t variance (void); 00091 nr_double_t stddev (void); 00092 00093 friend nr_complex_t sum (vector); 00094 friend nr_complex_t prod (vector); 00095 friend nr_complex_t avg (vector); 00096 friend vector cumsum (vector); 00097 friend vector cumprod (vector); 00098 friend vector cumavg (vector); 00099 friend vector dbm (vector, const nr_complex_t); 00100 friend nr_complex_t integrate (vector v, const nr_complex_t); 00101 friend nr_double_t integrate (vector v, const nr_double_t); 00102 00103 // vector manipulations 00104 friend vector real (vector); // the real part 00105 friend vector imag (vector); // the imaginary part 00106 friend vector conj (vector); // the complex conjugate 00107 friend vector norm (vector); // the square of the magnitude 00108 friend vector arg (vector); // the angle in the plane 00109 friend vector dB (vector); 00110 friend vector log (vector); 00111 friend vector log2 (vector); 00112 friend vector pow (vector, const nr_complex_t); 00113 friend vector pow (vector, const nr_double_t); 00114 friend vector pow (const nr_complex_t, vector); 00115 friend vector pow (const nr_double_t, vector); 00116 friend vector pow (vector, vector); 00117 friend vector ztor (vector, nr_complex_t); 00118 friend vector rtoz (vector, nr_complex_t); 00119 friend vector ytor (vector, nr_complex_t); 00120 friend vector rtoy (vector, nr_complex_t); 00121 friend vector diff (vector, vector, int); 00122 friend vector unwrap (vector, nr_double_t, nr_double_t); 00123 00124 friend vector polar (vector, const nr_complex_t); 00125 friend vector polar (const nr_complex_t, vector); 00126 friend vector polar (vector, vector); 00127 friend vector atan2 (vector, const nr_double_t); 00128 friend vector atan2 (const nr_double_t, vector); 00129 friend vector atan2 (vector, vector); 00130 friend vector dbm2w (vector); 00131 friend vector w2dbm (vector); 00132 friend vector xhypot (vector, vector); 00133 friend vector xhypot (vector, const nr_complex_t); 00134 friend vector xhypot (vector, const nr_double_t); 00135 friend vector xhypot (const nr_complex_t, vector); 00136 friend vector xhypot (const nr_double_t, vector); 00137 00138 // overloaded math functions 00139 friend vector abs (vector); 00140 friend vector log10 (vector); 00141 friend vector exp (vector); 00142 friend vector limexp (vector); 00143 friend vector sqrt (vector); 00144 friend vector sin (vector); 00145 friend vector asin (vector); 00146 friend vector cos (vector); 00147 friend vector acos (vector); 00148 friend vector tan (vector); 00149 friend vector atan (vector); 00150 friend vector cot (vector); 00151 friend vector acot (vector); 00152 friend vector sinh (vector); 00153 friend vector asinh (vector); 00154 friend vector cosh (vector); 00155 friend vector sech (vector); 00156 friend vector cosech (vector); 00157 friend vector acosh (vector); 00158 friend vector asech (vector); 00159 friend vector tanh (vector); 00160 friend vector atanh (vector); 00161 friend vector coth (vector); 00162 friend vector acoth (vector); 00163 friend vector signum (vector); 00164 friend vector sign (vector); 00165 friend vector sinc (vector); 00166 friend vector ceil (vector); 00167 friend vector floor (vector); 00168 friend vector fix (vector); 00169 friend vector round (vector); 00170 friend vector sqr (vector); 00171 friend vector step (vector); 00172 friend vector jn (const int, vector); 00173 friend vector yn (const int, vector); 00174 friend vector i0 (vector); 00175 friend vector erf (vector); 00176 friend vector erfc (vector); 00177 friend vector erfinv (vector); 00178 friend vector erfcinv (vector); 00179 friend vector rad2deg (vector); 00180 friend vector deg2rad (vector); 00181 00182 // operator functions 00183 friend vector operator + (vector, vector); 00184 friend vector operator + (vector, const nr_complex_t); 00185 friend vector operator + (vector, const nr_double_t); 00186 friend vector operator + (const nr_complex_t, vector); 00187 friend vector operator + (const nr_double_t, vector); 00188 friend vector operator - (vector, vector); 00189 friend vector operator - (vector, const nr_complex_t); 00190 friend vector operator - (vector, const nr_double_t); 00191 friend vector operator - (const nr_complex_t, vector); 00192 friend vector operator - (const nr_double_t, vector); 00193 friend vector operator * (vector, vector); 00194 friend vector operator * (vector, const nr_complex_t); 00195 friend vector operator * (vector, const nr_double_t); 00196 friend vector operator * (const nr_complex_t, vector); 00197 friend vector operator * (const nr_double_t, vector); 00198 friend vector operator / (vector, vector); 00199 friend vector operator / (vector, const nr_complex_t); 00200 friend vector operator / (vector, const nr_double_t); 00201 friend vector operator / (const nr_complex_t, vector); 00202 friend vector operator / (const nr_double_t, vector); 00203 friend vector operator % (vector, vector); 00204 friend vector operator % (vector, const nr_complex_t); 00205 friend vector operator % (vector, const nr_double_t); 00206 friend vector operator % (const nr_complex_t, vector); 00207 friend vector operator % (const nr_double_t, vector); 00208 00209 // comparisons 00210 // friend int operator == (const vector *, const vector *); 00211 // friend int operator != (const vector *, const vector *); 00212 00213 // assignment operations 00214 vector operator - (); 00215 vector operator = (const nr_complex_t); 00216 vector operator = (const nr_double_t); 00217 vector operator += (vector); 00218 vector operator += (const nr_complex_t); 00219 vector operator += (const nr_double_t); 00220 vector operator -= (vector); 00221 vector operator -= (const nr_complex_t); 00222 vector operator -= (const nr_double_t); 00223 vector operator *= (vector); 00224 vector operator *= (const nr_complex_t); 00225 vector operator *= (const nr_double_t); 00226 vector operator /= (vector); 00227 vector operator /= (const nr_complex_t); 00228 vector operator /= (const nr_double_t); 00229 00230 // easy accessor operators 00231 nr_complex_t operator () (int i) const { return data[i]; } 00232 nr_complex_t& operator () (int i) { return data[i]; } 00233 00234 private: 00235 int requested; 00236 int size; 00237 int capacity; 00238 strlist * dependencies; 00239 nr_complex_t * data; 00240 char * origin; 00241 }; 00242 00243 /* declarations of friend functions to make them available in the 00244 qucs namespace without argument-dependent lookup, see 00245 00246 http://stackoverflow.com/questions/7785886/access-friend-function-defined-in-class 00247 00248 for more info 00249 */ 00250 nr_complex_t sum (vector); 00251 nr_complex_t prod (vector); 00252 nr_complex_t avg (vector); 00253 vector cumsum (vector); 00254 vector cumprod (vector); 00255 vector cumavg (vector); 00256 vector dbm (vector, const nr_complex_t z = 50.0); 00257 nr_complex_t integrate (vector v, const nr_complex_t); 00258 nr_double_t integrate (vector v, const nr_double_t); 00259 vector real (vector); // the real part 00260 vector imag (vector); // the imaginary part 00261 vector conj (vector); // the complex conjugate 00262 vector norm (vector); // the square of the magnitude 00263 vector arg (vector); // the angle in the plane 00264 vector dB (vector); 00265 vector log (vector); 00266 vector log2 (vector); 00267 vector pow (vector, const nr_complex_t); 00268 vector pow (vector, const nr_double_t); 00269 vector pow (const nr_complex_t, vector); 00270 vector pow (const nr_double_t, vector); 00271 vector pow (vector, vector); 00272 vector ztor (vector, nr_complex_t zref = 50.0); 00273 vector rtoz (vector, nr_complex_t zref = 50.0); 00274 vector ytor (vector, nr_complex_t zref = 50.0); 00275 vector rtoy (vector, nr_complex_t zref = 50.0); 00276 vector diff (vector, vector, int n = 1); 00277 vector unwrap (vector, nr_double_t tol = pi, nr_double_t step = 2 * pi); 00278 vector polar (vector, const nr_complex_t); 00279 vector polar (const nr_complex_t, vector); 00280 vector polar (vector, vector); 00281 vector atan2 (vector, const nr_double_t); 00282 vector atan2 (const nr_double_t, vector); 00283 vector atan2 (vector, vector); 00284 vector dbm2w (vector); 00285 vector w2dbm (vector); 00286 vector xhypot (vector, vector); 00287 vector xhypot (vector, const nr_complex_t); 00288 vector xhypot (vector, const nr_double_t); 00289 vector xhypot (const nr_complex_t, vector); 00290 vector xhypot (const nr_double_t, vector); 00291 vector abs (vector); 00292 vector log10 (vector); 00293 vector exp (vector); 00294 vector limexp (vector); 00295 vector sqrt (vector); 00296 vector sin (vector); 00297 vector asin (vector); 00298 vector cos (vector); 00299 vector acos (vector); 00300 vector tan (vector); 00301 vector atan (vector); 00302 vector cot (vector); 00303 vector acot (vector); 00304 vector sinh (vector); 00305 vector asinh (vector); 00306 vector cosh (vector); 00307 vector sech (vector); 00308 vector cosech (vector); 00309 vector acosh (vector); 00310 vector asech (vector); 00311 vector tanh (vector); 00312 vector atanh (vector); 00313 vector coth (vector); 00314 vector acoth (vector); 00315 vector signum (vector); 00316 vector sign (vector); 00317 vector sinc (vector); 00318 vector ceil (vector); 00319 vector floor (vector); 00320 vector fix (vector); 00321 vector round (vector); 00322 vector sqr (vector); 00323 vector step (vector); 00324 vector jn (const int, vector); 00325 vector yn (const int, vector); 00326 vector i0 (vector); 00327 vector erf (vector); 00328 vector erfc (vector); 00329 vector erfinv (vector); 00330 vector erfcinv (vector); 00331 vector rad2deg (vector); 00332 vector deg2rad (vector); 00333 00334 } // namespace qucs 00335 00336 #endif /* __VECTOR_H__ */