# HG changeset patch # User jwe # Date 1200645339 0 # Node ID 270f28cfa7a0054c2167e9a382c99fd5e736fda4 # Parent f9df7f7520e7c981c8b4712ca16958ca7dd0f80b [project @ 2008-01-18 08:35:39 by jwe] diff -r f9df7f7520e7 -r 270f28cfa7a0 scripts/ChangeLog --- a/scripts/ChangeLog Fri Jan 18 08:25:24 2008 +0000 +++ b/scripts/ChangeLog Fri Jan 18 08:35:39 2008 +0000 @@ -1,3 +1,8 @@ +2008-01-15 Rolf Fabian + + * linear-algebra/__norm__.m: Only scale if inf norm is finite. + New tests. + 2008-01-18 John W. Eaton * optimization/sqp.m: End each function with endfunction. diff -r f9df7f7520e7 -r 270f28cfa7a0 scripts/linear-algebra/__norm__.m --- a/scripts/linear-algebra/__norm__.m Fri Jan 18 08:25:24 2008 +0000 +++ b/scripts/linear-algebra/__norm__.m Fri Jan 18 08:35:39 2008 +0000 @@ -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); + +