递归计算Ramanujan无穷根式

拉马努金无穷根式是印度数学家拉马努金(Srinivasa Ramanujan)于20世纪初提出的。

f(x) = sqrt(1 + (x + 1) * f(x + 1))

上面的函数是一个递归式,下面用Python编程计算该函数的值。

Python代码:

import math
class Ramanujan(object):
    def sum(self, d, md):
        if d > md:
            return 0
        return math.sqrt(1 + (d + 1) * self ...

继续阅读

年度归档