Mercurial > hg > octave-terminal
changeset 6952:09a89fb42c09
[project @ 2007-10-03 21:36:42 by jwe]
author | jwe |
---|---|
date | Wed, 03 Oct 2007 21:37:08 +0000 |
parents | f359defe99ff |
children | 4567a35e0777 |
files | scripts/ChangeLog scripts/linear-algebra/norm.m |
diffstat | 2 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,6 +1,6 @@ 2007-10-03 Quentin Spencer <qspencer@ieee.org> - * linear-algebra/norm.m: Special case vector 1-norm. + * linear-algebra/norm.m: Special case vector 1-norm and 2-norm. 2007-10-03 David Bateman <dbateman@free.fr>
--- a/scripts/linear-algebra/norm.m +++ b/scripts/linear-algebra/norm.m @@ -95,6 +95,11 @@ retval = min (abs (x)); elseif (p == 1) retval = sum (abs (x)); + elseif (p == 2) + if (iscomplex (x)) + x = abs (x); + endif + retval = sqrt (sum (x .* x)); else retval = sum (abs (x) .^ p) ^ (1/p); endif @@ -138,6 +143,7 @@ %!assert(norm(x,"fro"), 10); %!assert(norm(x), 10); %!assert(norm([1e200, 1]), 1e200); +%!assert(norm([3+4i, 3-4i, sqrt(31)]), 9, -4*eps); %!shared m %! m = magic (4); %!assert(norm(m,1), 34);