How to get the cubic root for complex number?

P

Peng Yu

Hi,

I'm wondering how to get the cubic root for a complex number? It seems
that cbrt does not work complex numbers.

Thanks,
Peng

#include <complex>
#include <iostream>

int main () {
std::complex<double> x(2, 2);
std::cout << cbrt(x) << std::endl;
}
 
K

Kai-Uwe Bux

Peng said:
Hi,

I'm wondering how to get the cubic root for a complex number? It seems
that cbrt does not work complex numbers.

I cannot find cbrt() in the standard anyway.

Thanks,
Peng

#include <complex>
#include <iostream>

int main () {
std::complex<double> x(2, 2);
std::cout << cbrt(x) << std::endl;
}

#include <cmath>
#include <complex>
#include <iostream>
#include <ostream>

int main () {
std::complex<double> x(2, 2);
std::complex<double> r = std::pow( x, 1.0/3.0 );
std::cout << r << '\n'
<< r*r*r << '\n';
}


Best

Kai-Uwe Bux
 
D

dot

Jack said:
...then wait until it is added to C++, which it probably will be.
Because it is not part of the standard C++ library today.

You don't need to wait. Write yourself a function to call cbrt(),
compile under C99, link it with the rest of your program.

Ben
 
M

Michael DOUBEZ

Peng Yu a écrit :
Hi,

I'm wondering how to get the cubic root for a complex number? It seems
that cbrt does not work complex numbers.

Because it would have to give too much results.

Mathematically, for a complex number c=r*exp(i*t),r>=0, the results are
obtained by solving z**3=c=r*exp(i*(t+2*k*pi)),k natural number.

The general solution is z=r**(1/3)*exp(i*(t+2*k*pi)/3)
Relevant solutions are:

z1=r**(1/3)*exp(i*t/3)
z2=r**(1/3)*exp(i*(t+2*pi)/3)
z3=r**(1/3)*exp(i*(t-2*pi)/3)
 

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,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top