home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-bin.lha / include / octave / CMatrix.h < prev    next >
C/C++ Source or Header  |  1996-10-12  |  13KB  |  366 lines

  1. //                                  -*- C++ -*-
  2. /*
  3.  
  4. Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. */
  23.  
  24. #if !defined (octave_ComplexMatrix_h)
  25. #define octave_ComplexMatrix_h 1
  26.  
  27. #include <Complex.h>
  28.  
  29. #include "Array.h"
  30.  
  31. #include "mx-defs.h"
  32.  
  33. extern "C++" {
  34.  
  35. class ComplexMatrix : public Array2<Complex>
  36. {
  37. friend class Matrix;
  38. friend class ComplexCHOL;
  39. friend class ComplexHESS;
  40. friend class ComplexLU;
  41. friend class ComplexQR;
  42. friend class ComplexQRP;
  43. friend class ComplexSCHUR;
  44. friend class ComplexSVD;
  45.  
  46. public:
  47.  
  48.   ComplexMatrix (void) : Array2<Complex> () { }
  49.   ComplexMatrix (int r, int c) : Array2<Complex> (r, c) { }
  50.   ComplexMatrix (int r, int c, const Complex& val)
  51.     : Array2<Complex> (r, c, val) { }
  52.   ComplexMatrix (const Matrix& a);
  53.   ComplexMatrix (const Array2<Complex>& a) : Array2<Complex> (a) { }
  54.   ComplexMatrix (const ComplexMatrix& a) : Array2<Complex> (a) { }
  55.   ComplexMatrix (const DiagMatrix& a);
  56.   ComplexMatrix (const DiagArray<Complex>& a) : Array2<Complex> (a) { }
  57.   ComplexMatrix (const ComplexDiagMatrix& a);
  58.  
  59.   ComplexMatrix& operator = (const ComplexMatrix& a)
  60.     {
  61.       Array2<Complex>::operator = (a);
  62.       return *this;
  63.     }
  64.  
  65.   int operator == (const ComplexMatrix& a) const;
  66.   int operator != (const ComplexMatrix& a) const;
  67.  
  68. // destructive insert/delete/reorder operations
  69.  
  70.   ComplexMatrix& insert (const Matrix& a, int r, int c);
  71.   ComplexMatrix& insert (const RowVector& a, int r, int c);
  72.   ComplexMatrix& insert (const ColumnVector& a, int r, int c);
  73.   ComplexMatrix& insert (const DiagMatrix& a, int r, int c);
  74.  
  75.   ComplexMatrix& insert (const ComplexMatrix& a, int r, int c);
  76.   ComplexMatrix& insert (const ComplexRowVector& a, int r, int c);
  77.   ComplexMatrix& insert (const ComplexColumnVector& a, int r, int c);
  78.   ComplexMatrix& insert (const ComplexDiagMatrix& a, int r, int c);
  79.  
  80.   ComplexMatrix& fill (double val);
  81.   ComplexMatrix& fill (const Complex& val);
  82.   ComplexMatrix& fill (double val, int r1, int c1, int r2, int c2);
  83.   ComplexMatrix& fill (const Complex& val, int r1, int c1, int r2, int c2);
  84.  
  85.   ComplexMatrix append (const Matrix& a) const;
  86.   ComplexMatrix append (const RowVector& a) const;
  87.   ComplexMatrix append (const ColumnVector& a) const;
  88.   ComplexMatrix append (const DiagMatrix& a) const;
  89.  
  90.   ComplexMatrix append (const ComplexMatrix& a) const;
  91.   ComplexMatrix append (const ComplexRowVector& a) const;
  92.   ComplexMatrix append (const ComplexColumnVector& a) const;
  93.   ComplexMatrix append (const ComplexDiagMatrix& a) const;
  94.  
  95.   ComplexMatrix stack (const Matrix& a) const;
  96.   ComplexMatrix stack (const RowVector& a) const;
  97.   ComplexMatrix stack (const ColumnVector& a) const;
  98.   ComplexMatrix stack (const DiagMatrix& a) const;
  99.  
  100.   ComplexMatrix stack (const ComplexMatrix& a) const;
  101.   ComplexMatrix stack (const ComplexRowVector& a) const;
  102.   ComplexMatrix stack (const ComplexColumnVector& a) const;
  103.   ComplexMatrix stack (const ComplexDiagMatrix& a) const;
  104.  
  105.   ComplexMatrix hermitian (void) const;  // complex conjugate transpose
  106.   ComplexMatrix transpose (void) const;
  107.  
  108.   friend ComplexMatrix conj (const ComplexMatrix& a);
  109.  
  110. // resize is the destructive equivalent for this one
  111.  
  112.   ComplexMatrix extract (int r1, int c1, int r2, int c2) const;
  113.  
  114. // extract row or column i.
  115.  
  116.   ComplexRowVector row (int i) const;
  117.   ComplexRowVector row (char *s) const;
  118.  
  119.   ComplexColumnVector column (int i) const;
  120.   ComplexColumnVector column (char *s) const;
  121.  
  122.   ComplexMatrix inverse (void) const;
  123.   ComplexMatrix inverse (int& info) const;
  124.   ComplexMatrix inverse (int& info, double& rcond) const;
  125.  
  126.   ComplexMatrix pseudo_inverse (double tol = 0.0);
  127.  
  128.   ComplexMatrix fourier (void) const;
  129.   ComplexMatrix ifourier (void) const;
  130.  
  131.   ComplexMatrix fourier2d (void) const;
  132.   ComplexMatrix ifourier2d (void) const;
  133.  
  134.   ComplexDET determinant (void) const;
  135.   ComplexDET determinant (int& info) const;
  136.   ComplexDET determinant (int& info, double& rcond) const;
  137.  
  138.   ComplexMatrix solve (const Matrix& b) const;
  139.   ComplexMatrix solve (const Matrix& b, int& info) const;
  140.   ComplexMatrix solve (const Matrix& b, int& info, double& rcond) const;
  141.  
  142.   ComplexMatrix solve (const ComplexMatrix& b) const;
  143.   ComplexMatrix solve (const ComplexMatrix& b, int& info) const;
  144.   ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const;
  145.  
  146.   ComplexColumnVector solve (const ComplexColumnVector& b) const;
  147.   ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const;
  148.   ComplexColumnVector solve (const ComplexColumnVector& b, int& info,
  149.                  double& rcond) const;
  150.  
  151.   ComplexMatrix lssolve (const ComplexMatrix& b) const;
  152.   ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const;
  153.   ComplexMatrix lssolve (const ComplexMatrix& b, int& info,
  154.              int& rank) const;
  155.  
  156.   ComplexColumnVector lssolve (const ComplexColumnVector& b) const;
  157.   ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const;
  158.   ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info,
  159.                    int& rank) const;
  160.  
  161. // column vector by row vector -> matrix operations
  162.  
  163.   friend ComplexMatrix operator * (const ColumnVector& a,
  164.                    const ComplexRowVector& b);
  165.  
  166.   friend ComplexMatrix operator * (const ComplexColumnVector& a,
  167.                    const RowVector& b);
  168.  
  169.   friend ComplexMatrix operator * (const ComplexColumnVector& a,
  170.                    const ComplexRowVector& b);
  171.  
  172. // diagonal matrix by scalar -> matrix operations
  173.  
  174.   friend ComplexMatrix operator + (const DiagMatrix& a, const Complex& s);
  175.   friend ComplexMatrix operator - (const DiagMatrix& a, const Complex& s);
  176.  
  177.   friend ComplexMatrix operator + (const ComplexDiagMatrix& a, double s);
  178.   friend ComplexMatrix operator - (const ComplexDiagMatrix& a, double s);
  179.  
  180.   friend ComplexMatrix operator + (const ComplexDiagMatrix& a,
  181.                    const Complex& s);
  182.   friend ComplexMatrix operator - (const ComplexDiagMatrix& a,
  183.                    const Complex& s);
  184.  
  185. // scalar by diagonal matrix -> matrix operations
  186.  
  187.   friend ComplexMatrix operator + (const Complex& s, const DiagMatrix& a);
  188.   friend ComplexMatrix operator - (const Complex& s, const DiagMatrix& a);
  189.  
  190.   friend ComplexMatrix operator + (double s, const ComplexDiagMatrix& a);
  191.   friend ComplexMatrix operator - (double s, const ComplexDiagMatrix& a);
  192.  
  193.   friend ComplexMatrix operator + (const Complex& s,
  194.                    const ComplexDiagMatrix& a);
  195.   friend ComplexMatrix operator - (const Complex& s,
  196.                    const ComplexDiagMatrix& a);
  197.  
  198. // matrix by diagonal matrix -> matrix operations
  199.  
  200.   ComplexMatrix& operator += (const DiagMatrix& a);
  201.   ComplexMatrix& operator -= (const DiagMatrix& a);
  202.  
  203.   ComplexMatrix& operator += (const ComplexDiagMatrix& a);
  204.   ComplexMatrix& operator -= (const ComplexDiagMatrix& a);
  205.  
  206.   friend ComplexMatrix operator + (const Matrix& a,
  207.                    const ComplexDiagMatrix& b); 
  208.   friend ComplexMatrix operator - (const Matrix& a,
  209.                    const ComplexDiagMatrix& b);
  210.   friend ComplexMatrix operator * (const Matrix& a,
  211.                    const ComplexDiagMatrix& b);
  212.  
  213. // diagonal matrix by matrix -> matrix operations
  214.  
  215.   friend ComplexMatrix operator + (const DiagMatrix& a,
  216.                    const ComplexMatrix& b);
  217.   friend ComplexMatrix operator - (const DiagMatrix& a,
  218.                    const ComplexMatrix& b);
  219.   friend ComplexMatrix operator * (const DiagMatrix& a,
  220.                    const ComplexMatrix& b);
  221.  
  222.   friend ComplexMatrix operator + (const ComplexDiagMatrix& a,
  223.                    const Matrix& b); 
  224.   friend ComplexMatrix operator - (const ComplexDiagMatrix& a,
  225.                    const Matrix& b);
  226.   friend ComplexMatrix operator * (const ComplexDiagMatrix& a,
  227.                    const Matrix& b);
  228.  
  229.   friend ComplexMatrix operator + (const ComplexDiagMatrix& a,
  230.                    const ComplexMatrix& b);
  231.   friend ComplexMatrix operator - (const ComplexDiagMatrix& a,
  232.                    const ComplexMatrix& b);
  233.   friend ComplexMatrix operator * (const ComplexDiagMatrix& a,
  234.                    const ComplexMatrix& b);
  235.  
  236. // matrix by matrix -> matrix operations
  237.  
  238.   ComplexMatrix& operator += (const Matrix& a);
  239.   ComplexMatrix& operator -= (const Matrix& a);
  240.  
  241.   ComplexMatrix& operator += (const ComplexMatrix& a);
  242.   ComplexMatrix& operator -= (const ComplexMatrix& a);
  243.  
  244. // unary operations
  245.  
  246.   Matrix operator ! (void) const;
  247.  
  248. // matrix by scalar -> matrix operations
  249.  
  250.   friend ComplexMatrix operator + (const Matrix& a, const Complex& s);
  251.   friend ComplexMatrix operator - (const Matrix& a, const Complex& s);
  252.   friend ComplexMatrix operator * (const Matrix& a, const Complex& s);
  253.   friend ComplexMatrix operator / (const Matrix& a, const Complex& s);
  254.  
  255.   friend ComplexMatrix operator + (const ComplexMatrix& a, double s);
  256.   friend ComplexMatrix operator - (const ComplexMatrix& a, double s);
  257.   friend ComplexMatrix operator * (const ComplexMatrix& a, double s);
  258.   friend ComplexMatrix operator / (const ComplexMatrix& a, double s);
  259.  
  260. // scalar by matrix -> matrix operations
  261.  
  262.   friend ComplexMatrix operator + (double s, const ComplexMatrix& a);
  263.   friend ComplexMatrix operator - (double s, const ComplexMatrix& a);
  264.   friend ComplexMatrix operator * (double s, const ComplexMatrix& a);
  265.   friend ComplexMatrix operator / (double s, const ComplexMatrix& a);
  266.  
  267.   friend ComplexMatrix operator + (const Complex& s, const Matrix& a);
  268.   friend ComplexMatrix operator - (const Complex& s, const Matrix& a);
  269.   friend ComplexMatrix operator * (const Complex& s, const Matrix& a);
  270.   friend ComplexMatrix operator / (const Complex& s, const Matrix& a);
  271.  
  272. // matrix by diagonal matrix -> matrix operations
  273.  
  274.   friend ComplexMatrix operator + (const ComplexMatrix& a,
  275.                    const DiagMatrix& b);
  276.   friend ComplexMatrix operator - (const ComplexMatrix& a,
  277.                    const DiagMatrix& b);
  278.   friend ComplexMatrix operator * (const ComplexMatrix& a,
  279.                    const DiagMatrix& b);
  280.  
  281.   friend ComplexMatrix operator + (const ComplexMatrix& a,
  282.                    const ComplexDiagMatrix& b);
  283.   friend ComplexMatrix operator - (const ComplexMatrix& a,
  284.                    const ComplexDiagMatrix& b);
  285.   friend ComplexMatrix operator * (const ComplexMatrix& a,
  286.                    const ComplexDiagMatrix& b);
  287.  
  288. // matrix by matrix -> matrix operations
  289.  
  290.   friend ComplexMatrix operator + (const ComplexMatrix& a, const Matrix& b);
  291.   friend ComplexMatrix operator - (const ComplexMatrix& a, const Matrix& b);
  292.  
  293.   friend ComplexMatrix operator + (const Matrix& a, const ComplexMatrix& b);
  294.   friend ComplexMatrix operator - (const Matrix& a, const ComplexMatrix& b);
  295.  
  296.   friend ComplexMatrix operator * (const ComplexMatrix& a, const Matrix& b);
  297.  
  298.   friend ComplexMatrix operator * (const Matrix& a, const ComplexMatrix& b);
  299.  
  300.   friend ComplexMatrix operator * (const ComplexMatrix& a,
  301.                    const ComplexMatrix& b);
  302.  
  303.   friend ComplexMatrix product (const ComplexMatrix& a, const Matrix& b);
  304.   friend ComplexMatrix quotient (const ComplexMatrix& a, const Matrix& b);
  305.  
  306.   friend ComplexMatrix product (const Matrix& a, const ComplexMatrix& b);
  307.   friend ComplexMatrix quotient (const Matrix& a, const ComplexMatrix& b);
  308.  
  309. // other operations
  310.  
  311.   friend ComplexMatrix map (c_c_Mapper f, const ComplexMatrix& a);
  312.   void map (c_c_Mapper f);
  313.  
  314.   Matrix all (void) const;
  315.   Matrix any (void) const;
  316.  
  317.   ComplexMatrix cumprod (void) const;
  318.   ComplexMatrix cumsum (void) const;
  319.   ComplexMatrix prod (void) const;
  320.   ComplexMatrix sum (void) const;
  321.   ComplexMatrix sumsq (void) const;
  322.  
  323.   ComplexColumnVector diag (void) const;
  324.   ComplexColumnVector diag (int k) const;
  325.  
  326.   ComplexColumnVector row_min (void) const;
  327.   ComplexColumnVector row_min_loc (void) const;
  328.  
  329.   ComplexColumnVector row_max (void) const;
  330.   ComplexColumnVector row_max_loc (void) const;
  331.  
  332.   ComplexRowVector column_min (void) const;
  333.   ComplexRowVector column_min_loc (void) const;
  334.  
  335.   ComplexRowVector column_max (void) const;
  336.   ComplexRowVector column_max_loc (void) const;
  337.  
  338. // i/o
  339.  
  340.   friend ostream& operator << (ostream& os, const ComplexMatrix& a);
  341.   friend istream& operator >> (istream& is, ComplexMatrix& a);
  342.  
  343. #define KLUDGE_MATRICES
  344. #define TYPE Complex
  345. #define KL_MAT_TYPE ComplexMatrix
  346. #include "mx-kludge.h"
  347. #undef KLUDGE_MATRICES
  348. #undef TYPE
  349. #undef KL_MAT_TYPE
  350.  
  351. private:
  352.  
  353.   ComplexMatrix (Complex *d, int r, int c) : Array2<Complex> (d, r, c) { }
  354. };
  355.  
  356. } // extern "C++"
  357.  
  358. #endif
  359.  
  360. /*
  361. ;;; Local Variables: ***
  362. ;;; mode: C++ ***
  363. ;;; page-delimiter: "^/\\*" ***
  364. ;;; End: ***
  365. */
  366.