拉马努金无穷根式 是印度数学家拉马努金(Srinivasa Ramanujan)于20世纪初提出的。
f(x) = sqrt(1 + (x + 1) * f(x + 1))上面的函数是一个递归式,下面用python编程计算该函数的值。
Python代码: import mathclass Ramanujan(object):
def sum(self, d, md):
if d > md:
return 0
return math.sqrt(1 + (d + 1) * self.sum(d + 1, md))
使用matplotlib画出x取值范围[0, 50]时的散点图: Python代码: import matplotlib.pyplot as plt
r = Ramanujan()
y = [r.sum(1, x) for x in range(50)]
plt.title("Ramanujan infinite radicals")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.semilogx(y, 'bo')
plt.show()
观察可以发现函数值最后收敛于3,证明过程可以参阅:http://math.stackexchange.com/questions/7204/evaluating-the-nested-radical-sqrt1-2-sqrt1-3-sqrt1-cdots