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