V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
juicy
V2EX  ›  分享发现

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

  •  
  •   juicy · 2014-12-29 11:14:05 +08:00 · 2655 次点击
    这是一个创建于 3407 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近看到了一个对复数开方的方法,例如运行

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

    但是如果换成复数,还能用这种方法?
    10 条回复    2014-12-29 21:45:03 +08:00
    invite
        1
    invite  
       2014-12-29 11:50:08 +08:00
    matlab 吧。
    ChanneW
        2
    ChanneW  
       2014-12-29 11:55:32 +08:00
    ```
    a = 1+3j
    b = a ** (0.5)

    ```
    ruoyu0088
        3
    ruoyu0088  
       2014-12-29 12:04:29 +08:00   ❤️ 1
    复数开平方就是模开平方,相角除以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
        4
    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
        5
    IamI  
       2014-12-29 13:07:18 +08:00
    n = p/q, 若q > 1
    x = x + 2k * pi, k = 0, 1, ... q - 1
    juicy
        6
    juicy  
    OP
       2014-12-29 13:08:05 +08:00
    @IamI 恩,刚看到这公式
    est
        7
    est  
       2014-12-29 13:17:14 +08:00
    python

    >>> (6.0+3.0j)**(1.0/3.0)
    (1.863493910707937+0.29031663618281145j)
    shmilyin
        8
    shmilyin  
       2014-12-29 18:10:34 +08:00   ❤️ 1
    juicy
        9
    juicy  
    OP
       2014-12-29 19:37:32 +08:00
    @shmilyin 不过这篇文章只讲了求实数的平方根
    shmilyin
        10
    shmilyin  
       2014-12-29 21:45:03 +08:00
    @juicy 抱歉,没看清
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2863 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 09:45 · PVG 17:45 · LAX 02:45 · JFK 05:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.