Udostępnij za pośrednictwem


sqrt

Oblicza pierwiastek kwadratowy z liczby zespolonej.

template<class Type>
   complex<Type> sqrt(
      const complex<Type>& _ComplexNum
   );

Parametry

  • _ComplexNum
    To liczba zespolona, której pierwiastek kwadratowy ma być.

Wartość zwracana

Pierwiastek kwadratowy z liczby zespolonej.

Uwagi

Pierwiastek kwadratowy ma kąt fazy interwał półotwartych (-pi/2, pi/2].

Kawałki oddziału w płaszczyźnie zespolonej są ujemne osi real.

Pierwiastek kwadratowy z liczby zespolonej będzie moduł, który jest pierwiastek kwadratowy wprowadzania numeru i argument, który jest połowę wprowadzania numeru.

Przykład

// complex_sqrt.cpp
// compile with: /EHsc
#include <complex>
#include <iostream>

int main( )
{
   using namespace std;
   double pi = 3.14159265359;

   // Complex numbers can be entered in polar form with
   // modulus and argument parameter inputs but are
   // stored in Cartesian form as real & imag coordinates
   complex <double> c1 ( polar ( 25.0 , pi / 2 ) );
   complex <double> c2 = sqrt ( c1 );
   cout << "c1 = polar ( 5.0 ) = " << c1 << endl;
   cout << "c2 = sqrt ( c1 ) = " << c2 << endl;


   // The modulus and argument of a complex number can be recovered
   double absc2 = abs ( c2 );
   double argc2 = arg ( c2 );
   cout << "The modulus of c2 is recovered from c2 using: abs ( c2 ) = "
        << absc2 << endl;
   cout << "Argument of c2 is recovered from c2 using:\n arg ( c2 ) = "
        << argc2 << " radians, which is " << argc2 * 180 / pi
        << " degrees." << endl;
   
   // The modulus and argument of c2 can be directly calculated
   absc2 = sqrt( abs ( c1 ) );
   argc2 = 0.5 * arg ( c1 );
   cout << "The modulus of c2 = sqrt( abs ( c1 ) ) =" << absc2 << endl;
   cout << "The argument of c2 = ( 1 / 2 ) * arg ( c1 ) ="
        << argc2 << " radians,\n which is " << argc2 * 180 / pi
        << " degrees." << endl;
}
  
  

Wymagania

Nagłówek: <complex>

Obszar nazw: std