Mercurial > hg > octave-terminal
changeset 7401:270f28cfa7a0
[project @ 2008-01-18 08:35:39 by jwe]
author | jwe |
---|---|
date | Fri, 18 Jan 2008 08:35:39 +0000 |
parents | f9df7f7520e7 |
children | bd58dafaf102 |
files | scripts/ChangeLog scripts/linear-algebra/__norm__.m |
diffstat | 2 files changed, 24 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2008-01-15 Rolf Fabian <Rolf.Fabian@gmx.de> + + * linear-algebra/__norm__.m: Only scale if inf norm is finite. + New tests. + 2008-01-18 John W. Eaton <jwe@octave.org> * optimization/sqp.m: End each function with endfunction.
--- a/scripts/linear-algebra/__norm__.m +++ b/scripts/linear-algebra/__norm__.m @@ -44,7 +44,7 @@ if (ischar (p)) if (strcmp (p, "fro")) inf_norm = norm (x, "inf"); - if (inf_norm) + if (inf_norm && finite (inf_norm)) retval = inf_norm .* sqrt (sum (abs (x ./ inf_norm) .^ 2)); else retval = inf_norm; @@ -74,7 +74,7 @@ if (ischar (p)) if (strcmp (p, "fro")) inf_norm = norm (x, "inf"); - if (inf_norm) + if (inf_norm && finite (inf_norm)) retval = inf_norm .* sqrt (sum (sum (abs (x ./ inf_norm) .^ 2))); else retval = inf_norm; @@ -123,3 +123,20 @@ %! assert (__norm__ (2*ones (3,5), 1), 6); +%!test +%! assert (__norm__ (1e304 * ones (5, 3), "fro"), 1e304 * sqrt (15)); +%! assert (__norm__ (1e-320 * ones (5, 3), "fro"), 1e-320 * sqrt (15)); +%! assert (x = __norm__ ([1, 2; 3, Inf], "fro"), Inf); +%! assert (x = __norm__ ([1, 2, 3, Inf], "fro"), Inf); +%! assert (x = __norm__ ([1, -Inf; 3, 4], "fro"), Inf); +%! assert (x = __norm__ ([1, 2; 3, NaN], "fro"), NaN); + +%!test +%! assert (__norm__ (1e304 * ones (5, 3), "inf"), 3e304); +%! assert (__norm__ (1e-320 * ones (5, 3), "inf"), 3e-320); +%! assert (x = __norm__ ([1, 2; 3, Inf], "inf"), Inf); +%! assert (x = __norm__ ([1, 2, 3, Inf], "inf"), Inf); +%! assert (x = __norm__ ([1, -Inf; 3, 4], "inf"), Inf); +%! assert (x = __norm__ ([1, 2; 3, NaN], "inf"), 3); + +