home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / octave-1.1.1-src.lha / octave-1.1.1 / liboctave / dDiagMatrix.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-04  |  5.5 KB  |  187 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_DiagMatrix_h)
  25. #define octave_DiagMatrix_h 1
  26.  
  27. #include "Array.h"
  28.  
  29. #include "dRowVector.h"
  30. #include "dColVector.h"
  31.  
  32. #include "mx-defs.h"
  33.  
  34. extern "C++" {
  35.  
  36. class DiagMatrix : public DiagArray<double>
  37. {
  38. friend class SVD;
  39. friend class ComplexSVD;
  40. friend class ComplexDiagMatrix;
  41.  
  42. public:
  43.  
  44.   DiagMatrix (void) : DiagArray<double> () { }
  45.   DiagMatrix (int n) : DiagArray<double> (n) { }
  46.   DiagMatrix (int n, double val) : DiagArray<double> (n, val) { }
  47.   DiagMatrix (int r, int c) : DiagArray<double> (r, c) { }
  48.   DiagMatrix (int r, int c, double val) : DiagArray<double> (r, c, val) { }
  49.   DiagMatrix (const RowVector& a) : DiagArray<double> (a) { }
  50.   DiagMatrix (const ColumnVector& a) : DiagArray<double> (a) { }
  51.   DiagMatrix (const DiagArray<double>& a) : DiagArray<double> (a) { }
  52.   DiagMatrix (const DiagMatrix& a) : DiagArray<double> (a) { }
  53. //  DiagMatrix (double a) : DiagArray<double> (1, a) { }
  54.  
  55.   DiagMatrix& operator = (const DiagMatrix& a)
  56.     {
  57.       DiagArray<double>::operator = (a);
  58.       return *this;
  59.     }
  60.  
  61. //  operator DiagArray<double>& () const { return *this; }
  62.  
  63.   int operator == (const DiagMatrix& a) const;
  64.   int operator != (const DiagMatrix& a) const;
  65.  
  66.   DiagMatrix& fill (double val);
  67.   DiagMatrix& fill (double val, int beg, int end);
  68.   DiagMatrix& fill (const ColumnVector& a);
  69.   DiagMatrix& fill (const RowVector& a);
  70.   DiagMatrix& fill (const ColumnVector& a, int beg);
  71.   DiagMatrix& fill (const RowVector& a, int beg);
  72.  
  73.   DiagMatrix transpose (void) const;
  74.  
  75. // resize is the destructive analog for this one
  76.  
  77.   Matrix extract (int r1, int c1, int r2, int c2) const;
  78.  
  79. // extract row or column i.
  80.  
  81.   RowVector row (int i) const;
  82.   RowVector row (char *s) const;
  83.  
  84.   ColumnVector column (int i) const;
  85.   ColumnVector column (char *s) const;
  86.  
  87.   DiagMatrix inverse (void) const;
  88.   DiagMatrix inverse (int& info) const;
  89.  
  90. // diagonal matrix by diagonal matrix -> diagonal matrix operations
  91.  
  92.   DiagMatrix& operator += (const DiagMatrix& a);
  93.   DiagMatrix& operator -= (const DiagMatrix& a);
  94.  
  95. // diagonal matrix by scalar -> matrix operations
  96.  
  97.   friend Matrix operator + (const DiagMatrix& a, double s);
  98.   friend Matrix operator - (const DiagMatrix& a, double s);
  99.  
  100.   friend ComplexMatrix operator + (const DiagMatrix& a, const Complex& s);
  101.   friend ComplexMatrix operator - (const DiagMatrix& a, const Complex& s);
  102.  
  103. // diagonal matrix by scalar -> diagonal matrix operations
  104.  
  105.   friend ComplexDiagMatrix operator * (const DiagMatrix& a, const Complex& s);
  106.   friend ComplexDiagMatrix operator / (const DiagMatrix& a, const Complex& s);
  107.  
  108. // scalar by diagonal matrix -> matrix operations
  109.  
  110.   friend Matrix operator + (double s, const DiagMatrix& a);
  111.   friend Matrix operator - (double s, const DiagMatrix& a);
  112.  
  113.   friend ComplexMatrix operator + (const Complex& s, const DiagMatrix& a);
  114.   friend ComplexMatrix operator - (const Complex& s, const DiagMatrix& a);
  115.  
  116. // scalar by diagonal matrix -> diagonal matrix operations
  117.  
  118.   friend ComplexDiagMatrix operator * (const Complex& s, const DiagMatrix& a);
  119.  
  120. // diagonal matrix by column vector -> column vector operations
  121.  
  122.   friend ColumnVector operator * (const DiagMatrix& a, const ColumnVector& b);
  123.  
  124.   friend ComplexColumnVector operator * (const DiagMatrix& a,
  125.                      const ComplexColumnVector& b);
  126.  
  127. // diagonal matrix by diagonal matrix -> diagonal matrix operations
  128.  
  129.   friend DiagMatrix operator * (const DiagMatrix& a,
  130.                 const DiagMatrix& b);
  131.  
  132.   friend ComplexDiagMatrix operator + (const DiagMatrix& a,
  133.                        const ComplexDiagMatrix& b);
  134.   friend ComplexDiagMatrix operator - (const DiagMatrix& a,
  135.                        const ComplexDiagMatrix& b);
  136.   friend ComplexDiagMatrix operator * (const DiagMatrix& a,
  137.                        const ComplexDiagMatrix& b);
  138.  
  139.   friend ComplexDiagMatrix product (const DiagMatrix& a,
  140.                     const ComplexDiagMatrix& b);
  141.  
  142. // diagonal matrix by matrix -> matrix operations
  143.  
  144.   friend Matrix operator + (const DiagMatrix& a, const Matrix& b);
  145.   friend Matrix operator - (const DiagMatrix& a, const Matrix& b);
  146.   friend Matrix operator * (const DiagMatrix& a, const Matrix& b);
  147.  
  148.   friend ComplexMatrix operator + (const DiagMatrix& a,
  149.                    const ComplexMatrix& b);
  150.   friend ComplexMatrix operator - (const DiagMatrix& a,
  151.                    const ComplexMatrix& b);
  152.   friend ComplexMatrix operator * (const DiagMatrix& a,
  153.                    const ComplexMatrix& b);
  154.  
  155. // other operations
  156.  
  157.   ColumnVector diag (void) const;
  158.   ColumnVector diag (int k) const;
  159.  
  160. // i/o
  161.  
  162.   friend ostream& operator << (ostream& os, const DiagMatrix& a);
  163.  
  164. #define KLUDGE_DIAG_MATRICES
  165. #define TYPE double
  166. #define KL_DMAT_TYPE DiagMatrix
  167. #include "mx-kludge.h"
  168. #undef KLUDGE_DIAG_MATRICES
  169. #undef TYPE
  170. #undef KL_DMAT_TYPE
  171.  
  172. private:
  173.  
  174.   DiagMatrix (double *d, int nr, int nc) : DiagArray<double> (d, nr, nc) { }
  175. };
  176.  
  177. } // extern "C++"
  178.  
  179. #endif
  180.  
  181. /*
  182. ;;; Local Variables: ***
  183. ;;; mode: C++ ***
  184. ;;; page-delimiter: "^/\\*" ***
  185. ;;; End: ***
  186. */
  187.