Hướng dẫn how do you get the complex input in python? - làm thế nào để bạn có được đầu vào phức tạp trong python?

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 hợ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

The phase of complex number is : 3.141592653589793
0____11
The phase of complex number is : 3.141592653589793
2

The phase of complex number is : 3.141592653589793
3
The phase of complex number is : 3.141592653589793
1
The phase of complex number is : 3.141592653589793
5

The phase of complex number is : 3.141592653589793
6
The phase of complex number is : 3.141592653589793
1
The phase of complex number is : 3.141592653589793
8
The phase of complex number is : 3.141592653589793
9

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)
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
2223
The phase of complex number is : 3.141592653589793
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
5

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)
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)
1
complex([real[, imag]])
0
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
3
The phase of complex number is : 3.141592653589793
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
5

The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
0
complex([real[, imag]])
5

Đầ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

The phase of complex number is : 3.141592653589793
0____11
The phase of complex number is : 3.141592653589793
2

The phase of complex number is : 3.141592653589793
3
The phase of complex number is : 3.141592653589793
1
The phase of complex number is : 3.141592653589793
5

The phase of complex number is : 3.141592653589793
6
The phase of complex number is : 3.141592653589793
1
The phase of complex number is : 3.141592653589793
8
The phase of complex number is : 3.141592653589793
9

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)
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
2223
The phase of complex number is : 3.141592653589793
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
5

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)
7

Output:

The phase of complex number is : 3.141592653589793

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)
1
complex([real[, imag]])
0
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
3
The phase of complex number is : 3.141592653589793
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
5

The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
0
complex([real[, imag]])
5 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

The phase of complex number is : 3.141592653589793
0____11
The phase of complex number is : 3.141592653589793
2

The phase of complex number is : 3.141592653589793
3
The phase of complex number is : 3.141592653589793
1
The phase of complex number is : 3.141592653589793
5

The phase of complex number is : 3.141592653589793
6
The phase of complex number is : 3.141592653589793
1
The phase of complex number is : 3.141592653589793
8
The phase of complex number is : 3.141592653589793
9

The phase of complex number is : 3.141592653589793
6
The phase of complex number is : 3.141592653589793
1
The phase of complex number is : 3.141592653589793
8
The phase of complex number is : 3.141592653589793
9

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)
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
2223
The phase of complex number is : 3.141592653589793
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
5

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)
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)
1
complex([real[, imag]])
0
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
3
The phase of complex number is : 3.141592653589793
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
5

The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
0
complex([real[, imag]])
5

Đầu ra:

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)
1
complex([real[, imag]])
0
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
3
The phase of complex number is : 3.141592653589793
1
The modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
5

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 modulus and argument of polar complex number is : (1.4142135623730951, 0.7853981633974483)
The rectangular form of complex number is : (1.0000000000000002+1j)
0
complex([real[, imag]])
5
 

Đầ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


Phương thức phức tạp () trả về một số phức khi các bộ phận thực và tưởng tượng được cung cấp hoặc nó chuyển đổi một chuỗi thành một số phức.

Cú pháp của cmath7 là:

complex([real[, imag]])

các tham số phức tạp ()

Nói chung, phương thức cmath7 có hai tham số:

  • THỰC SỰ - PHẦN THỰC SỰ. Nếu Real bị bỏ qua, nó mặc định là 0. - real part. If real is omitted, it defaults to 0.
  • Hình ảnh - Phần tưởng tượng. Nếu hình ảnh bị bỏ qua, nó mặc định là 0. - imaginary part. If imag is omitted, it defaults to 0.

Nếu tham số đầu tiên được truyền vào phương thức này là một chuỗi, nó sẽ được hiểu là một số phức. Trong trường hợp này, tham số thứ hai không nên được thông qua.


Trả về giá trị từ phức tạp ()

Theo đề xuất của tên, phương thức cmath7 trả về một số phức.

Nếu chuỗi được truyền vào phương thức này không phải là một số phức hợp hợp lệ, ngoại lệ

The phase of complex number is : 3.141592653589793
00 sẽ được nâng lên.

Lưu ý: Chuỗi được chuyển cho cmath7 phải ở dạng

The phase of complex number is : 3.141592653589793
02 hoặc
The phase of complex number is : 3.141592653589793
03
The string passed to cmath7 should be in the form
The phase of complex number is : 3.141592653589793
02 or
The phase of complex number is : 3.141592653589793
03


Ví dụ 1: Làm thế nào để tạo một số phức tạp trong Python?

z = complex(2, -3)
print(z)

z = complex(1)
print(z)

z = complex()
print(z)

z = complex('5-9j')
print(z)

Đầu ra

(2-3j)
(1+0j)
0j
(5-9j)

Ví dụ 2: Tạo số phức mà không sử dụng phức tạp ()

Có thể tạo một số phức mà không cần sử dụng phương thức cmath7. Đối với điều đó, bạn phải đặt 'j' hoặc 'j' sau một số.

a = 2+3j
print('a =',a)
print('Type of a is',type(a))

b = -2j
print('b =',b)
print('Type of b is',type(a))

c = 0j
print('c =',c)
print('Type of c is',type(c))

Đầu ra

a = (2+3j)
Type of a is <class>
b = (-0-2j)
Type of b is <class>
c = 0j
Type of c is <class>

Làm thế nào để bạn lấy đầu vào phức tạp trong Python?

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 hợ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 ().The real part can be accessed using the function real() and imaginary part can be represented by imag().

Làm thế nào để bạn tìm thấy những con số phức tạp trong Python?

Hàm python Complex () Hàm () Hàm trả về một số phức bằng cách chỉ định một số thực và một số tưởng tượng.The complex() function returns a complex number by specifying a real number and an imaginary number.

Làm thế nào để bạn sử dụng chức năng phức tạp trong Python?

Xem ví dụ dưới đây ...
# Ví dụ về chức năng python Complex () ..
# Chức năng gọi ..
a = phức tạp (1+2j) # PASS PASS SINGLE ..
B = phức tạp (1+2J, 2+3J) # Vượt qua cả hai tham số ..
# Hiển thị kết quả ..
print(a).
print(b).

Làm thế nào để bạn in một loại phức tạp trong Python?

Hàm python Complex () trả về một số phức (thực + tưởng tượng) ví dụ (5 + 2J) khi các bộ phận thực và tưởng tượng được truyền, hoặc nó cũng chuyển đổi một chuỗi thành một số phức. returns a complex number ( real + imaginary) example (5+2j) when real and imaginary parts are passed, or it also converts a string to a complex number.