Path: news.mathworks.com!not-for-mail
From: "Felipe Nievinski" <fgnievinski@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Symbolic Math BUG with ATAN2 function
Date: Mon, 21 Dec 2009 23:28:04 +0000 (UTC)
Organization: University of Colorado
Lines: 48
Message-ID: <hgp0a4$ojt$1@fred.mathworks.com>
References: <eee66e0.-1@webx.raydaftYaTP> <cg0vvl$q91$1@fred.mathworks.com>
Reply-To: "Felipe Nievinski" <fgnievinski@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1261438084 25213 172.30.248.38 (21 Dec 2009 23:28:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 21 Dec 2009 23:28:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 591043
Xref: news.mathworks.com comp.soft-sys.matlab:594227

moler@mathworks.com (Cleve Moler) wrote in message <cg0vvl$q91$1@fred.mathworks.com>...
> In article <eee66e0.-1@webx.raydaftYaTP>,
> sofa saib <sofa_2004au@yahoo.com.au> wrote:
> >If I use the following code
> >
> >syms x
> >y=1/(1+i*x)
> >r=abs(y)
> >ezplot( y )
> >
> >This works great to plot the magnitude of
> >the complex number y
> >
> >But if I want to plot the Angle of the
> >complex number
> >The following error results
> >-----------------------------------------
> >>> by=angle( y )
> >??? Function 'atan2' is not defined for values of class 'sym'.
> >
> >Error in ==> atan2 at 15
> >  [varargout{1:nargout}] = builtin('atan2', varargin{:});
> >
> >Error in ==> angle at 15
> >p = atan2(imag(h), real(h));
> >------------------------------------------
> >
> >Seems like the ATAN2 function will not work
> >with symbolic math and yet the abs function dies.
> >This makes complex symbolic maths rather
> >useless with matlab ????
> >
> >Any help would be appreciated ?
> >Is this a bug ???
> >
> >thanks
> >sofa_2004au@yahoo.com.au
> 
> Hi --
> 
> The ATAN2 function is only defined for real arguments, even in MATLAB
> itself.  Since its definition involves the signs of its two arguments,
> it doesn't make sense for complex arguments.  It isn't a bug.
> 
What about expressing the symbolic atan2 via the tangent half-angle formula:
    P = 2 * atan( (sqrt(X.^2 + Y.^2) - X) ./ Y );
(See <http://en.wikipedia.org/wiki/Atan2>)
-F.