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 / dMatrix.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-14  |  8.1 KB  |  271 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_Matrix_int_h)
  25. #define octave_Matrix_int_h 1
  26.  
  27. // For FILE...
  28. #include <stdio.h>
  29.  
  30. #include "Array.h"
  31.  
  32. #include "mx-defs.h"
  33.  
  34. extern "C++" {
  35.  
  36. class Matrix : public Array2<double>
  37. {
  38. friend class ColumnVector;
  39. friend class AEPBAL;
  40. friend class CHOL;
  41. friend class GEPBAL;
  42. friend class HESS;
  43. friend class LU;
  44. friend class QR;
  45. friend class QRP;
  46. friend class SCHUR;
  47. friend class SVD;
  48. friend class ComplexMatrix;
  49.  
  50. public:
  51.  
  52.   Matrix (void) : Array2<double> () { }
  53.   Matrix (int r, int c) : Array2<double> (r, c) { }
  54.   Matrix (int r, int c, double val) : Array2<double> (r, c, val) { }
  55.   Matrix (const Array2<double>& a) : Array2<double> (a) { }
  56.   Matrix (const Matrix& a) : Array2<double> (a) { }
  57.   Matrix (const DiagArray<double>& a) : Array2<double> (a) { }
  58.   Matrix (const DiagMatrix& a);
  59. //  Matrix (double a) : Array2<double> (1, 1, a) { }
  60.  
  61.   Matrix& operator = (const Matrix& a)
  62.     {
  63.       Array2<double>::operator = (a);
  64.       return *this;
  65.     }
  66.  
  67.   int operator == (const Matrix& a) const;
  68.   int operator != (const Matrix& a) const;
  69.  
  70. // destructive insert/delete/reorder operations
  71.  
  72.   Matrix& insert (const Matrix& a, int r, int c);
  73.   Matrix& insert (const RowVector& a, int r, int c);
  74.   Matrix& insert (const ColumnVector& a, int r, int c);
  75.   Matrix& insert (const DiagMatrix& a, int r, int c);
  76.  
  77.   Matrix& fill (double val);
  78.   Matrix& fill (double val, int r1, int c1, int r2, int c2);
  79.  
  80.   Matrix append (const Matrix& a) const;
  81.   Matrix append (const RowVector& a) const;
  82.   Matrix append (const ColumnVector& a) const;
  83.   Matrix append (const DiagMatrix& a) const;
  84.  
  85.   Matrix stack (const Matrix& a) const;
  86.   Matrix stack (const RowVector& a) const;
  87.   Matrix stack (const ColumnVector& a) const;
  88.   Matrix stack (const DiagMatrix& a) const;
  89.  
  90.   Matrix transpose (void) const;
  91.  
  92. // resize is the destructive equivalent for this one
  93.  
  94.   Matrix extract (int r1, int c1, int r2, int c2) const;
  95.  
  96. // extract row or column i.
  97.  
  98.   RowVector row (int i) const;
  99.   RowVector row (char *s) const;
  100.  
  101.   ColumnVector column (int i) const;
  102.   ColumnVector column (char *s) const;
  103.  
  104.   Matrix inverse (void) const;
  105.   Matrix inverse (int& info) const;
  106.   Matrix inverse (int& info, double& rcond) const;
  107.  
  108.   Matrix pseudo_inverse (double tol = 0.0);
  109.  
  110.   ComplexMatrix fourier (void) const;
  111.   ComplexMatrix ifourier (void) const;
  112.  
  113.   ComplexMatrix fourier2d (void) const;
  114.   ComplexMatrix ifourier2d (void) const;
  115.  
  116.   DET determinant (void) const;
  117.   DET determinant (int& info) const;
  118.   DET determinant (int& info, double& rcond) const;
  119.  
  120.   Matrix solve (const Matrix& b) const;
  121.   Matrix solve (const Matrix& b, int& info) const;
  122.   Matrix solve (const Matrix& b, int& info, double& rcond) const;
  123.  
  124.   ComplexMatrix solve (const ComplexMatrix& b) const;
  125.   ComplexMatrix solve (const ComplexMatrix& b, int& info) const;
  126.   ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const;
  127.  
  128.   ColumnVector solve (const ColumnVector& b) const;
  129.   ColumnVector solve (const ColumnVector& b, int& info) const;
  130.   ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const;
  131.  
  132.   ComplexColumnVector solve (const ComplexColumnVector& b) const;
  133.   ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const;
  134.   ComplexColumnVector solve (const ComplexColumnVector& b, int& info,
  135.                  double& rcond) const;
  136.  
  137.   Matrix lssolve (const Matrix& b) const;
  138.   Matrix lssolve (const Matrix& b, int& info) const;
  139.   Matrix lssolve (const Matrix& b, int& info, int& rank) const;
  140.  
  141.   ComplexMatrix lssolve (const ComplexMatrix& b) const;
  142.   ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const;
  143.   ComplexMatrix lssolve (const ComplexMatrix& b, int& info,
  144.              int& rank) const;
  145.  
  146.   ColumnVector lssolve (const ColumnVector& b) const;
  147.   ColumnVector lssolve (const ColumnVector& b, int& info) const;
  148.   ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const;
  149.  
  150.   ComplexColumnVector lssolve (const ComplexColumnVector& b) const;
  151.   ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const;
  152.   ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info,
  153.                    int& rank) const;
  154.  
  155.   Matrix& operator += (const Matrix& a);
  156.   Matrix& operator -= (const Matrix& a);
  157.  
  158.   Matrix& operator += (const DiagMatrix& a);
  159.   Matrix& operator -= (const DiagMatrix& a);
  160.  
  161. // unary operations
  162.  
  163.   Matrix operator ! (void) const;
  164.  
  165. // matrix by scalar -> matrix operations
  166.  
  167.   friend ComplexMatrix operator + (const Matrix& a, const Complex& s);
  168.   friend ComplexMatrix operator - (const Matrix& a, const Complex& s);
  169.   friend ComplexMatrix operator * (const Matrix& a, const Complex& s);
  170.   friend ComplexMatrix operator / (const Matrix& a, const Complex& s);
  171.  
  172. // scalar by matrix -> matrix operations
  173.  
  174.   friend ComplexMatrix operator + (const Complex& s, const Matrix& a);
  175.   friend ComplexMatrix operator - (const Complex& s, const Matrix& a);
  176.   friend ComplexMatrix operator * (const Complex& s, const Matrix& a);
  177.   friend ComplexMatrix operator / (const Complex& s, const Matrix& a);
  178.  
  179. // matrix by column vector -> column vector operations
  180.  
  181.   friend ColumnVector operator * (const Matrix& a, const ColumnVector& b);
  182.   friend ComplexColumnVector operator * (const Matrix& a,
  183.                      const ComplexColumnVector& b);
  184.  
  185. // matrix by diagonal matrix -> matrix operations
  186.  
  187.   friend Matrix operator + (const Matrix& a, const DiagMatrix& b);
  188.   friend Matrix operator - (const Matrix& a, const DiagMatrix& b);
  189.   friend Matrix operator * (const Matrix& a, const DiagMatrix& b);
  190.  
  191.   friend ComplexMatrix operator + (const Matrix& a,
  192.                    const ComplexDiagMatrix& b); 
  193.   friend ComplexMatrix operator - (const Matrix& a,
  194.                    const ComplexDiagMatrix& b);
  195.   friend ComplexMatrix operator * (const Matrix& a,
  196.                    const ComplexDiagMatrix& b);
  197.  
  198. // matrix by matrix -> matrix operations
  199.  
  200.   friend Matrix operator * (const Matrix& a, const Matrix& b);
  201.   friend ComplexMatrix operator * (const Matrix& a, const ComplexMatrix& b);
  202.  
  203.   friend ComplexMatrix operator + (const Matrix& a, const ComplexMatrix& b);
  204.   friend ComplexMatrix operator - (const Matrix& a, const ComplexMatrix& b);
  205.  
  206.   friend ComplexMatrix product (const Matrix& a, const ComplexMatrix& b);
  207.   friend ComplexMatrix quotient (const Matrix& a, const ComplexMatrix& b);
  208.  
  209. // other operations
  210.  
  211.   friend Matrix map (d_d_Mapper f, const Matrix& a);
  212.   void map (d_d_Mapper f);
  213.  
  214.   Matrix all (void) const;
  215.   Matrix any (void) const;
  216.  
  217.   Matrix cumprod (void) const;
  218.   Matrix cumsum (void) const;
  219.   Matrix prod (void) const;
  220.   Matrix sum (void) const;
  221.   Matrix sumsq (void) const;
  222.  
  223.   ColumnVector diag (void) const;
  224.   ColumnVector diag (int k) const;
  225.  
  226.   ColumnVector row_min (void) const;
  227.   ColumnVector row_min_loc (void) const;
  228.  
  229.   ColumnVector row_max (void) const;
  230.   ColumnVector row_max_loc (void) const;
  231.  
  232.   RowVector column_min (void) const;
  233.   RowVector column_min_loc (void) const;
  234.  
  235.   RowVector column_max (void) const;
  236.   RowVector column_max_loc (void) const;
  237.  
  238. // i/o
  239.  
  240.   friend ostream& operator << (ostream& os, const Matrix& a);
  241.   friend istream& operator >> (istream& is, Matrix& a);
  242.  
  243.   int read (FILE *fptr, char *type);
  244.   int write (FILE *fptr, char *type);
  245.  
  246. // Until templates really work with g++:
  247.  
  248. #define KLUDGE_MATRICES
  249. #define TYPE double
  250. #define KL_MAT_TYPE Matrix
  251. #include "mx-kludge.h"
  252. #undef KLUDGE_MATRICES
  253. #undef TYPE
  254. #undef KL_MAT_TYPE
  255.  
  256. private:
  257.  
  258.   Matrix (double *d, int r, int c) : Array2<double> (d, r, c) { }
  259. };
  260.  
  261. } // extern "C++"
  262.  
  263. #endif
  264.  
  265. /*
  266. ;;; Local Variables: ***
  267. ;;; mode: C++ ***
  268. ;;; page-delimiter: "^/\\*" ***
  269. ;;; End: ***
  270. */
  271.