Hướng dẫn how do you compute polar form of 2 − 3i in python - làm thế nào để bạn tính toán dạng cực của 2 - 3i trong python

Tôi là người mới đến Python nên hãy chịu đựng tôi. Vấn đề là:

"Viết một chức năng cực [z] để chuyển đổi một số phức sang dạng cực của nó [r, theta]. Bạn có thể sử dụng các hàm math.atan2 và math.hypot nhưng không phải là thư viện cmath."

Tôi thậm chí không biết bắt đầu từ đâu với cái này, nhưng cho đến nay tôi có:

import math
def polar[z]:
    z = a + bj
    r = math.hypot[a,b]
    theta = math.atan2[b,a]
    print "[",r,",",theta,"]"

Bất kỳ trợ giúp sẽ làm!

Hỏi ngày 10 tháng 10 năm 2016 lúc 4:17Oct 10, 2016 at 4:17

0

Bạn có thể sử dụng Object.Real và Object.imag để có được các giá trị của các giá trị thực và tưởng tượng. Kiểm tra câu trả lời này

import math
def polar[z]:
    a= z.real
    b= z.imag
    r = math.hypot[a,b]
    theta = math.atan2[b,a]
    return r,theta # use return instead of print.

u=3+5j
print polar[u]

Output:

[5.830951894845301, 1.0303768265243125]

Đọc sự khác biệt b/w in và trả lại trong các chức năng.

Đã trả lời ngày 10 tháng 10 năm 2016 lúc 4:37Oct 10, 2016 at 4:37

abs []: Phương thức này trả về mô đun [giá trị tuyệt đối] của số phức Z.

Absolute value of 3 + 4j is: 5.0
5=
Absolute value of 3 + 4j is: 5.0
7
Absolute value of 3 + 4j is: 5.0
8
Absolute value of 3 + 4j is: 5.0
9

import math
def polar[z]:
    a= z.real
    b= z.imag
    r = math.hypot[a,b]
    theta = math.atan2[b,a]
    return r,theta # use return instead of print.

