Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
sqrt complex

Subject: sqrt complex

From: Bruno Luong

Date: 11 May, 2010 16:26:04

Message: 1 of 6

I read at the help and doc but I could not find any specification of SQRT for complex numbers.

It seems the output keeps the same sign of the imaginary part as the input, and the discontinuity (in the complex plane) is the negative real axis. This is what I want, but I love to see it documented somewhere.

Any opinion?

Bruno

Subject: sqrt complex

From: Matt J

Date: 11 May, 2010 17:04:05

Message: 2 of 6

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hsc0es$988$1@fred.mathworks.com>...
> I read at the help and doc but I could not find any specification of SQRT for complex numbers.
>
> It seems the output keeps the same sign of the imaginary part as the input, and the discontinuity (in the complex plane) is the negative real axis. This is what I want, but I love to see it documented somewhere.
>
> Any opinion?
===============

Probably the closest thing you can get right now is

doc angle

After some experimentation it is pretty clear that the underlying algorithm is

sqrt(A)=sqrt(abs(A))*exp(-i*angle(A)/2);

Subject: sqrt complex

From: Bruno Luong

Date: 11 May, 2010 17:47:04

Message: 3 of 6

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hsc2m5$38l$1@fred.mathworks.com>...

> After some experimentation it is pretty clear that the underlying algorithm is
>
> sqrt(A)=sqrt(abs(A))*exp(-i*angle(A)/2);

I'm not sure. It does not give exactly the same output, and it's also slower

n = 1e6;
A=randn(1,n)+1i*rand(1,n);

tic
B=sqrt(abs(A)).*exp(-1i*angle(A)/2);
toc % Elapsed time is 0.292321 seconds.

tic
C=sqrt(A);
toc % Elapsed time is 0.082047 seconds.

isequal(B,C) % 0

%%%%%%%

I would prefer using stock SQRT function. My program expects the result having imaginary part with the same sign. Of course I can test the sign and reverse if necessary but why spending time for something that is true but not documented?

% Bruno

Subject: sqrt complex

From: Doug Schwarz

Date: 11 May, 2010 18:58:45

Message: 4 of 6

In article <hsc56o$ee6$1@fred.mathworks.com>,
 "Bruno Luong" <b.luong@fogale.findmycountry> wrote:

> "Matt J " <mattjacREMOVE@THISieee.spam> wrote in message
> <hsc2m5$38l$1@fred.mathworks.com>...
>
> > After some experimentation it is pretty clear that the underlying algorithm
> > is
> >
> > sqrt(A)=sqrt(abs(A))*exp(-i*angle(A)/2);
>
> I'm not sure. It does not give exactly the same output, and it's also slower
>
> n = 1e6;
> A=randn(1,n)+1i*rand(1,n);
>
> tic
> B=sqrt(abs(A)).*exp(-1i*angle(A)/2);
> toc % Elapsed time is 0.292321 seconds.
>
> tic
> C=sqrt(A);
> toc % Elapsed time is 0.082047 seconds.
>
> isequal(B,C) % 0
>
> %%%%%%%
>
> I would prefer using stock SQRT function. My program expects the result
> having imaginary part with the same sign. Of course I can test the sign and
> reverse if necessary but why spending time for something that is true but not
> documented?
>
> % Bruno

I can't answer your question, but on my machine the algorithm uses +1i
in the exponent, not -1i. (R2009a on Mac OS X)

  sqrt(A) = sqrt(abs(A))*exp(1i*angle(A)/2);

It still does not match exactly.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: sqrt complex

From: Roger Stafford

Date: 11 May, 2010 19:38:04

Message: 5 of 6

Doug Schwarz <see@sig.for.address.edu> wrote in message <see-FA4995.14584511052010@news.frontiernet.net>...
> In article <hsc56o$ee6$1@fred.mathworks.com>,
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote:
>
> > "Matt J " <mattjacREMOVE@THISieee.spam> wrote in message
> > <hsc2m5$38l$1@fred.mathworks.com>...
> >
> > > After some experimentation it is pretty clear that the underlying algorithm
> > > is
> > >
> > > sqrt(A)=sqrt(abs(A))*exp(-i*angle(A)/2);
> >
> > I'm not sure. It does not give exactly the same output, and it's also slower
> >
> > n = 1e6;
> > A=randn(1,n)+1i*rand(1,n);
> >
> > tic
> > B=sqrt(abs(A)).*exp(-1i*angle(A)/2);
> > toc % Elapsed time is 0.292321 seconds.
> >
> > tic
> > C=sqrt(A);
> > toc % Elapsed time is 0.082047 seconds.
> >
> > isequal(B,C) % 0
> >
> > %%%%%%%
> >
> > I would prefer using stock SQRT function. My program expects the result
> > having imaginary part with the same sign. Of course I can test the sign and
> > reverse if necessary but why spending time for something that is true but not
> > documented?
> >
> > % Bruno
>
> I can't answer your question, but on my machine the algorithm uses +1i
> in the exponent, not -1i. (R2009a on Mac OS X)
>
> sqrt(A) = sqrt(abs(A))*exp(1i*angle(A)/2);
>
> It still does not match exactly.
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

  Perhaps they use:

 sqrt(z) = exp(1/2*log(z))

That should always give a non-negative imaginary part. Actually I suspect they have their own special algorithm, however.

Roger Stafford

Subject: sqrt complex

From: Roger Stafford

Date: 11 May, 2010 19:49:04

Message: 6 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hscbms$b4u$1@fred.mathworks.com>...
> .......
> That should always give a non-negative imaginary part. Actually I suspect they have their own special algorithm, however.
> .......

  I didn't say what I meant. I should have said that the real part is always non-negative.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us