Mercurial > hg > octave-nkf
annotate liboctave/array/dDiagMatrix.cc @ 19174:04dc55bf71e8
adjust spacing in gnuplot legend when non default font size is used.
* scripts/plot/util/private/__go_draw_axes__.m add spacing spec to key
definition in __go_draw_axes__
author | Serviscope Minor <serviscope_minor@verybigfrog.com> |
---|---|
date | Mon, 04 Aug 2014 20:49:32 +0100 |
parents | 80b8873c90ba |
children | 4197fc428c7d |
rev | line source |
---|---|
1993 | 1 // DiagMatrix manipulations. |
458 | 2 /* |
3 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17663
diff
changeset
|
4 Copyright (C) 1994-2013 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague |
458 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
458 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
458 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
1192 | 26 #include <config.h> |
458 | 27 #endif |
28 | |
3503 | 29 #include <iostream> |
458 | 30 |
4669 | 31 #include "Array-util.h" |
1368 | 32 #include "lo-error.h" |
458 | 33 #include "mx-base.h" |
34 #include "mx-inlines.cc" | |
1650 | 35 #include "oct-cmplx.h" |
458 | 36 |
1360 | 37 // Diagonal Matrix class. |
458 | 38 |
2385 | 39 bool |
458 | 40 DiagMatrix::operator == (const DiagMatrix& a) const |
41 { | |
42 if (rows () != a.rows () || cols () != a.cols ()) | |
43 return 0; | |
44 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
45 return mx_inline_equal (length (), data (), a.data ()); |
458 | 46 } |
47 | |
2385 | 48 bool |
458 | 49 DiagMatrix::operator != (const DiagMatrix& a) const |
50 { | |
51 return !(*this == a); | |
52 } | |
53 | |
54 DiagMatrix& | |
55 DiagMatrix::fill (double val) | |
56 { | |
5275 | 57 for (octave_idx_type i = 0; i < length (); i++) |
458 | 58 elem (i, i) = val; |
59 return *this; | |
60 } | |
61 | |
62 DiagMatrix& | |
5275 | 63 DiagMatrix::fill (double val, octave_idx_type beg, octave_idx_type end) |
458 | 64 { |
65 if (beg < 0 || end >= length () || end < beg) | |
66 { | |
67 (*current_liboctave_error_handler) ("range error for fill"); | |
68 return *this; | |
69 } | |
70 | |
5275 | 71 for (octave_idx_type i = beg; i <= end; i++) |
458 | 72 elem (i, i) = val; |
73 | |
74 return *this; | |
75 } | |
76 | |
77 DiagMatrix& | |
78 DiagMatrix::fill (const ColumnVector& a) | |
79 { | |
5275 | 80 octave_idx_type len = length (); |
458 | 81 if (a.length () != len) |
82 { | |
83 (*current_liboctave_error_handler) ("range error for fill"); | |
84 return *this; | |
85 } | |
86 | |
5275 | 87 for (octave_idx_type i = 0; i < len; i++) |
458 | 88 elem (i, i) = a.elem (i); |
89 | |
90 return *this; | |
91 } | |
92 | |
93 DiagMatrix& | |
94 DiagMatrix::fill (const RowVector& a) | |
95 { | |
5275 | 96 octave_idx_type len = length (); |
458 | 97 if (a.length () != len) |
98 { | |
99 (*current_liboctave_error_handler) ("range error for fill"); | |
100 return *this; | |
101 } | |
102 | |
5275 | 103 for (octave_idx_type i = 0; i < len; i++) |
458 | 104 elem (i, i) = a.elem (i); |
105 | |
106 return *this; | |
107 } | |
108 | |
109 DiagMatrix& | |
5275 | 110 DiagMatrix::fill (const ColumnVector& a, octave_idx_type beg) |
458 | 111 { |
5275 | 112 octave_idx_type a_len = a.length (); |
458 | 113 if (beg < 0 || beg + a_len >= length ()) |
114 { | |
115 (*current_liboctave_error_handler) ("range error for fill"); | |
116 return *this; | |
117 } | |
118 | |
5275 | 119 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 120 elem (i+beg, i+beg) = a.elem (i); |
121 | |
122 return *this; | |
123 } | |
124 | |
125 DiagMatrix& | |
5275 | 126 DiagMatrix::fill (const RowVector& a, octave_idx_type beg) |
458 | 127 { |
5275 | 128 octave_idx_type a_len = a.length (); |
458 | 129 if (beg < 0 || beg + a_len >= length ()) |
130 { | |
131 (*current_liboctave_error_handler) ("range error for fill"); | |
132 return *this; | |
133 } | |
134 | |
5275 | 135 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 136 elem (i+beg, i+beg) = a.elem (i); |
137 | |
138 return *this; | |
139 } | |
140 | |
141 DiagMatrix | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
142 DiagMatrix::abs (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
143 { |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
144 return DiagMatrix (extract_diag ().abs (), rows (), columns ()); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
145 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
146 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
147 DiagMatrix |
1205 | 148 real (const ComplexDiagMatrix& a) |
149 { | |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
150 return DiagMatrix (real (a.extract_diag ()), a.rows (), a.cols ()); |
1205 | 151 } |
152 | |
153 DiagMatrix | |
154 imag (const ComplexDiagMatrix& a) | |
155 { | |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
156 return DiagMatrix (imag (a.extract_diag ()), a.rows (), a.cols ()); |
1205 | 157 } |
158 | |
458 | 159 Matrix |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
160 DiagMatrix::extract (octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
161 octave_idx_type r2, octave_idx_type c2) const |
458 | 162 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15448
diff
changeset
|
163 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15448
diff
changeset
|
164 if (c1 > c2) { std::swap (c1, c2); } |
458 | 165 |
5275 | 166 octave_idx_type new_r = r2 - r1 + 1; |
167 octave_idx_type new_c = c2 - c1 + 1; | |
458 | 168 |
169 Matrix result (new_r, new_c); | |
170 | |
5275 | 171 for (octave_idx_type j = 0; j < new_c; j++) |
172 for (octave_idx_type i = 0; i < new_r; i++) | |
458 | 173 result.elem (i, j) = elem (r1+i, c1+j); |
174 | |
175 return result; | |
176 } | |
177 | |
178 // extract row or column i. | |
179 | |
180 RowVector | |
5275 | 181 DiagMatrix::row (octave_idx_type i) const |
458 | 182 { |
5275 | 183 octave_idx_type r = rows (); |
184 octave_idx_type c = cols (); | |
3504 | 185 if (i < 0 || i >= r) |
458 | 186 { |
187 (*current_liboctave_error_handler) ("invalid row selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
188 return RowVector (); |
458 | 189 } |
190 | |
3504 | 191 RowVector retval (c, 0.0); |
192 if (r <= c || (r > c && i < c)) | |
458 | 193 retval.elem (i) = elem (i, i); |
194 | |
195 return retval; | |
196 } | |
197 | |
198 RowVector | |
199 DiagMatrix::row (char *s) const | |
200 { | |
533 | 201 if (! s) |
458 | 202 { |
203 (*current_liboctave_error_handler) ("invalid row selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
204 return RowVector (); |
458 | 205 } |
206 | |
207 char c = *s; | |
208 if (c == 'f' || c == 'F') | |
5275 | 209 return row (static_cast<octave_idx_type>(0)); |
458 | 210 else if (c == 'l' || c == 'L') |
211 return row (rows () - 1); | |
212 else | |
213 { | |
214 (*current_liboctave_error_handler) ("invalid row selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
215 return RowVector (); |
458 | 216 } |
217 } | |
218 | |
219 ColumnVector | |
5275 | 220 DiagMatrix::column (octave_idx_type i) const |
458 | 221 { |
5275 | 222 octave_idx_type r = rows (); |
223 octave_idx_type c = cols (); | |
3504 | 224 if (i < 0 || i >= c) |
458 | 225 { |
226 (*current_liboctave_error_handler) ("invalid column selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
227 return ColumnVector (); |
458 | 228 } |
229 | |
3504 | 230 ColumnVector retval (r, 0.0); |
231 if (r >= c || (r < c && i < r)) | |
458 | 232 retval.elem (i) = elem (i, i); |
233 | |
234 return retval; | |
235 } | |
236 | |
237 ColumnVector | |
238 DiagMatrix::column (char *s) const | |
239 { | |
533 | 240 if (! s) |
458 | 241 { |
242 (*current_liboctave_error_handler) ("invalid column selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
243 return ColumnVector (); |
458 | 244 } |
245 | |
246 char c = *s; | |
247 if (c == 'f' || c == 'F') | |
5275 | 248 return column (static_cast<octave_idx_type>(0)); |
458 | 249 else if (c == 'l' || c == 'L') |
250 return column (cols () - 1); | |
251 else | |
252 { | |
253 (*current_liboctave_error_handler) ("invalid column selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
254 return ColumnVector (); |
458 | 255 } |
256 } | |
257 | |
258 DiagMatrix | |
259 DiagMatrix::inverse (void) const | |
260 { | |
8811 | 261 octave_idx_type info; |
458 | 262 return inverse (info); |
263 } | |
264 | |
265 DiagMatrix | |
8811 | 266 DiagMatrix::inverse (octave_idx_type &info) const |
458 | 267 { |
5275 | 268 octave_idx_type r = rows (); |
269 octave_idx_type c = cols (); | |
270 octave_idx_type len = length (); | |
3504 | 271 if (r != c) |
458 | 272 { |
273 (*current_liboctave_error_handler) ("inverse requires square matrix"); | |
274 return DiagMatrix (); | |
275 } | |
276 | |
3504 | 277 DiagMatrix retval (r, c); |
1627 | 278 |
458 | 279 info = 0; |
5275 | 280 for (octave_idx_type i = 0; i < len; i++) |
458 | 281 { |
282 if (elem (i, i) == 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
283 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
284 info = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
285 return *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
286 } |
458 | 287 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
288 retval.elem (i, i) = 1.0 / elem (i, i); |
458 | 289 } |
290 | |
1627 | 291 return retval; |
458 | 292 } |
293 | |
8840
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
294 DiagMatrix |
18535
c5a101de2d88
Allow pinv to work on Diagonal Matrices with a tolerance (bug #41546).
Rik <rik@octave.org>
parents:
18084
diff
changeset
|
295 DiagMatrix::pseudo_inverse (double tol) const |
8840
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
296 { |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
297 octave_idx_type r = rows (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
298 octave_idx_type c = cols (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
299 octave_idx_type len = length (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
300 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
301 DiagMatrix retval (c, r); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
302 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
303 for (octave_idx_type i = 0; i < len; i++) |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
304 { |
18549
16b0cd465ecd
Handle special case of 0 for pinv with Diagonal matrices.
Rik <rik@octave.org>
parents:
18535
diff
changeset
|
305 double val = std::abs (elem (i, i)); |
18564
80b8873c90ba
Fix pinv bug with 0 values introduced in cset 16b0cd465ecd.
Rik <rik@octave.org>
parents:
18562
diff
changeset
|
306 if (val < tol || val == 0.0) |
18535
c5a101de2d88
Allow pinv to work on Diagonal Matrices with a tolerance (bug #41546).
Rik <rik@octave.org>
parents:
18084
diff
changeset
|
307 retval.elem (i, i) = 0.0; |
18564
80b8873c90ba
Fix pinv bug with 0 values introduced in cset 16b0cd465ecd.
Rik <rik@octave.org>
parents:
18562
diff
changeset
|
308 else |
18562 | 309 retval.elem (i, i) = 1.0 / elem (i, i); |
8840
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
310 } |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
311 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
312 return retval; |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
313 } |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
314 |
458 | 315 // diagonal matrix by diagonal matrix -> diagonal matrix operations |
316 | |
317 // diagonal matrix by diagonal matrix -> diagonal matrix operations | |
318 | |
319 DiagMatrix | |
320 operator * (const DiagMatrix& a, const DiagMatrix& b) | |
321 { | |
5275 | 322 octave_idx_type a_nr = a.rows (); |
323 octave_idx_type a_nc = a.cols (); | |
2385 | 324 |
5275 | 325 octave_idx_type b_nr = b.rows (); |
326 octave_idx_type b_nc = b.cols (); | |
2385 | 327 |
3504 | 328 if (a_nc != b_nr) |
9698
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
329 gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc); |
458 | 330 |
3504 | 331 DiagMatrix c (a_nr, b_nc); |
458 | 332 |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
333 octave_idx_type len = c.length (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
334 octave_idx_type lenm = len < a_nc ? len : a_nc; |
458 | 335 |
9698
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
336 for (octave_idx_type i = 0; i < lenm; i++) |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
337 c.dgxelem (i) = a.dgelem (i) * b.dgelem (i); |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
338 for (octave_idx_type i = lenm; i < len; i++) |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
339 c.dgxelem (i) = 0.0; |
458 | 340 |
341 return c; | |
342 } | |
343 | |
344 // other operations | |
345 | |
8371
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
346 DET |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
347 DiagMatrix::determinant (void) const |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
348 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
349 DET det (1.0); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
350 if (rows () != cols ()) |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
351 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
352 (*current_liboctave_error_handler) ("determinant requires square matrix"); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
353 det = 0.0; |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
354 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
355 else |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
356 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
357 octave_idx_type len = length (); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
358 for (octave_idx_type i = 0; i < len; i++) |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
359 det *= elem (i, i); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
360 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
361 |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
362 return det; |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
363 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
364 |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
365 double |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
366 DiagMatrix::rcond (void) const |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
367 { |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
368 ColumnVector av = extract_diag (0).map<double> (fabs); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
369 double amx = av.max (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
370 double amn = av.min (); |
8371
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
371 return amx == 0 ? 0.0 : amn / amx; |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
372 } |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
373 |
3504 | 374 std::ostream& |
375 operator << (std::ostream& os, const DiagMatrix& a) | |
458 | 376 { |
377 // int field_width = os.precision () + 7; | |
1360 | 378 |
5275 | 379 for (octave_idx_type i = 0; i < a.rows (); i++) |
458 | 380 { |
5275 | 381 for (octave_idx_type j = 0; j < a.cols (); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
382 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
383 if (i == j) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
384 os << " " /* setw (field_width) */ << a.elem (i, i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
385 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
386 os << " " /* setw (field_width) */ << 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
387 } |
458 | 388 os << "\n"; |
389 } | |
390 return os; | |
391 } |