Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Can you determine the sign of the polar form of a complex number?

Reply
Thread Tools

Can you determine the sign of the polar form of a complex number?

 
 
schaefer.mp@gmail.com
Guest
Posts: n/a
 
      10-17-2007
To compute the absolute value of a negative base raised to a
fractional exponent such as:

z = (-3)^4.5

you can compute the real and imaginary parts and then convert to the
polar form to get the correct value:

real_part = ( 3^-4.5 ) * cos( -4.5 * pi )
imag_part = ( 3^-4.5 ) * sin( -4.5 * pi )

|z| = sqrt( real_part^2 + imag_part^2 )

Is there any way to determine the correct sign of z, or perform this
calculation in another way that allows you to get the correct value of
z expressed without imaginary parts?

For example, I can compute:

z1 = (-3)^-4 = 0,012345679
and
z3 = (-3)^-5 = -0,004115226

and I can get what the correct absolute value of z2 should be by
computing the real and imaginary parts:

|z2| = (-3)^-4.5 = sqrt( 3,92967E-18^2 + -0,007127781^2 ) =
0,007127781

but I need to know the sign.

Any help is appreciated.



but I can know the correct sign for this value.

 
Reply With Quote
 
 
 
 
schaefer.mp@gmail.com
Guest
Posts: n/a
 
      10-17-2007
Just to clarify what I'm after:

If you plot (-3)^n where n is a set of negative real numbers between 0
and -20 for example, then you get a discontinuos line due to the
problem mentioned above with fractional exponents. However, you can
compute what the correct absolute value of the the missing points
should be (see z2 above for an example), but I would like to know how
to determine what the correct sign of z2 should be so that it fits the
graph.



 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      10-17-2007
In article <(E-Mail Removed) .com>,
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Just to clarify what I'm after:
>
> If you plot (-3)^n where n is a set of negative real numbers between 0
> and -20 for example, then you get a discontinuos line due to the
> problem mentioned above with fractional exponents. However, you can
> compute what the correct absolute value of the the missing points
> should be (see z2 above for an example), but I would like to know how
> to determine what the correct sign of z2 should be so that it fits the
> graph.


You need to ask this question on a math group. It's not a Python question
at all.
 
Reply With Quote
 
Paul Rubin
Guest
Posts: n/a
 
      10-17-2007
(E-Mail Removed) writes:
> Just to clarify what I'm after:
> If you plot (-3)^n where n is a set of negative real numbers between 0


I still can't figure out for certain what you're asking, but you might
look at the article

http://en.wikipedia.org/wiki/De_Moivre%27s_formula
 
Reply With Quote
 
J. Robertson
Guest
Posts: n/a
 
      10-17-2007
(E-Mail Removed) wrote:
> Just to clarify what I'm after:
>
> If you plot (-3)^n where n is a set of negative real numbers between 0
> and -20 for example, then you get a discontinuos line due to the
> problem mentioned above with fractional exponents.
>
> ..
>


It looks like you crash-landed in imaginary space, you may want to think
again about what you're up to Complex numbers are not positive or
negative, as such.

If you want to obtain a continuous curve, then take the real part of the
complex number you obtain, as in "((-3+0j)**(-x)).real", it will fit
with what you obtain for integers.


 
Reply With Quote
 
Gerard Flanagan
Guest
Posts: n/a
 
      10-17-2007
On Oct 17, 3:17 pm, (E-Mail Removed) wrote:
> To compute the absolute value of a negative base raised to a
> fractional exponent such as:
>
> z = (-3)^4.5
>
> you can compute the real and imaginary parts and then convert to the
> polar form to get the correct value:
>
> real_part = ( 3^-4.5 ) * cos( -4.5 * pi )
> imag_part = ( 3^-4.5 ) * sin( -4.5 * pi )
>
> |z| = sqrt( real_part^2 + imag_part^2 )
>
> Is there any way to determine the correct sign of z, or perform this
> calculation in another way that allows you to get the correct value of
> z expressed without imaginary parts?
>



Your question is not clear. (There is a cmath module if that helps).

>>> z1 = complex(-3)**4.5
>>> z1

(7.7313381458154376e-014+140.29611541307906j)
>>> import cmath
>>> z2 = cmath.exp(4.5 * cmath.log(-3))
>>> z2

(7.7313381458154401e-014+140.29611541307909j)
>>>


Gerard

 
Reply With Quote
 
Matimus
Guest
Posts: n/a
 
      10-17-2007
