help-octave
[Top][All Lists]

## Re: Applying function to vector by index

 From: Paul Kienzle Subject: Re: Applying function to vector by index Date: Thu, 12 Dec 2002 09:40:11 -0500 User-agent: Mutt/1.2.5.1i

```On Tue, Dec 10, 2002 at 10:38:48AM +0100, Schloegl Alois wrote:
>
>
>
> > I've got most of a patch in place, but there's all
> > sorts of weird side cases.
> >
> > For example, what should sparse(eye(2)).^(1+1i) give?
> >
> > Matlab gives:
> > >> full(sparse(eye(2)).^(1+1i))
> >
> > ans =
> >
> >      1     0
> >      0     1
> >
> > >> full(full(eye(2)).^(1+1i))
> >
> > ans =
> >
> >    1.0000             NaN +    NaNi
> >       NaN +    NaNi   1.0000
> >
> >
> > That's because a^(b+ci) = e^(ln(a))*(b+ci)
> > and ln(a) is NaN
>
>
> It should be
>    a^(b+ci) = e^(ln(a)*(b+ci))
>             = e^(ln(a)*b + ln(a)*ci)
>             = e^(ln(a)*b)*e^(ln(a)*ci)
>
> ln(a) = [0,-inf;-inf,0]
>
> Because e^(ln(a)*i) is limited (abs(e^(ln(a)*i)<=1) and b>0, the result
> converges. Hence, the result [1,0;0,1] is correct.

However, for b <=0 the result should be NaN.

Matlab is inconsistent in this case:

>> eye(2).^(-2+i)

ans =

1.0000                NaN +    NaNi
NaN +    NaNi   1.0000

>> sparse(eye(2)).^(-2+i)

ans =

(1,1)        1
(2,2)        1

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```