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
2import 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]
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
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
2import 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]
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]
0import 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]
1import 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]
2import 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]
0import 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]
8import 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]
9The 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
5The phase of complex number is : 3.141592653589793
6
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]
The phase of complex number is : 3.141592653589793
8The phase of complex number is : 3.141592653589793
9Absolute 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.04
Đầ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.1415926535897933
=
The phase of complex number is : 3.1415926535897935
The phase of complex number is : 3.1415926535897936
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]
The phase of complex number is : 3.141592653589793
8The phase of complex number is : 3.141592653589793
9Absolute 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]
0import 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]
1import 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]
2The phase of complex number is : 3.1415926535897938
[5.830951894845301, 1.0303768265243125]
4import
9