Liczby zespolone w Pythonie | Zestaw 2 (ważne funkcje i stałe)

Wprowadzenie do liczb zespolonych w Pythonie: Liczby zespolone w Pythonie | Zestaw 1 (Wprowadzenie) W tym artykule omówiono kilka ważniejszych funkcji i stałych. Operacje na liczbach zespolonych : 1. exp() :- Ta funkcja zwraca wykładnik potęgowy liczby zespolonej wymienionej w jej argumencie. 2. log(xb) :- Ta funkcja zwraca logarytmiczna wartość x o podstawie b both mentioned in its arguments. If base is not specified natural log of x is returned. Python
   # Python code to demonstrate the working of    # exp() log()   # importing 'cmath' for complex number operations   import   cmath   import   math   # Initializing real numbers   x   =   1.0   y   =   1.0   # converting x and y into complex number   z   =   complex  (  x     y  );   # printing exponent of complex number   print   (  'The exponent of complex number is : '     end  =  ''  )   print   (  cmath  .  exp  (  z  ))   # printing log form of complex number   print   (  'The log(base 10) of complex number is : '     end  =  ''  )   print   (  cmath  .  log  (  z    10  ))   
Output:
The exponent of complex number is : (1.4686939399158851+2.2873552871788423j) The log(base 10) of complex number is : (0.15051499783199057+0.3410940884604603j)  
  3. log10() :- Ta funkcja zwraca podstawa dziennika 10 liczby zespolonej. 4. sqrt() :- To oblicza pierwiastek kwadratowy of a complex number. Python
   # Python code to demonstrate the working of    # log10() sqrt()   # importing 'cmath' for complex number operations   import   cmath   import   math   # Initializing real numbers   x   =   1.0   y   =   1.0   # converting x and y into complex number   z   =   complex  (  x     y  );   # printing log10 of complex number   print   (  'The log10 of complex number is : '     end  =  ''  )   print   (  cmath  .  log10  (  z  ))   # printing square root form of complex number   print   (  'The square root of complex number is : '     end  =  ''  )   print   (  cmath  .  sqrt  (  z  ))   
Output:
The log10 of complex number is : (0.15051499783199057+0.3410940884604603j) The square root of complex number is : (1.09868411346781+0.45508986056222733j)  
  5. jest nieskończony() :- Zwraca prawdziwe, jeśli jest to zarówno część rzeczywista, jak i urojona liczby zespolonej to skończony w przeciwnym razie zwraca wartość false. 6. Dla Ciebie() :- Zwraca prawda, jeśli jest to część rzeczywista lub urojona liczby zespolonej jest/are nieskończony w przeciwnym razie zwraca wartość false. 7. isnan() :- Zwraca wartość true, jeśli część rzeczywista lub urojona liczby zespolonej to NaN else returns false. Python
   # Python code to demonstrate the working of    # isnan() isinf() isfinite()   # importing 'cmath' for complex number operations   import   cmath   import   math   # Initializing real numbers   x   =   1.0   y   =   1.0   a   =   math  .  inf   b   =   math  .  nan   # converting x and y into complex number   z   =   complex  (  x    y  );   # converting x and a into complex number   w   =   complex  (  x    a  );   # converting x and b into complex number   v   =   complex  (  x    b  );   # checking if both numbers are finite   if   cmath  .  isfinite  (  z  ):   print   (  'Complex number is finite'  )   else   :   print   (  'Complex number is infinite'  )   # checking if either number is/are infinite   if   cmath  .  isinf  (  w  ):   print   (  'Complex number is infinite'  )   else   :   print   (  'Complex number is finite'  )   # checking if either number is/are infinite   if   cmath  .  isnan  (  v  ):   print   (  'Complex number is NaN'  )   else   :   print   (  'Complex number is not NaN'  )   
Output:
Complex number is finite Complex number is infinite Complex number is NaN  
  Stałe W module cmath zdefiniowano dwie stałe 'liczba pi' która zwraca wartość liczbową pi. Drugie jest 'I' which returns the numerical value of exponent. Python
   # Python code to demonstrate the working of    # pi and e    # importing 'cmath' for complex number operations   import   cmath   import   math   # printing the value of pi    print   (  'The value of pi is : '     end  =  ''  )   print   (  cmath  .  pi  )   # printing the value of e   print   (  'The value of exponent is : '     end  =  ''  )   print   (  cmath  .  e  )   
Output:
The value of pi is : 3.141592653589793 The value of exponent is : 2.718281828459045  
Liczby zespolone w Pythonie | Zbiór 3 (funkcje trygonometryczne i hiperboliczne)