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" |
2870
|
34 #include "mx-op-defs.h" |
458
|
35 |
2317
|
36 #include "data-conv.h" |
|
37 #include "mach-info.h" |
|
38 |
1214
|
39 class Matrix : public MArray2<double> |
458
|
40 { |
|
41 public: |
|
42 |
3480
|
43 typedef void (*solve_singularity_handler) (double rcond); |
|
44 |
1214
|
45 Matrix (void) : MArray2<double> () { } |
|
46 Matrix (int r, int c) : MArray2<double> (r, c) { } |
|
47 Matrix (int r, int c, double val) : MArray2<double> (r, c, val) { } |
|
48 Matrix (const MArray2<double>& a) : MArray2<double> (a) { } |
|
49 Matrix (const Matrix& a) : MArray2<double> (a) { } |
2349
|
50 Matrix (const RowVector& rv); |
|
51 Matrix (const ColumnVector& cv); |
1989
|
52 // Matrix (const MDiagArray2<double>& a) : MArray2<double> (a) { } |
458
|
53 Matrix (const DiagMatrix& a); |
|
54 |
2828
|
55 Matrix (const boolMatrix& a); |
1574
|
56 Matrix (const charMatrix& a); |
|
57 |
458
|
58 Matrix& operator = (const Matrix& a) |
|
59 { |
1214
|
60 MArray2<double>::operator = (a); |
458
|
61 return *this; |
|
62 } |
|
63 |
2385
|
64 bool operator == (const Matrix& a) const; |
|
65 bool operator != (const Matrix& a) const; |
458
|
66 |
3354
|
67 bool is_symmetric (void) const; |
|
68 |
1359
|
69 // destructive insert/delete/reorder operations |
458
|
70 |
|
71 Matrix& insert (const Matrix& a, int r, int c); |
|
72 Matrix& insert (const RowVector& a, int r, int c); |
|
73 Matrix& insert (const ColumnVector& a, int r, int c); |
|
74 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
75 |
|
76 Matrix& fill (double val); |
|
77 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
78 |
|
79 Matrix append (const Matrix& a) const; |
|
80 Matrix append (const RowVector& a) const; |
|
81 Matrix append (const ColumnVector& a) const; |
|
82 Matrix append (const DiagMatrix& a) const; |
|
83 |
|
84 Matrix stack (const Matrix& a) const; |
|
85 Matrix stack (const RowVector& a) const; |
|
86 Matrix stack (const ColumnVector& a) const; |
|
87 Matrix stack (const DiagMatrix& a) const; |
|
88 |
1205
|
89 friend Matrix real (const ComplexMatrix& a); |
|
90 friend Matrix imag (const ComplexMatrix& a); |
|
91 |
3225
|
92 Matrix transpose (void) const { return MArray2<double>::transpose (); } |
|
93 |
1359
|
94 // resize is the destructive equivalent for this one |
458
|
95 |
|
96 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
97 |
1359
|
98 // extract row or column i. |
458
|
99 |
|
100 RowVector row (int i) const; |
|
101 RowVector row (char *s) const; |
|
102 |
|
103 ColumnVector column (int i) const; |
|
104 ColumnVector column (char *s) const; |
|
105 |
|
106 Matrix inverse (void) const; |
|
107 Matrix inverse (int& info) const; |
1656
|
108 Matrix inverse (int& info, double& rcond, int force = 0) const; |
458
|
109 |
740
|
110 Matrix pseudo_inverse (double tol = 0.0); |
|
111 |
458
|
112 ComplexMatrix fourier (void) const; |
|
113 ComplexMatrix ifourier (void) const; |
|
114 |
677
|
115 ComplexMatrix fourier2d (void) const; |
|
116 ComplexMatrix ifourier2d (void) const; |
|
117 |
458
|
118 DET determinant (void) const; |
|
119 DET determinant (int& info) const; |
|
120 DET determinant (int& info, double& rcond) const; |
|
121 |
|
122 Matrix solve (const Matrix& b) const; |
|
123 Matrix solve (const Matrix& b, int& info) const; |
|
124 Matrix solve (const Matrix& b, int& info, double& rcond) const; |
3480
|
125 Matrix solve (const Matrix& b, int& info, double& rcond, |
|
126 solve_singularity_handler sing_handler) const; |
458
|
127 |
|
128 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
129 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
130 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
3480
|
131 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond, |
|
132 solve_singularity_handler sing_handler) const; |
458
|
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; |
3480
|
137 ColumnVector solve (const ColumnVector& b, int& info, double& rcond, |
|
138 solve_singularity_handler sing_handler) const; |
458
|
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; |
3480
|
144 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
145 double& rcond, |
|
146 solve_singularity_handler sing_handler) const; |
458
|
147 |
|
148 Matrix lssolve (const Matrix& b) const; |
|
149 Matrix lssolve (const Matrix& b, int& info) const; |
|
150 Matrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
151 |
|
152 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
153 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
154 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
155 int& rank) const; |
|
156 |
|
157 ColumnVector lssolve (const ColumnVector& b) const; |
|
158 ColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
159 ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const; |
|
160 |
|
161 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
162 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
163 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
164 int& rank) const; |
|
165 |
1819
|
166 Matrix expm (void) const; |
|
167 |
458
|
168 Matrix& operator += (const Matrix& a); |
|
169 Matrix& operator -= (const Matrix& a); |
|
170 |
|
171 Matrix& operator += (const DiagMatrix& a); |
|
172 Matrix& operator -= (const DiagMatrix& a); |
|
173 |
1359
|
174 // unary operations |
458
|
175 |
2964
|
176 boolMatrix operator ! (void) const; |
458
|
177 |
1359
|
178 // column vector by row vector -> matrix operations |
458
|
179 |
2385
|
180 friend Matrix operator * (const ColumnVector& a, const RowVector& b); |
458
|
181 |
1359
|
182 // other operations |
458
|
183 |
2676
|
184 Matrix map (d_d_Mapper f) const; |
3248
|
185 boolMatrix map (b_d_Mapper f) const; |
2676
|
186 |
|
187 Matrix& apply (d_d_Mapper f); |
458
|
188 |
2385
|
189 bool any_element_is_negative (void) const; |
|
190 bool any_element_is_inf_or_nan (void) const; |
|
191 bool all_elements_are_int_or_inf_or_nan (void) const; |
|
192 bool all_integers (double& max_val, double& min_val) const; |
|
193 bool too_large_for_float (void) const; |
1963
|
194 |
2832
|
195 boolMatrix all (void) const; |
|
196 boolMatrix any (void) const; |
458
|
197 |
|
198 Matrix cumprod (void) const; |
|
199 Matrix cumsum (void) const; |
|
200 Matrix prod (void) const; |
|
201 Matrix sum (void) const; |
|
202 Matrix sumsq (void) const; |
2385
|
203 Matrix abs (void) const; |
458
|
204 |
|
205 ColumnVector diag (void) const; |
|
206 ColumnVector diag (int k) const; |
|
207 |
|
208 ColumnVector row_min (void) const; |
2354
|
209 ColumnVector row_max (void) const; |
458
|
210 |
2354
|
211 ColumnVector row_min (Array<int>& index) const; |
|
212 ColumnVector row_max (Array<int>& index) const; |
458
|
213 |
|
214 RowVector column_min (void) const; |
2354
|
215 RowVector column_max (void) const; |
458
|
216 |
2354
|
217 RowVector column_min (Array<int>& index) const; |
|
218 RowVector column_max (Array<int>& index) const; |
458
|
219 |
1359
|
220 // i/o |
458
|
221 |
3504
|
222 friend std::ostream& operator << (std::ostream& os, const Matrix& a); |
|
223 friend std::istream& operator >> (std::istream& is, Matrix& a); |
458
|
224 |
3504
|
225 int read (std::istream& is, int nr, int nc, oct_data_conv::data_type dt, |
2317
|
226 int skip, oct_mach_info::float_format flt_fmt); |
|
227 |
3504
|
228 int write (std::ostream& os, oct_data_conv::data_type dt, int skip, |
2317
|
229 oct_mach_info::float_format flt_fmt); |
458
|
230 |
|
231 private: |
|
232 |
1214
|
233 Matrix (double *d, int r, int c) : MArray2<double> (d, r, c) { } |
458
|
234 }; |
|
235 |
1959
|
236 extern Matrix Givens (double, double); |
1819
|
237 |
1959
|
238 extern Matrix Sylvester (const Matrix&, const Matrix&, const Matrix&); |
|
239 |
2828
|
240 extern Matrix operator * (const Matrix& a, const Matrix& b); |
|
241 |
2870
|
242 MS_CMP_OP_DECLS (Matrix, double) |
|
243 MS_BOOL_OP_DECLS (Matrix, double) |
|
244 |
|
245 SM_CMP_OP_DECLS (double, Matrix) |
|
246 SM_BOOL_OP_DECLS (double, Matrix) |
|
247 |
|
248 MM_CMP_OP_DECLS (Matrix, Matrix) |
|
249 MM_BOOL_OP_DECLS (Matrix, Matrix) |
|
250 |
3573
|
251 MARRAY_FORWARD_DEFS (MArray2, Matrix, double) |
|
252 |
458
|
253 #endif |
|
254 |
|
255 /* |
|
256 ;;; Local Variables: *** |
|
257 ;;; mode: C++ *** |
|
258 ;;; End: *** |
|
259 */ |