# HG changeset patch # User jwe # Date 1200425061 0 # Node ID 4ec8f8a4f0056a00f58dd59ca0c9cd620e73b2e5 # Parent 90b931a4061751a5db217a43b76420892259167b [project @ 2008-01-15 19:24:21 by jwe] diff -r 90b931a40617 -r 4ec8f8a4f005 scripts/ChangeLog --- a/scripts/ChangeLog Tue Jan 15 19:12:14 2008 +0000 +++ b/scripts/ChangeLog Tue Jan 15 19:24:21 2008 +0000 @@ -1,3 +1,7 @@ +2008-01-15 John W. Eaton + + * linear-algebra/__norm__.m: Use sum(abs(x),2), not sum(abs(x.')). + 2008-01-15 Michael Goffioul * plot/drawnow.m, plot/__go_draw_figure__.m, plot/__go_draw_axes__.m: diff -r 90b931a40617 -r 4ec8f8a4f005 scripts/linear-algebra/__norm__.m --- a/scripts/linear-algebra/__norm__.m Tue Jan 15 19:12:14 2008 +0000 +++ b/scripts/linear-algebra/__norm__.m Tue Jan 15 19:24:21 2008 +0000 @@ -80,7 +80,7 @@ retval = inf_norm; endif elseif (strcmp (p, "inf")) - retval = max (sum (abs (x.'))); + retval = max (sum (abs (x), 2)); else error ("norm: unrecognized vector norm"); endif @@ -91,7 +91,7 @@ s = svd (x); retval = s (1); elseif (p == Inf) - retval = max (sum (abs (x.'))); + retval = max (sum (abs (x), 2)); else error ("norm: unrecognized matrix norm"); endif @@ -101,23 +101,25 @@ endfunction %!test -%! x = __norm__ (zeros (5), "fro"); -%! assert (x, 0); -%! x = __norm__ (ones (5), "fro"); -%! assert (x, 5); -%! x = __norm__ (zeros (5,1), "fro"); -%! assert (x, 0); -%! x = __norm__ (2*ones (5,3), "fro"); -%! assert (x, sqrt (60)); +%! assert (__norm__ (magic (3)), 15, -2*eps); +%! assert (__norm__ (magic (3) * i), 15, -2*eps); + +%!test +%! assert (__norm__ (zeros (5), "fro"), 0); +%! assert (__norm__ (ones (5), "fro"), 5); +%! assert (__norm__ (zeros (5,1), "fro"), 0); +%! assert (__norm__ (2*ones (5,3), "fro"), sqrt (60)); %!test -%! x = __norm__ (zeros (5), "inf"); -%! assert (x, 0); -%! x = __norm__ (ones (5), "inf"); -%! assert (x, 5); -%! x = __norm__ (2*ones (5,1), "inf"); -%! assert (x, 0); -%! x = __norm__ (2*ones (5,3), "inf"); -%! assert (x, 6); +%! assert (__norm__ (zeros (5), "inf"), 0); +%! assert (__norm__ (ones (5), "inf"), 5); +%! assert (__norm__ (2*ones (5,1), "inf"), 2); +%! assert (__norm__ (2*ones (5,3), "inf"), 6); + +%!test +%! assert (__norm__ (zeros (5), 1), 0); +%! assert (__norm__ (ones (5), 1), 5); +%! assert (__norm__ (2*ones (1,5), 1), 10); +%! assert (__norm__ (2*ones (3,5), 1), 6);