将复数转为极坐标值的 Python 程序


假设我们有一个复数 c,我们需要将其转换为极坐标(半径,角度)。复数的格式为 x + yj。半径是复数的模数,即 (x^2 + y^2) 的平方根。角度是从正 x 轴到线段 x + yj 与原点相连的逆时针角。从 cmath 库中,我们可以使用 phase() 函数来计算角度。复数上的 abs() 函数将返回模数值。

因此,如果输入如下所示 c = 2+5j,那么输出将为 (5.385164807134504, 1.1902899496825317)

为了解决这个问题,我们将按照以下步骤进行操作:-

  • 从 cmath 库中返回一个包含 (|c|, phase(c)) 的 pair

範例

让我们看看以下实现,以便更好地理解

Open Compiler
import cmath def solve(c): return (abs(c), cmath.phase(c)) c = 2+5j print(solve(c))

输入

2+5j

Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.

输出

(5.385164807134504, 1.1902899496825317)

更新于: 2021 年 10 月 12 日

346 次浏览

开始你的 职业

完成课程即可获得认证

开始学习
广告