Exercise 1.38. In 1737, the Swiss mathematician Leonhard Euler published a memoir De Fractionibus Continuis, which included a continued fraction expansion for e - 2, where e is the base of the natural logarithms. In this fraction, the Ni are all 1, and the Di are successively 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, .... Write a program that uses your cont-frac procedure from exercise 1.37 to approximate e, based on Euler’s expansion.
根据描述,Euler’s continued fraction 公式为:
我们可以变一下,这样来想这个公式
fix this
(load "37-cont-frac.scm")
(load "../testframe.scm")
(let ((e-1
(/ 1
(cont-frac (lambda (i) 1.0)
(lambda (i)
(if (= (remainder i 3) 0)
(/ (* 2 i) 3)
1))
100)))
(e 2.7182818284590452353602874713))
(display (+ e-1 1))) ;Value: 2.7182818284590455
最后我们可以对 e - 1 求值,这个值加上 1 就是 e 的近似值
;Value: 2.7182818284590455