 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Justin Caldicott Guest
|
Posted: Tue Dec 30, 2003 3:37 pm Post subject: Complex Roots |
|
|
Hi
There are n solutions to the nth root of any number, eg:
(- ^(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
|
|
| Back to top |
|
 |
P.J. Plauger Guest
|
Posted: Tue Dec 30, 2003 4:00 pm Post subject: Re: Complex Roots |
|
|
"Justin Caldicott" <justin (AT) caldicott (DOT) org> wrote
| Quote: | There are n solutions to the nth root of any number, eg:
(- ^(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/ .
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Tue Dec 30, 2003 4:08 pm Post subject: Re: Complex Roots |
|
|
"Justin Caldicott" <justin (AT) caldicott (DOT) org> wrote...
| Quote: | There are n solutions to the nth root of any number, eg:
(- ^(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(-
e
where log(- is calculated so that imag(log(- ) 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
|
|
| Back to top |
|
 |
P.J. Plauger Guest
|
Posted: Tue Dec 30, 2003 4:50 pm Post subject: Re: Complex Roots |
|
|
"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote
| Quote: | 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.
| Quote: | so what
you get is
1./3. * log(-
e
where log(- is calculated so that imag(log(- ) 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
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Tue Dec 30, 2003 5:40 pm Post subject: Re: Complex Roots |
|
|
"P.J. Plauger" <pjp (AT) dinkumware (DOT) com> wrote...
| Quote: | "Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote in message
news:kqhIb.172767$8y1.521047 (AT) attbi_s52 (DOT) ..
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".
| Quote: | 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.
| Quote: |
so what
you get is
1./3. * log(-
e
where log(- is calculated so that imag(log(- ) 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
|
|
| Back to top |
|
 |
P.J. Plauger Guest
|
Posted: Tue Dec 30, 2003 6:15 pm Post subject: Re: Complex Roots |
|
|
"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote
| Quote: | "P.J. Plauger" <pjp (AT) dinkumware (DOT) com> wrote...
"Victor Bazarov" <v.Abazarov (AT) comAcast (DOT) net> wrote in message
news:kqhIb.172767$8y1.521047 (AT) attbi_s52 (DOT) ..
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).
| Quote: | 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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|