Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to get the cubic root for complex number?

Reply
Thread Tools

How to get the cubic root for complex number?

 
 
Peng Yu
Guest
Posts: n/a
 
      09-10-2008
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;
}
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      09-10-2008
Peng Yu wrote:

> 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:ow( x, 1.0/3.0 );
std::cout << r << '\n'
<< r*r*r << '\n';
}


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
 
Peng Yu
Guest
Posts: n/a
 
      09-10-2008
On Sep 9, 8:10 pm, Kai-Uwe Bux <(E-Mail Removed)> wrote:
> Peng Yu wrote:
> > 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.


cbrt() is conforming to C99.

Thanks,
Peng
 
Reply With Quote
 
dot
Guest
Posts: n/a
 
      09-10-2008
Jack Klein wrote:
> On Tue, 9 Sep 2008 18:20:45 -0700 (PDT), Peng Yu <(E-Mail Removed)>
> wrote in comp.lang.c++:
>
>> On Sep 9, 8:10 pm, Kai-Uwe Bux <(E-Mail Removed)> wrote:
>>> Peng Yu wrote:
>>>> 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.

>> cbrt() is conforming to C99.

>
> ...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
 
Reply With Quote
 
Michael DOUBEZ
Guest
Posts: n/a
 
      09-10-2008
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)

--
Michael
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
cubic root subroutine Dan van Ginhoven Perl Misc 20 02-25-2005 08:59 AM
Cubic Root JKop C++ 8 04-29-2004 08:32 PM
Cubic root Philip KOCH Javascript 2 11-11-2003 05:29 PM



Advertisments