473,587 Members | 2,527 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 3203
"Justin Caldicott" <ju****@caldico tt.org> wrote in message
news:3f******@2 12.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****@caldico tt.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.********@com Acast.net> wrote in message
news:kqhIb.1727 67$8y1.521047@a ttbi_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.********@com Acast.net> wrote in message
news:kqhIb.1727 67$8y1.521047@a ttbi_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.********@com Acast.net> wrote in message
news:LMiIb.7793 5$VB2.156647@at tbi_s51...
"P.J. Plauger" <pj*@dinkumware .com> wrote...
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:kqhIb.1727 67$8y1.521047@a ttbi_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
1785
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 other with the host as "linux.site." I suppose this is normal, but I don't understand why. This is sort of a repost from yesterday, but since then...
21
4104
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 cmplx, temp;
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 routh-hurwitz criterion. So it is difficult to code. Can you please tell me how to solve the problem for degree 20 ? and how to approach the problem for...
0
1277
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 polynomial of degree 100. For more information see http://calcrpnpy.sourceforge.net/ratfun.html
3
2204
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 read Q307467 (How To Create an ASP.NET Application from Multiple Projects for Team Development) and it seems to work well. I understand that when...
18
2061
by: anand | last post by:
*********************************************************************************************************** #include<stdio.h> #include<conio.h> #include<math.h> void main() { double a,b,c,fa,fb,fc,err; int count;
2
2027
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 roots are 0 and -1
1
2992
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 roots” if the discriminant is negative and find the two roots when there is no error condition. DO NOT FIND THE ROOT IF THERE IS AN ERROR CONDITION....
16
9845
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 <module> TypeError: no ordering relation is defined for complex numbers
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5394
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2358
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 we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.