编程语言如何实现复数的开方运算?

2014-12-29 11:14:05 +08:00
 juicy
最近看到了一个对复数开方的方法,例如运行

>sqrt(1 + 2i)

得到:

>1.272019649514069 + 0.7861513777574233i

当时就在想求复数开方是如何实现,于是在网上搜到了个方法

http://www.qc.edu.hk/math/Advanced%20Level/Finding%20the%20square%20root%20of%20a%20complex%20number.htm

编程语言应该不是通过上述方法来求解的吧,有做过研究的童鞋么?

我之前有写过一篇编程语言用牛顿迭代法实现实数的开方运算的方法

http://melon.github.io/blog/2014/11/25/recursive-algorithm-of-square-root/

但是如果换成复数,还能用这种方法?
2659 次点击
所在节点    分享发现
10 条回复
invite
2014-12-29 11:50:08 +08:00
matlab 吧。
ChanneW
2014-12-29 11:55:32 +08:00
```
a = 1+3j
b = a ** (0.5)

```
ruoyu0088
2014-12-29 12:04:29 +08:00
复数开平方就是模开平方,相角除以2,下面是演示代码:

import math
a = 1.0
b = 2.0
r = math.sqrt(math.hypot(a, b))
theta = math.atan2(b, a) * 0.5
print r * math.cos(theta), r * math.sin(theta)

sqrt, hypot, atan2, cos, sin都是C语言的标准库中间的函数。
IamI
2014-12-29 13:03:02 +08:00
Complex a + bi
a = rcosx
b = rsinx
(rcosx + irsinx)^n = r^n(cosnx+isinnx)
n = 1/2
IamI
2014-12-29 13:07:18 +08:00
n = p/q, 若q > 1
x = x + 2k * pi, k = 0, 1, ... q - 1
juicy
2014-12-29 13:08:05 +08:00
@IamI 恩,刚看到这公式
est
2014-12-29 13:17:14 +08:00
python

>>> (6.0+3.0j)**(1.0/3.0)
(1.863493910707937+0.29031663618281145j)
shmilyin
2014-12-29 18:10:34 +08:00
juicy
2014-12-29 19:37:32 +08:00
@shmilyin 不过这篇文章只讲了求实数的平方根
shmilyin
2014-12-29 21:45:03 +08:00
@juicy 抱歉,没看清

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/157510

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX