458
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
2828
|
63 Matrix (const boolMatrix& a); |
1574
|
64 Matrix (const charMatrix& a); |
|
65 |
458
|
66 Matrix& operator = (const Matrix& a) |
|
67 { |
1214
|
68 MArray2<double>::operator = (a); |
458
|
69 return *this; |
|
70 } |
|
71 |
2385
|
72 bool operator == (const Matrix& a) const; |
|
73 bool operator != (const Matrix& a) const; |
458
|
74 |
1359
|
75 // destructive insert/delete/reorder operations |
458
|
76 |
|
77 Matrix& insert (const Matrix& a, int r, int c); |
|
78 Matrix& insert (const RowVector& a, int r, int c); |
|
79 Matrix& insert (const ColumnVector& a, int r, int c); |
|
80 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
81 |
|
82 Matrix& fill (double val); |
|
83 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
84 |
|
85 Matrix append (const Matrix& a) const; |
|
86 Matrix append (const RowVector& a) const; |
|
87 Matrix append (const ColumnVector& a) const; |
|
88 Matrix append (const DiagMatrix& a) const; |
|
89 |
|
90 Matrix stack (const Matrix& a) const; |
|
91 Matrix stack (const RowVector& a) const; |
|
92 Matrix stack (const ColumnVector& a) const; |
|
93 Matrix stack (const DiagMatrix& a) const; |
|
94 |
|
95 Matrix transpose (void) const; |
|
96 |
1205
|
97 friend Matrix real (const ComplexMatrix& a); |
|
98 friend Matrix imag (const ComplexMatrix& a); |
|
99 |
1359
|
100 // resize is the destructive equivalent for this one |
458
|
101 |
|
102 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
103 |
1359
|
104 // extract row or column i. |
458
|
105 |
|
106 RowVector row (int i) const; |
|
107 RowVector row (char *s) const; |
|
108 |
|
109 ColumnVector column (int i) const; |
|
110 ColumnVector column (char *s) const; |
|
111 |
|
112 Matrix inverse (void) const; |
|
113 Matrix inverse (int& info) const; |
1656
|
114 Matrix inverse (int& info, double& rcond, int force = 0) const; |
458
|
115 |
740
|
116 Matrix pseudo_inverse (double tol = 0.0); |
|
117 |
458
|
118 ComplexMatrix fourier (void) const; |
|
119 ComplexMatrix ifourier (void) const; |
|
120 |
677
|
121 ComplexMatrix fourier2d (void) const; |
|
122 ComplexMatrix ifourier2d (void) const; |
|
123 |
458
|
124 DET determinant (void) const; |
|
125 DET determinant (int& info) const; |
|
126 DET determinant (int& info, double& rcond) const; |
|
127 |
|
128 Matrix solve (const Matrix& b) const; |
|
129 Matrix solve (const Matrix& b, int& info) const; |
|
130 Matrix solve (const Matrix& b, int& info, double& rcond) const; |
|
131 |
|
132 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
133 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
134 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
|
135 |
|
136 ColumnVector solve (const ColumnVector& b) const; |
|
137 ColumnVector solve (const ColumnVector& b, int& info) const; |
|
138 ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const; |
|
139 |
|
140 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
|
141 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; |
|
142 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
143 double& rcond) const; |
|
144 |
|
145 Matrix lssolve (const Matrix& b) const; |
|
146 Matrix lssolve (const Matrix& b, int& info) const; |
|
147 Matrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
148 |
|
149 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
150 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
151 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
152 int& rank) const; |
|
153 |
|
154 ColumnVector lssolve (const ColumnVector& b) const; |
|
155 ColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
156 ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const; |
|
157 |
|
158 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
159 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
160 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
161 int& rank) const; |
|
162 |
1819
|
163 Matrix expm (void) const; |
|
164 |
458
|
165 Matrix& operator += (const Matrix& a); |
|
166 Matrix& operator -= (const Matrix& a); |
|
167 |
|
168 Matrix& operator += (const DiagMatrix& a); |
|
169 Matrix& operator -= (const DiagMatrix& a); |
|
170 |
1359
|
171 // unary operations |
458
|
172 |
|
173 Matrix operator ! (void) const; |
|
174 |
1359
|
175 // column vector by row vector -> matrix operations |
458
|
176 |
2385
|
177 friend Matrix operator * (const ColumnVector& a, const RowVector& b); |
458
|
178 |
1359
|
179 // other operations |
458
|
180 |
2676
|
181 Matrix map (d_d_Mapper f) const; |
|
182 |
|
183 Matrix& apply (d_d_Mapper f); |
458
|
184 |
2385
|
185 bool any_element_is_negative (void) const; |
|
186 bool any_element_is_inf_or_nan (void) const; |
|
187 bool all_elements_are_int_or_inf_or_nan (void) const; |
|
188 bool all_integers (double& max_val, double& min_val) const; |
|
189 bool too_large_for_float (void) const; |
1963
|
190 |
2832
|
191 boolMatrix all (void) const; |
|
192 boolMatrix any (void) const; |
458
|
193 |
|
194 Matrix cumprod (void) const; |
|
195 Matrix cumsum (void) const; |
|
196 Matrix prod (void) const; |
|
197 Matrix sum (void) const; |
|
198 Matrix sumsq (void) const; |
2385
|
199 Matrix abs (void) const; |
458
|
200 |
|
201 ColumnVector diag (void) const; |
|
202 ColumnVector diag (int k) const; |
|
203 |
|
204 ColumnVector row_min (void) const; |
2354
|
205 ColumnVector row_max (void) const; |
458
|
206 |
2354
|
207 ColumnVector row_min (Array<int>& index) const; |
|
208 ColumnVector row_max (Array<int>& index) const; |
458
|
209 |
|
210 RowVector column_min (void) const; |
2354
|
211 RowVector column_max (void) const; |
458
|
212 |
2354
|
213 RowVector column_min (Array<int>& index) const; |
|
214 RowVector column_max (Array<int>& index) const; |
458
|
215 |
1359
|
216 // i/o |
458
|
217 |
|
218 friend ostream& operator << (ostream& os, const Matrix& a); |
|
219 friend istream& operator >> (istream& is, Matrix& a); |
|
220 |
2317
|
221 int read (istream& is, int nr, int nc, oct_data_conv::data_type dt, |
|
222 int skip, oct_mach_info::float_format flt_fmt); |
|
223 |
|
224 int write (ostream& os, oct_data_conv::data_type dt, int skip, |
|
225 oct_mach_info::float_format flt_fmt); |
458
|
226 |
|
227 private: |
|
228 |
1214
|
229 Matrix (double *d, int r, int c) : MArray2<double> (d, r, c) { } |
458
|
230 }; |
|
231 |
1959
|
232 extern Matrix Givens (double, double); |
1819
|
233 |
1959
|
234 extern Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&); |
|
235 |
|
236 extern ComplexColumnVector Qzval (const Matrix& a, const Matrix& b); |
1819
|
237 |
2828
|
238 extern Matrix operator * (const Matrix& a, const Matrix& b); |
|
239 |
458
|
240 #endif |
|
241 |
|
242 /* |
|
243 ;;; Local Variables: *** |
|
244 ;;; mode: C++ *** |
|
245 ;;; End: *** |
|
246 */ |