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: John W. Eaton
Subject: Re: MacOSX: Octave.app 2.9.14
Date: Wed, 03 Oct 2007 17:36:29 -0400

On  3-Oct-2007, Quentin Spencer wrote:

| 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

OK, I used

  elseif (p == 2)
    if (iscomplex (x))
      x = abs (x);
    endif
    retval = sqrt (sum (x .* x));
  else

Is

  sum (x .* x)

really faster here than

  sumsq (x)

?

jwe

  


reply via email to

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