Complex Roots

J

Justin Caldicott

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
 
P

P.J. Plauger

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
 
V

Victor Bazarov

Justin Caldicott said:
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
 
P

P.J. Plauger

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
 
V

Victor Bazarov

P.J. Plauger said:
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
 
P

P.J. Plauger

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).
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top