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:
Symbolic Math BUG with ATAN2 function

Subject: Symbolic Math BUG with ATAN2 function

From: sofa saib

Date: 18 Aug, 2004 14:11:29

Message: 1 of 6

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

Subject: Symbolic Math BUG with ATAN2 function

From: moler@mathworks.com (Cleve Moler)

Date: 19 Aug, 2004 01:32:37

Message: 2 of 6

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.

  -- Cleve
  moler@mathworks.com

Subject: Symbolic Math BUG with ATAN2 function

From: sofa

Date: 19 Aug, 2004 03:20:10

Message: 3 of 6

ATAN2 does not work with symbolic math ?
----------------------------------------
syms x
y=1/(1+x)
a=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));

HELP ? WHY ?

/////////////////////////////////////////////

Cleve Moler wrote:
>
>
> 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.
>
> -- Cleve
> moler@mathworks.com
>
>
>

Subject: Symbolic Math BUG with ATAN2 function

From: Felipe Nievinski

Date: 21 Dec, 2009 23:28:04

Message: 4 of 6

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.

Subject: Symbolic Math BUG with ATAN2 function

From: Star Strider

Date: 22 Dec, 2009 09:31:05

Message: 5 of 6

"Felipe Nievinski" <fgnievinski@gmail.com> wrote in message <hgp0a4$ojt$1@fred.mathworks.com>...
> 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.



Seems to me atan2 doesn't really mean anything in the symbolic context, since x and y aren't defined numerically. (The purpose of atan2 is to put the resulting angle in the correct quadrant.) How about the old standby: phi = atan(imag(y)/real(y))? MATLAB is good, but it won't do your homework *for* you!

Star Strider

Subject: Symbolic Math BUG with ATAN2 function

From: Felipe Nievinski

Date: 22 Dec, 2009 18:12:03

Message: 6 of 6

"Star Strider" <skystriderDELETETHIS@ieee.net> wrote in message <hgq3kp$ktf$1@fred.mathworks.com>...
> "Felipe Nievinski" <fgnievinski@gmail.com> wrote in message <hgp0a4$ojt$1@fred.mathworks.com>...
> > 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.
>
>
>
> Seems to me atan2 doesn't really mean anything in the symbolic context, since x and y aren't defined numerically.
But it _does_ mean as soon as you replace the symbolic variables by numerical values, e.g., double(subs(P, {'X','Y'}, {-0.1,+0.3}));
furthermore, without a symbolic atan2 (and hypot, too), you can't use cart2sph with symbolic input.

> How about the old standby: phi = atan(imag(y)/real(y))? MATLAB is good, but it won't do your homework *for* you!
y is not complex. and even if it were, "The purpose of atan2 is to put the resulting angle in the correct quadrant," in contrast with atan.

-Felipe.

Tags for this Thread

No tags are associated with 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