Mercurial > hg > octave-lojdl
changeset 14067:b2e9c4b0c4f8 stable
isdefinite.m: Use any specified tolerance in deciding whether matrix is hermitian.
* isdefinite.m: Use any specified tolerance in deciding whether matrix is hermitian.
author | Lukas Reichlin <lukas.reichlin@gmail.com> |
---|---|
date | Sun, 18 Dec 2011 19:15:50 -0800 |
parents | 80bda7c4f012 |
children | 6eeb9e8e63cf |
files | scripts/linear-algebra/isdefinite.m |
diffstat | 1 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/linear-algebra/isdefinite.m +++ b/scripts/linear-algebra/isdefinite.m @@ -37,16 +37,16 @@ print_usage (); endif - if (! ishermitian (x)) - error ("isdefinite: X must be a hermitian matrix"); - endif - if (! isfloat (x)) x = double (x); endif if (nargin == 1) - tol = 100 * eps(class (x)) * norm (x, "fro"); + tol = 100 * eps (class (x)) * norm (x, "fro"); + endif + + if (! ishermitian (x, tol)) + error ("isdefinite: X must be a Hermitian matrix"); endif e = tol * eye (rows (x)); @@ -64,6 +64,7 @@ endfunction + %!test %! A = [-1 0; 0 -1]; %! assert (isdefinite (A), -1) @@ -81,4 +82,6 @@ %! assert (isdefinite (A), 0) %!error isdefinite () -%!error isdefinite ([1 2; 3 4]) \ No newline at end of file +%!error isdefinite (1,2,3) +%!error <X must be a Hermitian matrix> isdefinite ([1 2; 3 4]) +