logo

Python의 복소수 | 세트 1(소개)

실수뿐만 아니라 Python은 'cmath' 파일을 사용하여 복소수 및 관련 함수도 처리할 수 있습니다. 복소수 수학과 관련된 많은 응용 프로그램에서 사용되며 Python은 이를 처리하고 조작하는 데 유용한 도구를 제공합니다. 실수를 복소수로 변환 복소수는 ' x + 이 '. Python은 다음 함수를 사용하여 실수 x와 y를 복소수로 변환합니다. 복합체(xy) . 실제 부분은 함수를 사용하여 액세스할 수 있습니다. 진짜() 허수부는 다음과 같이 표현될 수 있습니다. 이미지()

Python
# Python code to demonstrate the working of # complex() real() and imag() # importing 'cmath' for complex number operations import cmath # Initializing real numbers x = 5 y = 3 # converting x and y into complex number z = complex(x y) # printing real and imaginary part of complex number print('The real part of complex number is:' z.real) print('The imaginary part of complex number is:' z.imag) 

산출
The real part of complex number is: 5.0 The imaginary part of complex number is: 3.0 

복소수를 초기화하는 다른 방법  



다음은 복잡한 숫자를 만드는 방법을 구현한 것입니다. 사용하지 않고 complex() 함수 .

Python
# An alternative way to initialize complex numbers' # importing 'cmath' for complex number operations import cmath # Initializing complex number z = 5+3j # Print the parts of Complex No. print('The real part of complex number is : ' end='') print(z.real) print('The imaginary part of complex number is : ' end='') print(z.imag) 

산출
The real part of complex number is : 5.0 The imaginary part of complex number is : 3.0 

설명: 복소수의 위상 기하학적으로 복소수의 위상은 양의 실수 축과 복소수를 나타내는 벡터 사이의 각도 . 이는 다음으로도 알려져 있습니다. 논쟁 복소수의. 위상은 다음을 사용하여 반환됩니다. 단계() 이는 복소수를 인수로 사용합니다. 위상 범위는 다음과 같습니다. -pi는 +pi를 의미합니다. 즉, -3.14 ~ +3.14 .

Python
# importing 'cmath' for complex number operations import cmath # Initializing real numbers x = -1.0 y = 0.0 # converting x and y into complex number z = complex(x y) # printing phase of a complex number using phase() print('The phase of complex number is:' cmath.phase(z)) 

산출
The phase of complex number is: 3.141592653589793 

극형에서 직사각형으로 또는 그 반대로 변환 극좌표로의 변환은 다음을 사용하여 수행됩니다. 극선() 이는 쌍(rph) 나타내는 모듈러스 r 및 위상 각도 ph . 모듈러스는 다음을 사용하여 표시할 수 있습니다. 복근() 및 단계 사용 단계() . 복소수는 다음을 사용하여 직교 좌표로 변환됩니다. 직사각형(r ph) 어디 r은 모듈러스입니다. 그리고 ph는 위상각 . 수치적으로 다음과 같은 값을 반환합니다. r * (math.cos(ph) + math.sin(ph)*1j)  

Python
# 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) # converting complex number into polar using polar() w = cmath.polar(z) # printing modulus and argument of polar complex number print('The modulus and argument of polar complex number is:' w) # converting complex number into rectangular using rect() w = cmath.rect(1.4142135623730951 0.7853981633974483) # printing rectangular form of complex number print('The rectangular form of complex number is:' w) 

산출
The modulus and argument of polar complex number is: (1.4142135623730951 0.7853981633974483) The rectangular form of complex number is: (1.0000000000000002+1j) 


Python의 복소수 | 세트 2(중요 기능 및 상수)