|
|||
|
Hi,
"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." [1] Solution: [2] (define (cont-frac n d k) **(define (iter i sub-expr) ****(if (= i 0) ********sub-expr ********(iter (- i 1) (/ (n i) (+ (d i) sub-expr))))) **(iter (- k 1) (/ (n k) (d k)))) (define (e k) **(+ (cont-frac (lambda (i) 1.0) ************ (lambda (i) (if (= (remainder (+ i 1) 3) 0) **************************** (* 2 (/ (+ i 1) 3)) **************************** 1.0)) ************ k) **** 2)) This is a part which I don't understand: (if (= (remainder (+ i 1) 3) 0) **************************** (* 2 (/ (+ i 1) 3)) I'm not really good at math that's why I looked through some articles. But I haven't found anything similar to this conditions. Where did we get them? [1] http://mitpress.mit.edu/sicp/full-te...ml#%_sec_1.3.2 [2] http://www.kendyck.com/archives/2007...p-exercise-138 Thanks |
|
|
||||
|
||||
|
|
|
|||
|
On Friday, 10 August 2012 20:57:14 UTC-4, . wrote:
> Hi, > > > > "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." [1] > > > > Solution: [2] > > ... > This is a part which I don't understand: > > (if (= (remainder (+ i 1) 3) 0) > *** (* 2 (/ (+ i 1) 3)) > This expression generates the denominators for i=0,1,... The required values from the problem statement are: 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8, (Di) Notice that these are all 1 except for every third value after the 2nd. Visualising the sequence starting from i=0,1,..., we can see: i = 0 1 2 3 4 5 6 7 8 9 10 ... i+1 = 1 2 3 4 5 6 7 8 9 10 11 ... (i+1)%3 = 1 2 0 1 2 0 1 2 0 1 2 ... (remainder, r) (i+1)/3 = 0 0 1 1 1 2 2 2 3 3 3 ... (quotient, q) if we choose 2*q when r == 0, and 1 otherwise, we obtain the desired Di.. (My solution is here http://www.telegraphics.com.au/svn/p.../sicp/1-38.scm ) > ... > [1] http://mitpress.mit.edu/sicp/full-te...ml#%_sec_1.3.2 > > [2] http://www.kendyck.com/archives/2007...p-exercise-138 > > > > Thanks |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|