458
|
1 /* |
|
2 |
1882
|
3 Copyright (C) 1996 John W. Eaton |
458
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
458
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_Matrix_int_h) |
|
24 #define octave_Matrix_int_h 1 |
|
25 |
1296
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
1989
|
30 #include "MArray2.h" |
|
31 #include "MDiagArray2.h" |
458
|
32 |
|
33 #include "mx-defs.h" |
|
34 |
2317
|
35 #include "data-conv.h" |
|
36 #include "mach-info.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) { } |
2349
|
58 Matrix (const RowVector& rv); |
|
59 Matrix (const ColumnVector& cv); |
1989
|
60 // Matrix (const MDiagArray2<double>& a) : MArray2<double> (a) { } |
458
|
61 Matrix (const DiagMatrix& a); |
|
62 |
1574
|
63 Matrix (const charMatrix& a); |
|
64 |
458
|
65 Matrix& operator = (const Matrix& a) |
|
66 { |
1214
|
67 MArray2<double>::operator = (a); |
458
|
68 return *this; |
|
69 } |
|
70 |
2385
|
71 bool operator == (const Matrix& a) const; |
|
72 bool operator != (const Matrix& a) const; |
458
|
73 |
1359
|
74 // destructive insert/delete/reorder operations |
458
|
75 |
|
76 Matrix& insert (const Matrix& a, int r, int c); |
|
77 Matrix& insert (const RowVector& a, int r, int c); |
|
78 Matrix& insert (const ColumnVector& a, int r, int c); |
|
79 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
80 |
|
81 Matrix& fill (double val); |
|
82 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
83 |
|
84 Matrix append (const Matrix& a) const; |
|
85 Matrix append (const RowVector& a) const; |
|
86 Matrix append (const ColumnVector& a) const; |
|
87 Matrix append (const DiagMatrix& a) const; |
|
88 |
|
89 Matrix stack (const Matrix& a) const; |
|
90 Matrix stack (const RowVector& a) const; |
|
91 Matrix stack (const ColumnVector& a) const; |
|
92 Matrix stack (const DiagMatrix& a) const; |
|
93 |
|
94 Matrix transpose (void) const; |
|
95 |
1205
|
96 friend Matrix real (const ComplexMatrix& a); |
|
97 friend Matrix imag (const ComplexMatrix& a); |
|
98 |
1359
|
99 // resize is the destructive equivalent for this one |
458
|
100 |
|
101 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
102 |
1359
|
103 // extract row or column i. |
458
|
104 |
|
105 RowVector row (int i) const; |
|
106 RowVector row (char *s) const; |
|
107 |
|
108 ColumnVector column (int i) const; |
|
109 ColumnVector column (char *s) const; |
|
110 |
|
111 Matrix inverse (void) const; |
|
112 Matrix inverse (int& info) const; |
1656
|
113 Matrix inverse (int& info, double& rcond, int force = 0) const; |
458
|
114 |
740
|
115 Matrix pseudo_inverse (double tol = 0.0); |
|
116 |
458
|
117 ComplexMatrix fourier (void) const; |
|
118 ComplexMatrix ifourier (void) const; |
|
119 |
677
|
120 ComplexMatrix fourier2d (void) const; |
|
121 ComplexMatrix ifourier2d (void) const; |
|
122 |
458
|
123 DET determinant (void) const; |
|
124 DET determinant (int& info) const; |
|
125 DET determinant (int& info, double& rcond) const; |
|
126 |
|
127 Matrix solve (const Matrix& b) const; |
|
128 Matrix solve (const Matrix& b, int& info) const; |
|
129 Matrix solve (const Matrix& b, int& info, double& rcond) const; |
|
130 |
|
131 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
132 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
133 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
|
134 |
|
135 ColumnVector solve (const ColumnVector& b) const; |
|
136 ColumnVector solve (const ColumnVector& b, int& info) const; |
|
137 ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const; |
|
138 |
|
139 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
|
140 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; |
|
141 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
142 double& rcond) const; |
|
143 |
|
144 Matrix lssolve (const Matrix& b) const; |
|
145 Matrix lssolve (const Matrix& b, int& info) const; |
|
146 Matrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
147 |
|
148 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
149 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
150 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
151 int& rank) const; |
|
152 |
|
153 ColumnVector lssolve (const ColumnVector& b) const; |
|
154 ColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
155 ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const; |
|
156 |
|
157 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
158 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
159 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
160 int& rank) const; |
|
161 |
1819
|
162 Matrix expm (void) const; |
|
163 |
458
|
164 Matrix& operator += (const Matrix& a); |
|
165 Matrix& operator -= (const Matrix& a); |
|
166 |
|
167 Matrix& operator += (const DiagMatrix& a); |
|
168 Matrix& operator -= (const DiagMatrix& a); |
|
169 |
1359
|
170 // unary operations |
458
|
171 |
|
172 Matrix operator ! (void) const; |
|
173 |
1359
|
174 // column vector by row vector -> matrix operations |
458
|
175 |
2385
|
176 friend Matrix operator * (const ColumnVector& a, const RowVector& b); |
458
|
177 |
1359
|
178 // diagonal matrix by scalar -> matrix operations |
458
|
179 |
1205
|
180 friend Matrix operator + (const DiagMatrix& a, double s); |
|
181 friend Matrix operator - (const DiagMatrix& a, double s); |
458
|
182 |
1359
|
183 // scalar by diagonal matrix -> matrix operations |
458
|
184 |
1205
|
185 friend Matrix operator + (double s, const DiagMatrix& a); |
|
186 friend Matrix operator - (double s, const DiagMatrix& a); |
458
|
187 |
1359
|
188 // matrix by diagonal matrix -> matrix operations |
458
|
189 |
|
190 friend Matrix operator + (const Matrix& a, const DiagMatrix& b); |
|
191 friend Matrix operator - (const Matrix& a, const DiagMatrix& b); |
|
192 friend Matrix operator * (const Matrix& a, const DiagMatrix& b); |
|
193 |
1359
|
194 // diagonal matrix by matrix -> matrix operations |
1205
|
195 |
|
196 friend Matrix operator + (const DiagMatrix& a, const Matrix& b); |
|
197 friend Matrix operator - (const DiagMatrix& a, const Matrix& b); |
|
198 friend Matrix operator * (const DiagMatrix& a, const Matrix& b); |
458
|
199 |
1359
|
200 // matrix by matrix -> matrix operations |
458
|
201 |
|
202 friend Matrix operator * (const Matrix& a, const Matrix& b); |
|
203 |
1359
|
204 // other operations |
458
|
205 |
2676
|
206 Matrix map (d_d_Mapper f) const; |
|
207 |
|
208 Matrix& apply (d_d_Mapper f); |
458
|
209 |
2385
|
210 bool any_element_is_negative (void) const; |
|
211 bool any_element_is_inf_or_nan (void) const; |
|
212 bool all_elements_are_int_or_inf_or_nan (void) const; |
|
213 bool all_integers (double& max_val, double& min_val) const; |
|
214 bool too_large_for_float (void) const; |
1963
|
215 |
458
|
216 Matrix all (void) const; |
|
217 Matrix any (void) const; |
|
218 |
|
219 Matrix cumprod (void) const; |
|
220 Matrix cumsum (void) const; |
|
221 Matrix prod (void) const; |
|
222 Matrix sum (void) const; |
|
223 Matrix sumsq (void) const; |
2385
|
224 Matrix abs (void) const; |
458
|
225 |
|
226 ColumnVector diag (void) const; |
|
227 ColumnVector diag (int k) const; |
|
228 |
|
229 ColumnVector row_min (void) const; |
2354
|
230 ColumnVector row_max (void) const; |
458
|
231 |
2354
|
232 ColumnVector row_min (Array<int>& index) const; |
|
233 ColumnVector row_max (Array<int>& index) const; |
458
|
234 |
|
235 RowVector column_min (void) const; |
2354
|
236 RowVector column_max (void) const; |
458
|
237 |
2354
|
238 RowVector column_min (Array<int>& index) const; |
|
239 RowVector column_max (Array<int>& index) const; |
458
|
240 |
1359
|
241 // i/o |
458
|
242 |
|
243 friend ostream& operator << (ostream& os, const Matrix& a); |
|
244 friend istream& operator >> (istream& is, Matrix& a); |
|
245 |
2317
|
246 int read (istream& is, int nr, int nc, oct_data_conv::data_type dt, |
|
247 int skip, oct_mach_info::float_format flt_fmt); |
|
248 |
|
249 int write (ostream& os, oct_data_conv::data_type dt, int skip, |
|
250 oct_mach_info::float_format flt_fmt); |
458
|
251 |
|
252 private: |
|
253 |
1214
|
254 Matrix (double *d, int r, int c) : MArray2<double> (d, r, c) { } |
458
|
255 }; |
|
256 |
1959
|
257 extern Matrix Givens (double, double); |
1819
|
258 |
1959
|
259 extern Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&); |
|
260 |
|
261 extern ComplexColumnVector Qzval (const Matrix& a, const Matrix& b); |
1819
|
262 |
458
|
263 #endif |
|
264 |
|
265 /* |
|
266 ;;; Local Variables: *** |
|
267 ;;; mode: C++ *** |
|
268 ;;; End: *** |
|
269 */ |