u=3+5j
print polar[u]
2
The phase of complex number is : 3.141592653589793
8[5.830951894845301, 1.0303768265243125]2[5.830951894845301, 1.0303768265243125]3[5.830951894845301, 1.0303768265243125]4[5.830951894845301, 1.0303768265243125]5

  • Bạn được cung cấp một số Z phức tạp và nhiệm vụ của bạn là chuyển đổi nó thành tọa độ cực.
  • Chúng ta hãy coi một số phức là 1+5J và chúng ta cần chuyển đổi nó thành tọa độ cực. & NBSP;
  • abs []: Phương thức này trả về mô đun [giá trị tuyệt đối] của số phức Z.

    Absolute value of 3 + 4j is: 5.0
    5=
    Absolute value of 3 + 4j is: 5.0
    7
    Absolute value of 3 + 4j is: 5.0
    8
    Absolute value of 3 + 4j is: 5.0
    9

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    2
    The phase of complex number is : 3.141592653589793
    8[5.830951894845301, 1.0303768265243125]2[5.830951894845301, 1.0303768265243125]3[5.830951894845301, 1.0303768265243125]4[5.830951894845301, 1.0303768265243125]5

    Bạn được cung cấp một số Z phức tạp và nhiệm vụ của bạn là chuyển đổi nó thành tọa độ cực.

    Nó hoàn toàn được xác định bởi phần X thực và phần tưởng tượng của nó y. Ở đây, J là đơn vị tưởng tượng.

    Các tọa độ cực [r,] được xác định hoàn toàn bởi mô đun r và góc pha.

    Where,

    • R: Khoảng cách từ z đến gốc, tức là, & nbsp; Distance from z to origin, i.e., 

    • & nbsp; φ: Góc ngược chiều kim đồng hồ được đo từ trục x dương đến đoạn dòng nối z với gốc.φ: Counterclockwise angle measured from the positive x-axis to the line segment that joins z to the origin.

    Việc chuyển đổi các số phức thành tọa độ cực được giải thích dưới đây với các ví dụ.

    Sử dụng mô -đun CMATH

    Mô -đun CMATH của Python cung cấp quyền truy cập vào các hàm toán học cho các số phức. Nó chứa một số chức năng được sử dụng để chuyển đổi tọa độ từ miền này sang miền khác. & NBSP;

    Trong số họ, một số được giải thích khi-

    1. cmath.polar [x]:

    Trả về đại diện của X trong tọa độ cực. Hàm cmath.polar [] được sử dụng để chuyển đổi một số phức thành tọa độ cực. & nbsp;

    Python3

    import cmath

    num = cmath.polar[

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    0
    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    1

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    2
    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    3

    Độ phức tạp về thời gian: O [1]

    Không gian phụ trợ: O [1]

    2. Cmath.phase [Z]: Phương pháp này trả về pha của số phức Z [còn được gọi là đối số của Z].This method returns the phase of complex number z[also known as the argument of z].

    Python3

    import cmath

    num = cmath.polar[

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    0
    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    1

    Độ phức tạp về thời gian: O [1]

    Không gian phụ trợ: O [1]

    2. Cmath.phase [Z]: Phương pháp này trả về pha của số phức Z [còn được gọi là đối số của Z].

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    6=
    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    8
    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    9

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

    The phase of complex number is : 3.141592653589793

    The phase of complex number is : 3.141592653589793
    3=
    The phase of complex number is : 3.141592653589793
    5
    The phase of complex number is : 3.141592653589793
    6

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    2
    The phase of complex number is : 3.141592653589793
    8
    The phase of complex number is : 3.141592653589793
    9
    Absolute value of 3 + 4j is: 5.0
    0=
    Absolute value of 3 + 4j is: 5.0
    2
    This method returns the modulus [absolute value] of complex number z.

    Python3

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    2
    Absolute value of 3 + 4j is: 5.0
    4

    Đầu ra

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

    Absolute value of 3 + 4j is: 5.0

    The phase of complex number is : 3.141592653589793
    3=
    The phase of complex number is : 3.141592653589793
    5
    The phase of complex number is : 3.141592653589793
    6

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    2
    The phase of complex number is : 3.141592653589793
    8
    The phase of complex number is : 3.141592653589793
    9
    Absolute value of 3 + 4j is: 5.0
    0=
    Absolute value of 3 + 4j is: 5.0
    2

    Python3

    import cmath

    num = cmath.polar[

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    0
    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    1

    import math
    def polar[z]:
        a= z.real
        b= z.imag
        r = math.hypot[a,b]
        theta = math.atan2[b,a]
        return r,theta # use return instead of print.
    
    u=3+5j
    print polar[u]
    
    2
    The phase of complex number is : 3.141592653589793
    8[5.830951894845301, 1.0303768265243125]4import9


    Độ phức tạp về thời gian: O [1]

    Phương pháp cmath.polar [] chuyển đổi một số phức thành tọa độ cực.Nó trả về một tuple của mô đun và pha.Trong tọa độ cực, một số phức được xác định bởi mô đun r và góc pha PHI. polar[] method converts a complex number to polar coordinates. It returns a tuple of modulus and phase. In polar coordinates, a complex number is defined by modulus r and phase angle phi.

    Làm thế nào để bạn tính toán dạng cực?

    Để viết các số phức ở dạng cực, chúng tôi sử dụng các công thức x = rcosθ, y = rsinθ và r = √x2+y2.then, z = r [cosθ+isinθ].x=rcosθ, y=rsinθ, and r=√x2+y2. Then, z=r[cosθ+isinθ].

    Làm thế nào để bạn viết tưởng tượng tôi trong Python?

    Trong Python, biểu tượng J được sử dụng để biểu thị đơn vị tưởng tượng.the symbol j is used to denote the imaginary unit.

    Chủ Đề