help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MacOSX: Octave.app 2.9.14


From: Quentin Spencer
Subject: Re: MacOSX: Octave.app 2.9.14
Date: Wed, 03 Oct 2007 16:21:29 -0500
User-agent: Thunderbird 2.0.0.5 (X11/20070727)

John W. Eaton wrote:
On  3-Oct-2007, Quentin Spencer wrote:

| John W. Eaton wrote:
| > On 30-Sep-2007, Dmitri A. Sergatskov wrote:
| >
| > | Another speedup can be done if we make a norm (x,1) a special case,
| > | so instead of calculating:
| > | | > | octave:29> tic; sum((abs(x) .^1))^1 ; toc
| > | Elapsed time is 0.174812 seconds.
| > | | > | We can simply calculate: | > | | > | octave:30> tic; sum((abs(x))) ; toc
| > | Elapsed time is 0.080658 seconds.
| >
| > Patches, anyone?
| > | | It looks like it should be as simple as this.

Thanks.

What about the other suggestions here:

  http://www.cae.wisc.edu/pipermail/help-octave/2007-September/006001.html


OK, here's another version with special cases for p==2 and real and complex inputs.

Quentin

Index: scripts/linear-algebra/norm.m
===================================================================
RCS file: /cvs/octave/scripts/linear-algebra/norm.m,v
retrieving revision 1.31
diff -u -r1.31 norm.m
--- scripts/linear-algebra/norm.m       1 Oct 2007 15:59:33 -0000       1.31
+++ scripts/linear-algebra/norm.m       3 Oct 2007 21:19:56 -0000
@@ -93,6 +93,16 @@
           retval = max (abs (x));
         elseif (p == -Inf)
           retval = min (abs (x));
+        elseif (p == 1)
+          retval = sum (abs (x));
+        elseif (p == 2)
+          if (iscomplex (x))
+            y = abs(x);
+            y .*= y;
+            retval = sqrt (sum (y));
+          else
+            retval = sqrt (sum (x .* x));
+          endif
         else
           retval = sum (abs (x) .^ p) ^ (1/p);
         endif

reply via email to

[Prev in Thread] Current Thread [Next in Thread]