473,513 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Complex Roots

Hi

There are n solutions to the nth root of any number, eg:

(-8)^(1/3) = 1 + sqrt(3)i
or -2
or 1 - sqrt(3)i

The following code:

complex<double> x = -8;
complex<double> cbrtX = pow(x, 1.0/3.0);

gives cbrtX = 1 + sqrt(3)i, the first solution from above. (with both MS and
STLPort 4.6 versions of the C++ standard library)
My question is, does anyone know a method of retrieving the other solutions?

Perhaps -2 is the most useful solution, as it is purely real..

Thanks

Justin
Jul 22 '05 #1
5 3190
"Justin Caldicott" <ju****@caldicott.org> wrote in message
news:3f******@212.67.96.135...
There are n solutions to the nth root of any number, eg:

(-8)^(1/3) = 1 + sqrt(3)i
or -2
or 1 - sqrt(3)i

The following code:

complex<double> x = -8;
complex<double> cbrtX = pow(x, 1.0/3.0);

gives cbrtX = 1 + sqrt(3)i, the first solution from above. (with both MS and STLPort 4.6 versions of the C++ standard library)
My question is, does anyone know a method of retrieving the other solutions?
Perhaps -2 is the most useful solution, as it is purely real..


Keep multiplying by the polar vector (1, 2*pi/8).

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #2
"Justin Caldicott" <ju****@caldicott.org> wrote...
There are n solutions to the nth root of any number, eg:

(-8)^(1/3) = 1 + sqrt(3)i
or -2
or 1 - sqrt(3)i

The following code:

complex<double> x = -8;
complex<double> cbrtX = pow(x, 1.0/3.0);

gives cbrtX = 1 + sqrt(3)i, the first solution from above. (with both MS and STLPort 4.6 versions of the C++ standard library)
My question is, does anyone know a method of retrieving the other solutions?
Perhaps -2 is the most useful solution, as it is purely real..


The Standard says that pow(x,y) is implemented as exp(y*log(x)), so what
you get is
1./3. * log(-8)
e

where log(-8) is calculated so that imag(log(-8)) is Pi [3.1415926...].

The only ways to get all roots of 'Number' is to solve the corresponding
equation:

n
x + Number = 0

using whatever methods mathematicians use (instead of 'pow' function).

Victor
Jul 22 '05 #3
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:kqhIb.172767$8y1.521047@attbi_s52...
The Standard says that pow(x,y) is implemented as exp(y*log(x)),
It says nothing of the sort, nor should it. That's often a *terrible*
way to compute the power function, if you value accuracy at all.
so what
you get is
1./3. * log(-8)
e

where log(-8) is calculated so that imag(log(-8)) is Pi [3.1415926...].

The only ways to get all roots of 'Number' is to solve the corresponding
equation:

n
x + Number = 0

using whatever methods mathematicians use (instead of 'pow' function).


Or you can get the principal root and note that the n roots of a complex
number are spaced at equal angles on a circle about the origin.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #4
"P.J. Plauger" <pj*@dinkumware.com> wrote...
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:kqhIb.172767$8y1.521047@attbi_s52...
The Standard says that pow(x,y) is implemented as exp(y*log(x)),
It says nothing of the sort, nor should it.


Well, uh, whether it should or not is not my place to say. But 26.2.8/9
DOES say that pow is "defined as exp(y*log(x))". Just spend a few seconds
and peek in your copy of the Standard. So, I accept your apology for the
"it says nothing of the sort".
That's often a *terrible*
way to compute the power function, if you value accuracy at all.
You're on the Standard Committee, aren't you? Go tell THEM.
so what
you get is
1./3. * log(-8)
e

where log(-8) is calculated so that imag(log(-8)) is Pi [3.1415926...].

The only ways to get all roots of 'Number' is to solve the corresponding
equation:

n
x + Number = 0

using whatever methods mathematicians use (instead of 'pow' function).


Or you can get the principal root and note that the n roots of a complex
number are spaced at equal angles on a circle about the origin.


Good. It's been a while since I used complex numbers in my household
calculations.

Victor
Jul 22 '05 #5
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:LMiIb.77935$VB2.156647@attbi_s51...
"P.J. Plauger" <pj*@dinkumware.com> wrote...
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:kqhIb.172767$8y1.521047@attbi_s52...
The Standard says that pow(x,y) is implemented as exp(y*log(x)),


It says nothing of the sort, nor should it.


Well, uh, whether it should or not is not my place to say. But 26.2.8/9
DOES say that pow is "defined as exp(y*log(x))". Just spend a few seconds
and peek in your copy of the Standard. So, I accept your apology for the
"it says nothing of the sort".


Sorry, wrong "it". I was thinking of the C Standard (and that's what I
checked before posting).
That's often a *terrible*
way to compute the power function, if you value accuracy at all.


You're on the Standard Committee, aren't you? Go tell THEM.


At least the C++ Standard says the value is "defined as ...", which
IMO leaves us implementors wiggle room to do the job properly.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1778
by: Richard Hollenbeck | last post by:
I'm sure there's a good explanation, but I haven't seen it in any of the documentation. When I query the mysql database in the user table I see two roots--one with the host as "localhost" and the...
21
4094
by: Blair | last post by:
could someone PLEASE tell me why this doesn't work... ----------------------------------------- #include <complex> using namespace std; typedef complex<long double> cld; void main() { cld...
2
620
by: temper3243 | last post by:
Hi, I have been trying to solve the problem Roots of the polynomial 038 from mipt.ru (el judge). I have failed to do so. I tried to search on the net but found about contour integrals for...
0
1271
by: Raymond L. Buvel | last post by:
If you are using the root finder in Numeric, and are having problems, check out the root finder in the ratfun module. My testing indicates that it will give the exact roots of a Wilkinson...
3
2201
by: Carl Johansen | last post by:
I have a big ASP website (used by several thousand car dealers) that is a collection of lots of small and medium-sized applications. Now I want to start adding ASP.NET applications to it. I have...
18
2049
by: anand | last post by:
*********************************************************************************************************** #include<stdio.h> #include<conio.h> #include<math.h> void main() { double...
2
2024
by: =?ISO-8859-1?Q?Sch=FCle_Daniel?= | last post by:
Hello NG, given this call to roots funtion from pylab In : roots() Out: array() as far as I understand it stands for a0+a1*x+a2*x^2 in the above case it yields 2x^2+2x = 2x(1+x) and the...
1
2985
by: candacefaye1 | last post by:
1. write a C++ program to decide if the coefficients of a quadratic equation have real roots. The three choices will be to write the message “zero divide” when A is zero, write the message “no real...
16
9824
by: skip | last post by:
The thread on sorting in Python 3 got me to thinking. How could I sort a list of complex numbers using key? As expected: Traceback (most recent call last): File "<stdin>", line 1, in...
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.