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