Mercurial > octave
annotate src/DLD-FUNCTIONS/rcond.cc @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | 610a4e780a19 |
children | 60e5cf354d80 197774b411ec |
rev | line source |
---|---|
7788 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12791
diff
changeset
|
3 Copyright (C) 2008-2012 David Bateman |
7788 | 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 3 of the License, or (at your | |
10 option) any 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, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "defun-dld.h" | |
28 #include "error.h" | |
29 #include "gripes.h" | |
30 #include "oct-obj.h" | |
31 #include "utils.h" | |
32 | |
33 DEFUN_DLD (rcond, args, , | |
34 "-*- texinfo -*-\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
35 @deftypefn {Loadable Function} {@var{c} =} rcond (@var{A})\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
36 Compute the 1-norm estimate of the reciprocal condition number as returned\n\ |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
37 by @sc{lapack}. If the matrix is well-conditioned then @var{c} will be near\n\ |
7788 | 38 1 and if the matrix is poorly conditioned it will be close to zero.\n\ |
39 \n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
40 The matrix @var{A} must not be sparse. If the matrix is sparse then\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
41 @code{condest (@var{A})} or @code{rcond (full (@var{A}))} should be used\n\ |
7788 | 42 instead.\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
43 @seealso{cond, condest}\n\ |
7788 | 44 @end deftypefn") |
45 { | |
46 octave_value retval; | |
47 | |
48 int nargin = args.length (); | |
49 | |
50 if (nargin != 1) | |
51 print_usage (); | |
52 else if (args(0).is_sparse_type ()) | |
53 error ("rcond: for sparse matrices use 'rcond (full (a))' or 'condest (a)' instead"); | |
7797
f42c6f8d6d8e
Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
54 else if (args(0).is_single_type ()) |
f42c6f8d6d8e
Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
55 { |
f42c6f8d6d8e
Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
56 if (args(0).is_complex_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
57 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
58 FloatComplexMatrix m = args(0).float_complex_matrix_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
59 MatrixType mattyp; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
60 retval = m.rcond (mattyp); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
61 args(0).matrix_type (mattyp); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
62 } |
7797
f42c6f8d6d8e
Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
63 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
64 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
65 FloatMatrix m = args(0).float_matrix_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
66 MatrixType mattyp; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
67 retval = m.rcond (mattyp); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
68 args(0).matrix_type (mattyp); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
69 } |
7797
f42c6f8d6d8e
Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
70 } |
7788 | 71 else if (args(0).is_complex_type ()) |
72 { | |
73 ComplexMatrix m = args(0).complex_matrix_value (); | |
74 MatrixType mattyp; | |
75 retval = m.rcond (mattyp); | |
76 args(0).matrix_type (mattyp); | |
77 } | |
78 else | |
79 { | |
80 Matrix m = args(0).matrix_value (); | |
81 MatrixType mattyp; | |
82 retval = m.rcond (mattyp); | |
83 args(0).matrix_type (mattyp); | |
84 } | |
85 | |
86 return retval; | |
87 } | |
12791
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
88 |
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
89 /* |
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
90 |
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
91 %!assert( rcond (eye (2)), 1) |
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
92 %!assert( rcond (ones (2)), 0) |
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
93 %!assert( rcond ([1 1; 2 1]), 1/9) |
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
94 %!assert( rcond (magic (4)), 0, eps) |
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
95 |
610a4e780a19
codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11572
diff
changeset
|
96 */ |