Qucs-core  0.0.19
matrix.h
Go to the documentation of this file.
00001 /*
00002  * matrix.h - matrix class definitions
00003  *
00004  * Copyright (C) 2003-2009 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00029 #ifndef __MATRIX_H__
00030 #define __MATRIX_H__
00031 
00032 namespace qucs {
00033 
00034 class vector;
00035 class matrix;
00036 
00037 matrix eye (int);
00038 matrix transpose (matrix);
00039 matrix conj (matrix);
00040 matrix abs (matrix);
00041 matrix dB (matrix);
00042 matrix arg (matrix);
00043 matrix adjoint (matrix);
00044 matrix real (matrix);
00045 matrix imag (matrix);
00046 matrix sqr (matrix);
00047 matrix eye (int, int);
00048 matrix diagonal (vector);
00049 matrix pow (matrix, int);
00050 nr_complex_t cofactor (matrix, int, int);
00051 nr_complex_t detLaplace (matrix);
00052 nr_complex_t detGauss (matrix);
00053 nr_complex_t det (matrix);
00054 matrix inverseLaplace (matrix);
00055 matrix inverseGaussJordan (matrix);
00056 matrix inverse (matrix);
00057 matrix stos (matrix, nr_complex_t, nr_complex_t z0 = 50.0);
00058 matrix stos (matrix, nr_double_t, nr_double_t z0 = 50.0);
00059 matrix stos (matrix, vector, nr_complex_t z0 = 50.0);
00060 matrix stos (matrix, nr_complex_t, vector);
00061 matrix stos (matrix, vector, vector);
00062 matrix stoz (matrix, nr_complex_t z0 = 50.0);
00063 matrix stoz (matrix, vector);
00064 matrix ztos (matrix, nr_complex_t z0 = 50.0);
00065 matrix ztos (matrix, vector);
00066 matrix ztoy (matrix);
00067 matrix stoy (matrix, nr_complex_t z0 = 50.0);
00068 matrix stoy (matrix, vector);
00069 matrix ytos (matrix, nr_complex_t z0 = 50.0);
00070 matrix ytos (matrix, vector);
00071 matrix ytoz (matrix);
00072 matrix stoa (matrix, nr_complex_t z1 = 50.0, nr_complex_t z2 = 50.0);
00073 matrix atos (matrix, nr_complex_t z1 = 50.0, nr_complex_t z2 = 50.0);
00074 matrix stoh (matrix, nr_complex_t z1 = 50.0, nr_complex_t z2 = 50.0);
00075 matrix htos (matrix, nr_complex_t z1 = 50.0, nr_complex_t z2 = 50.0);
00076 matrix stog (matrix, nr_complex_t z1 = 50.0, nr_complex_t z2 = 50.0);
00077 matrix gtos (matrix, nr_complex_t z1 = 50.0, nr_complex_t z2 = 50.0);
00078 matrix cytocs (matrix, matrix);
00079 matrix cztocs (matrix, matrix);
00080 matrix cztocy (matrix, matrix);
00081 matrix cstocy (matrix, matrix);
00082 matrix cytocz (matrix, matrix);
00083 matrix cstocz (matrix, matrix);
00084 matrix twoport (matrix, char, char);
00085 nr_double_t rollet (matrix);
00086 nr_double_t b1 (matrix);
00087 matrix rad2deg     (matrix);
00088 matrix deg2rad     (matrix);
00089 
00090 
00095 class matrix
00096 {
00097  public:
00098   matrix ();
00099   matrix (int);
00100   matrix (int, int);
00101   matrix (const matrix &);
00102   const matrix& operator = (const matrix &);
00103   ~matrix ();
00104   nr_complex_t get (int, int);
00105   void set (int, int, nr_complex_t);
00106   int getCols (void) { return cols; }
00107   int getRows (void) { return rows; }
00108   nr_complex_t * getData (void) { return data; }
00109   void print (void);
00110   void exchangeRows (int, int);
00111   void exchangeCols (int, int);
00112 
00113   // operator functions
00114   friend matrix operator + (matrix, matrix);
00115   friend matrix operator + (nr_complex_t, matrix);
00116   friend matrix operator + (matrix, nr_complex_t);
00117   friend matrix operator + (nr_double_t, matrix);
00118   friend matrix operator + (matrix, nr_double_t);
00119   friend matrix operator - (matrix, matrix);
00120   friend matrix operator - (nr_complex_t, matrix);
00121   friend matrix operator - (matrix, nr_complex_t);
00122   friend matrix operator - (nr_double_t, matrix);
00123   friend matrix operator - (matrix, nr_double_t);
00124   friend matrix operator / (matrix, nr_complex_t);
00125   friend matrix operator / (matrix, nr_double_t);
00126   friend matrix operator * (nr_complex_t, matrix);
00127   friend matrix operator * (matrix, nr_complex_t);
00128   friend matrix operator * (nr_double_t, matrix);
00129   friend matrix operator * (matrix, nr_double_t);
00130   friend matrix operator * (matrix, matrix);
00131 
00132   // intrinsic operator functions
00133   matrix operator  - ();
00134   matrix operator += (matrix);
00135   matrix operator -= (matrix);
00136 
00137   // other operations
00138   friend matrix transpose (matrix);
00139   friend matrix conj (matrix);
00140   friend matrix abs (matrix);
00141   friend matrix dB (matrix);
00142   friend matrix arg (matrix);
00143   friend matrix adjoint (matrix);
00144   friend matrix real (matrix);
00145   friend matrix imag (matrix);
00146   friend matrix sqr (matrix);
00147   friend matrix eye (int, int);
00148   friend matrix diagonal (qucs::vector);
00149   friend matrix pow (matrix, int);
00150   friend nr_complex_t cofactor (matrix, int, int);
00151   friend nr_complex_t detLaplace (matrix);
00152   friend nr_complex_t detGauss (matrix);
00153   friend nr_complex_t det (matrix);
00154   friend matrix inverseLaplace (matrix);
00155   friend matrix inverseGaussJordan (matrix);
00156   friend matrix inverse (matrix);
00157   friend matrix stos (matrix, nr_complex_t, nr_complex_t);
00158   friend matrix stos (matrix, nr_double_t, nr_double_t);
00159   friend matrix stos (matrix, qucs::vector, nr_complex_t);
00160   friend matrix stos (matrix, nr_complex_t, qucs::vector);
00161   friend matrix stos (matrix, qucs::vector, qucs::vector);
00162   friend matrix stoz (matrix, nr_complex_t);
00163   friend matrix stoz (matrix, qucs::vector);
00164   friend matrix ztos (matrix, nr_complex_t);
00165   friend matrix ztos (matrix, qucs::vector);
00166   friend matrix ztoy (matrix);
00167   friend matrix stoy (matrix, nr_complex_t);
00168   friend matrix stoy (matrix, qucs::vector);
00169   friend matrix ytos (matrix, nr_complex_t);
00170   friend matrix ytos (matrix, qucs::vector);
00171   friend matrix ytoz (matrix);
00172   friend matrix stoa (matrix, nr_complex_t, nr_complex_t);
00173   friend matrix atos (matrix, nr_complex_t, nr_complex_t);
00174   friend matrix stoh (matrix, nr_complex_t, nr_complex_t);
00175   friend matrix htos (matrix, nr_complex_t, nr_complex_t);
00176   friend matrix stog (matrix, nr_complex_t, nr_complex_t);
00177   friend matrix gtos (matrix, nr_complex_t, nr_complex_t);
00178   friend matrix cytocs (matrix, matrix);
00179   friend matrix cztocs (matrix, matrix);
00180   friend matrix cztocy (matrix, matrix);
00181   friend matrix cstocy (matrix, matrix);
00182   friend matrix cytocz (matrix, matrix);
00183   friend matrix cstocz (matrix, matrix);
00184 
00185   friend matrix twoport (matrix, char, char);
00186   friend nr_double_t rollet (matrix);
00187   friend nr_double_t b1 (matrix);
00188 
00189   friend matrix rad2deg    (matrix);
00190   friend matrix deg2rad    (matrix);
00191 
00200   nr_complex_t  operator () (int r, int c) const { return data[r * cols + c]; }
00209   nr_complex_t& operator () (int r, int c) { return data[r * cols + c]; }
00210 
00211  private:
00213   int cols;
00215   int rows;
00217   nr_complex_t * data;
00218 };
00219 
00220 } // namespace qucs
00221 
00222 #endif /* __MATRIX_H__ */