On Oct 17, 6:51 am, (E-Mail Removed) wrote:
> Just to clarify what I'm after:
>
> If you plot (-3)^n where n is a set of negative real numbers between 0
> and -20 for example, then you get a discontinuos line due to the
> problem mentioned above with fractional exponents. However, you can
> compute what the correct absolute value of the the missing points
> should be (see z2 above for an example), but I would like to know how
> to determine what the correct sign of z2 should be so that it fits the
> graph.


I know this isn't specifically what you are asking, but since you
aren't asking a Python question and this is a Python group I figure
I'm justified in giving you a slightly unrelated Python answer.

If you want to raise a negative number to a fractional exponent in
Python you simply have to make sure that you use complex numbers to
begin with:

>>> (-3+0j)**4.5

(7.7313381458154376e-014+140.29611541307906j)

Then if you want the absolute value of that, you can simply use the
abs function:

>>> x = (-3+0j)**4.5
>>> abs(x)

140.29611541307906

The absolute value will always be positive. If you want the angle you
can use atan.

>>> x = (-3+0j)**4.5
>>> math.atan(x.imag/x.real)

1.5707963267948961

I would maybe do this:

>>> def ang(x):

.... return math.atan(x.imag/x.real)

So, now that you have the angle and the magnitude, you can do this:

>>> abs(x) * cmath.exp(1j * ang(x))

(7.0894366756400186e-014+140.29611541307906j)

Which matches our original answer. Well, there is a little rounding
error because we are using floats.

So, if you have a negative magnitude, that should be exactly the same
as adding pi (180 degrees) to the angle.

>>> (-abs(x)) * cmath.exp(1j * (ang(x)+cmath.pi))

(2.5771127152718125e-014+140.29611541307906j)

Which should match our original answer. It is a little different, but
notice the magnitude of the real and imaginary parts. The real part
looks different, but is so small compared to the imaginary part that
it can almost be ignored.

Matt

 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      10-17-2007
On Oct 17, 7:51 am, (E-Mail Removed) wrote:
> Just to clarify what I'm after:
>
> If you plot (-3)^n where n is a set of negative real numbers between 0
> and -20 for example, then you get a discontinuos line due to the
> problem mentioned above with fractional exponents. However, you can
> compute what the correct absolute value of the the missing points
> should be (see z2 above for an example), but I would like to know how
> to determine what the correct sign of z2 should be so that it fits the
> graph.


As Roy said, a math newsgroup may be able to help you better, as you
seem to be having fundamental issues with imaginary numbers. The
imaginary part isn't an artifact of computing (-3+0j)**(-4.5), it is
an integral part of the answer. Without the imaginary part, the
result is very, very incorrect.

Actually, the graph result of (-3)^n is not necessarily discontinuous
at the intervals you specified. You just need to graph the result
with the proper number of dimensions. If you want to plot the results
of (-3)^n for n=0 to -20, you need to make a three dimensional graph,
a two dimensional graph with two sets of lines, or a circular graph
with labeled values of n.

Complex numbers can be viewed as having a magnitude and a rotation in
the real/imaginary plane. This is called polar form. Complex numbers
can also be represented using a Cartesian form, which is how Python
displays complex numbers.

Python's complex numbers allow you to extract the real or imaginary
part separately, via the "real" and "imag" attributes. To convert to
polar form, you'll need to use the abs built-in to retrieve the
magnitude, and math.atan2 to retrieve the angle. (Remember that the
imaginary part is considered the Y-axis component.)

Depending on what you're doing, you might need the real part or the
magnitude. It sounds a little bit like you're trying to represent
something as a flatlander when you should be in Spaceland. (http://
en.wikipedia.org/wiki/Flatland)

--Jason

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
negative values on polar plot (decibels polar plots ) yadin Python 0 08-14-2007 04:05 PM
DVD Verdict reviews: MARCH OF THE PENGUINS, THE POLAR EXPRESS: SPECIAL EDITION, and more! DVD Verdict DVD Video 0 11-29-2005 09:17 AM
NTDLL.DLL and polar performance system Asaf.Louzon@gmail.com Computer Support 1 10-09-2005 10:01 AM
DVD Verdict reviews: THE LITTLE POLAR BEAR, THE WUBBULOUS WORLD OF DR. SEUSS, and more! DVD Verdict DVD Video 0 02-28-2004 10:05 AM
Polar to Rectangular conversion Alexander Weddell VHDL 1 11-28-2003 03:46 PM



Advertisments