How to get the cubic root for complex number?

Discussion in 'C++' started by Peng Yu, Sep 10, 2008.

  1. Peng Yu

    Peng Yu Guest

    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;
    }
     
    Peng Yu, Sep 10, 2008
    #1
    1. Advertising

  2. Peng Yu

    Kai-Uwe Bux Guest

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


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Sep 10, 2008
    #2
    1. Advertising

  3. Peng Yu

    Peng Yu Guest

    On Sep 9, 8:10 pm, Kai-Uwe Bux <> 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
     
    Peng Yu, Sep 10, 2008
    #3
  4. Peng Yu

    dot Guest

    Jack Klein wrote:
    > On Tue, 9 Sep 2008 18:20:45 -0700 (PDT), Peng Yu <>
    > wrote in comp.lang.c++:
    >
    >> On Sep 9, 8:10 pm, Kai-Uwe Bux <> 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
     
    dot, Sep 10, 2008
    #4
  5. 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
     
    Michael DOUBEZ, Sep 10, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop

    Cubic Root

    JKop, Apr 24, 2004, in forum: C++
    Replies:
    8
    Views:
    6,242
    Gunnar G
    Apr 29, 2004
  2. Will Ware
    Replies:
    0
    Views:
    453
    Will Ware
    Nov 21, 2005
  3. jitasi
    Replies:
    1
    Views:
    769
    Terry Reedy
    Mar 4, 2007
  4. Philip KOCH

    Cubic root

    Philip KOCH, Nov 11, 2003, in forum: Javascript
    Replies:
    2
    Views:
    138
    Dr John Stockton
    Nov 11, 2003
  5. Dan van Ginhoven

    cubic root subroutine

    Dan van Ginhoven, Feb 19, 2005, in forum: Perl Misc
    Replies:
    20
    Views:
    392
    Arndt Jonasson
    Feb 25, 2005
Loading...

Share This Page