458
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
458
|
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 |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
458
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_Matrix_int_h) |
|
25 #define octave_Matrix_int_h 1 |
|
26 |
1296
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
532
|
31 // For FILE... |
1366
|
32 #include <cstdio> |
532
|
33 |
1214
|
34 #include "MArray.h" |
458
|
35 |
|
36 #include "mx-defs.h" |
|
37 |
1214
|
38 class Matrix : public MArray2<double> |
458
|
39 { |
1205
|
40 friend class ComplexMatrix; |
532
|
41 friend class AEPBAL; |
|
42 friend class CHOL; |
|
43 friend class GEPBAL; |
|
44 friend class HESS; |
458
|
45 friend class LU; |
532
|
46 friend class QR; |
536
|
47 friend class QRP; |
532
|
48 friend class SCHUR; |
458
|
49 friend class SVD; |
|
50 |
|
51 public: |
|
52 |
1214
|
53 Matrix (void) : MArray2<double> () { } |
|
54 Matrix (int r, int c) : MArray2<double> (r, c) { } |
|
55 Matrix (int r, int c, double val) : MArray2<double> (r, c, val) { } |
|
56 Matrix (const MArray2<double>& a) : MArray2<double> (a) { } |
|
57 Matrix (const Matrix& a) : MArray2<double> (a) { } |
|
58 Matrix (const MDiagArray<double>& a) : MArray2<double> (a) { } |
458
|
59 Matrix (const DiagMatrix& a); |
|
60 |
1574
|
61 Matrix (const charMatrix& a); |
|
62 |
458
|
63 Matrix& operator = (const Matrix& a) |
|
64 { |
1214
|
65 MArray2<double>::operator = (a); |
458
|
66 return *this; |
|
67 } |
|
68 |
|
69 int operator == (const Matrix& a) const; |
|
70 int operator != (const Matrix& a) const; |
|
71 |
1359
|
72 // destructive insert/delete/reorder operations |
458
|
73 |
|
74 Matrix& insert (const Matrix& a, int r, int c); |
|
75 Matrix& insert (const RowVector& a, int r, int c); |
|
76 Matrix& insert (const ColumnVector& a, int r, int c); |
|
77 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
78 |
|
79 Matrix& fill (double val); |
|
80 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
81 |
|
82 Matrix append (const Matrix& a) const; |
|
83 Matrix append (const RowVector& a) const; |
|
84 Matrix append (const ColumnVector& a) const; |
|
85 Matrix append (const DiagMatrix& a) const; |
|
86 |
|
87 Matrix stack (const Matrix& a) const; |
|
88 Matrix stack (const RowVector& a) const; |
|
89 Matrix stack (const ColumnVector& a) const; |
|
90 Matrix stack (const DiagMatrix& a) const; |
|
91 |
|
92 Matrix transpose (void) const; |
|
93 |
1205
|
94 friend Matrix real (const ComplexMatrix& a); |
|
95 friend Matrix imag (const ComplexMatrix& a); |
|
96 |
1359
|
97 // resize is the destructive equivalent for this one |
458
|
98 |
|
99 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
100 |
1359
|
101 // extract row or column i. |
458
|
102 |
|
103 RowVector row (int i) const; |
|
104 RowVector row (char *s) const; |
|
105 |
|
106 ColumnVector column (int i) const; |
|
107 ColumnVector column (char *s) const; |
|
108 |
|
109 Matrix inverse (void) const; |
|
110 Matrix inverse (int& info) const; |
|
111 Matrix inverse (int& info, double& rcond) const; |
|
112 |
740
|
113 Matrix pseudo_inverse (double tol = 0.0); |
|
114 |
458
|
115 ComplexMatrix fourier (void) const; |
|
116 ComplexMatrix ifourier (void) const; |
|
117 |
677
|
118 ComplexMatrix fourier2d (void) const; |
|
119 ComplexMatrix ifourier2d (void) const; |
|
120 |
458
|
121 DET determinant (void) const; |
|
122 DET determinant (int& info) const; |
|
123 DET determinant (int& info, double& rcond) const; |
|
124 |
|
125 Matrix solve (const Matrix& b) const; |
|
126 Matrix solve (const Matrix& b, int& info) const; |
|
127 Matrix solve (const Matrix& b, int& info, double& rcond) const; |
|
128 |
|
129 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
130 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
131 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
|
132 |
|
133 ColumnVector solve (const ColumnVector& b) const; |
|
134 ColumnVector solve (const ColumnVector& b, int& info) const; |
|
135 ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const; |
|
136 |
|
137 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
|
138 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; |
|
139 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
140 double& rcond) const; |
|
141 |
|
142 Matrix lssolve (const Matrix& b) const; |
|
143 Matrix lssolve (const Matrix& b, int& info) const; |
|
144 Matrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
145 |
|
146 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
147 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
148 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
149 int& rank) const; |
|
150 |
|
151 ColumnVector lssolve (const ColumnVector& b) const; |
|
152 ColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
153 ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const; |
|
154 |
|
155 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
156 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
157 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
158 int& rank) const; |
|
159 |
|
160 Matrix& operator += (const Matrix& a); |
|
161 Matrix& operator -= (const Matrix& a); |
|
162 |
|
163 Matrix& operator += (const DiagMatrix& a); |
|
164 Matrix& operator -= (const DiagMatrix& a); |
|
165 |
1359
|
166 // unary operations |
458
|
167 |
|
168 Matrix operator ! (void) const; |
|
169 |
1359
|
170 // column vector by row vector -> matrix operations |
458
|
171 |
1205
|
172 friend Matrix operator * (const ColumnVector& a, const RowVector& a); |
458
|
173 |
1359
|
174 // diagonal matrix by scalar -> matrix operations |
458
|
175 |
1205
|
176 friend Matrix operator + (const DiagMatrix& a, double s); |
|
177 friend Matrix operator - (const DiagMatrix& a, double s); |
458
|
178 |
1359
|
179 // scalar by diagonal matrix -> matrix operations |
458
|
180 |
1205
|
181 friend Matrix operator + (double s, const DiagMatrix& a); |
|
182 friend Matrix operator - (double s, const DiagMatrix& a); |
458
|
183 |
1359
|
184 // matrix by diagonal matrix -> matrix operations |
458
|
185 |
|
186 friend Matrix operator + (const Matrix& a, const DiagMatrix& b); |
|
187 friend Matrix operator - (const Matrix& a, const DiagMatrix& b); |
|
188 friend Matrix operator * (const Matrix& a, const DiagMatrix& b); |
|
189 |
1359
|
190 // diagonal matrix by matrix -> matrix operations |
1205
|
191 |
|
192 friend Matrix operator + (const DiagMatrix& a, const Matrix& b); |
|
193 friend Matrix operator - (const DiagMatrix& a, const Matrix& b); |
|
194 friend Matrix operator * (const DiagMatrix& a, const Matrix& b); |
458
|
195 |
1359
|
196 // matrix by matrix -> matrix operations |
458
|
197 |
|
198 friend Matrix operator * (const Matrix& a, const Matrix& b); |
|
199 |
1359
|
200 // other operations |
458
|
201 |
|
202 friend Matrix map (d_d_Mapper f, const Matrix& a); |
1205
|
203 friend Matrix map (d_c_Mapper f, const ComplexMatrix& a); |
458
|
204 void map (d_d_Mapper f); |
|
205 |
|
206 Matrix all (void) const; |
|
207 Matrix any (void) const; |
|
208 |
|
209 Matrix cumprod (void) const; |
|
210 Matrix cumsum (void) const; |
|
211 Matrix prod (void) const; |
|
212 Matrix sum (void) const; |
|
213 Matrix sumsq (void) const; |
|
214 |
|
215 ColumnVector diag (void) const; |
|
216 ColumnVector diag (int k) const; |
|
217 |
|
218 ColumnVector row_min (void) const; |
|
219 ColumnVector row_min_loc (void) const; |
|
220 |
|
221 ColumnVector row_max (void) const; |
|
222 ColumnVector row_max_loc (void) const; |
|
223 |
|
224 RowVector column_min (void) const; |
|
225 RowVector column_min_loc (void) const; |
|
226 |
|
227 RowVector column_max (void) const; |
|
228 RowVector column_max_loc (void) const; |
|
229 |
1359
|
230 // i/o |
458
|
231 |
|
232 friend ostream& operator << (ostream& os, const Matrix& a); |
|
233 friend istream& operator >> (istream& is, Matrix& a); |
|
234 |
1365
|
235 int read (FILE *fptr, const char *type); |
|
236 int write (FILE *fptr, const char *type); |
458
|
237 |
|
238 private: |
|
239 |
1214
|
240 Matrix (double *d, int r, int c) : MArray2<double> (d, r, c) { } |
458
|
241 }; |
|
242 |
|
243 #endif |
|
244 |
|
245 /* |
|
246 ;;; Local Variables: *** |
|
247 ;;; mode: C++ *** |
|
248 ;;; page-delimiter: "^/\\*" *** |
|
249 ;;; End: *** |
|
250 */ |