Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sqrt complex
Date: Tue, 11 May 2010 17:47:04 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 26
Message-ID: <hsc56o$ee6$1@fred.mathworks.com>
References: <hsc0es$988$1@fred.mathworks.com> <hsc2m5$38l$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1273600024 14790 172.30.248.35 (11 May 2010 17:47:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 11 May 2010 17:47:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:634691

"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