Không chỉ các số thực, Python cũng có thể xử lý các số phức và các chức năng liên quan của nó bằng cách sử dụng tệp CM CMath. Các số phức tạp có cách sử dụng của chúng trong nhiều ứng dụng liên quan đến toán học và Python cung cấp các công cụ hữu ích để xử lý và thao túng chúng.
Chuyển đổi số thực thành số phức
Một số phức được đại diện bởi các x + yi. Python chuyển đổi các số thực x và y thành phức tạp bằng cách sử dụng phức hợp hàm [x, y]. Phần thực có thể được truy cập bằng cách sử dụng phần thực [] và phần tưởng tượng có thể được biểu diễn bằng hình ảnh []. x + yi “. Python converts the real numbers x and y into complex using the function complex[x,y]. The real part can be accessed using the function real[] and imaginary part can be represented by imag[].
import
cmath
x
=
5
The phase of complex number is : 3.1415926535897930
=
The phase of complex number is : 3.1415926535897932
The phase of complex number is : 3.1415926535897933
=
The phase of complex number is : 3.1415926535897935
The phase of complex number is : 3.1415926535897936
The phase of complex number is : 3.1415926535897937
The phase of complex number is : 3.1415926535897938
The phase of complex number is : 3.1415926535897939
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]0
=
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]2
The phase of complex number is : 3.1415926535897937
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]4
The phase of complex number is : 3.1415926535897937
The phase of complex number is : 3.1415926535897938
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]7
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]0
=
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]2
The phase of complex number is : 3.1415926535897937
f[k] = Re[k - 0.5*[sqrt[1 - 4*k] + 1]]
2Đầu ra:
The real part of complex number is : 5.0 The imaginary part of complex number is : 3.0
Giai đoạn của số phức
Về mặt hình học, pha của một số phức là góc giữa trục thực dương và vectơ đại diện cho số phức. Điều này còn được gọi là đối số của số phức. Pha được trả về bằng pha [], lấy số phức làm đối số. Phạm vi của pha nằm từ -pi đến +pi. tức là từ -3,14 đến +3,14.angle between the positive real axis and the vector representing complex number. This is also known as argument of complex number. Phase is returned using phase[], which takes complex number as argument. The range of phase lies from -pi to +pi. i.e from -3.14 to +3.14.
import
cmath
x
=
5
The phase of complex number is : 3.1415926535897930
=
The phase of complex number is : 3.1415926535897932
The phase of complex number is : 3.1415926535897933
=
The phase of complex number is : 3.1415926535897935
The phase of complex number is : 3.1415926535897936
The phase of complex number is : 3.1415926535897937
The phase of complex number is : 3.1415926535897938
The phase of complex number is : 3.1415926535897939
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]0
=
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]2
The phase of complex number is : 3.1415926535897937
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]4
Output:
The phase of complex number is : 3.141592653589793
The phase of complex number is : 3.141592653589793
7 The phase of complex number is : 3.141592653589793
8The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483]
The rectangular form of complex number is : [1.0000000000000002+1j]
7The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483]
The rectangular form of complex number is : [1.0000000000000002+1j]
0=
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483]
The rectangular form of complex number is : [1.0000000000000002+1j]
2
The phase of complex number is : 3.1415926535897937
f[k] = Re[k - 0.5*[sqrt[1 - 4*k] + 1]]
2 polar[], which returns a pair[r,ph] denoting the modulus r and phase angle
ph. modulus can be displayed using abs[] and phase using phase[].A complex number converts into rectangular coordinates by using rect[r, ph], where r is modulus and ph is phase angle. It returns a value numerically equal to r * [math.cos[ph] + math.sin[ph]*1j]
import
cmath
x
=
5
The phase of complex number is : 3.1415926535897930
=
The phase of complex number is : 3.1415926535897932
The phase of complex number is : 3.1415926535897933
=
The phase of complex number is : 3.1415926535897935
The phase of complex number is : 3.1415926535897936
The phase of complex number is : 3.1415926535897933
=
The phase of complex number is : 3.1415926535897935
The phase of complex number is : 3.1415926535897936
The phase of complex number is : 3.1415926535897937
The phase of complex number is : 3.1415926535897938
The phase of complex number is : 3.1415926535897939
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]0
=
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]2
The phase of complex number is : 3.1415926535897937
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]4
The phase of complex number is : 3.1415926535897937
The phase of complex number is : 3.1415926535897938
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]7
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]0
=
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]2
The phase of complex number is : 3.1415926535897937
f[k] = Re[k - 0.5*[sqrt[1 - 4*k] + 1]]
2Đầu ra:
The phase of complex number is : 3.1415926535897937
The phase of complex number is : 3.1415926535897938
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]7
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]0
=
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]2
Output:
The modulus and argument of polar complex number is : [1.4142135623730951, 0.7853981633974483] The rectangular form of complex number is : [1.0000000000000002+1j]
The phase of complex number is : 3.1415926535897937
f[k] = Re[k - 0.5*[sqrt[1 - 4*k] + 1]]
2Đầu ra:Manjeet Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Giai đoạn của số phức
Tôi đang cố gắng vẽ các chức năng sau đây ...
f[k] = Re[k - 0.5*[sqrt[1 - 4*k] + 1]]
Đối với 5
4, nhưng điều tốt nhất tôi có thể làm là ...
import matplotlib.pyplot as plt
import numpy as np
k = np.linspace[-2, 2, 100]
f = np.real[k - 0.5*[np.sqrt[1 - 4*k] + 1]]
plt.plot[k, f]
plt.axis[[-2,2,-10,10]]
mà âm mưu tốt cho 5
5 nhưng không có gì cho kết quả phức tạp. Tôi có thể làm điều này theo cách khác không?