递归序列$ x_n = \ sqrt {2} $,$ x_ {n + 1} = \ sqrt {2x_n} $

时间:2014-02-20 02:01:08

标签: python math sequence

我如何在python中创建一个脚本,它来自递归序列的值:

$x_1 = \sqrt{2}$, $x_{n+1} = \sqrt{2x_n}$ http://www.sciweavers.org/upload/Tex2Img_1392861864/render.png

2 个答案:

答案 0 :(得分:2)

X = [sqrt(2)]
for i in range(1,10):
    X.append(sqrt(2*X[i-1]))

答案 1 :(得分:0)

这是一个缓慢的解决方案。假设n>> = 1

import math
def recursive(n):
    if n = 1:
        math.sqrt(2)
    return math.sqrt(2*recursive(n-1))