#lang Racket (define (cont-frac N D k) (define (cf T) (if(= t1) (/(N t) (D T)) (/(N T) (+ (D t) (cf (-t1)))) );if); CF (cf K)); Cont-frac (define (cont-frac-Iteration N D k) (define (cf result T) (if(=t k) result (cf (/(N T) (+ (D t) result)); (+ t1) ; cf);if); CF (CF (/(N k) (D K))1)); Cont-frac-Iteration (cont-frac (Lambda (i)1.0) (Lambda (i)1.0) Ten) (cont-frac-iteration (Lambda (i)1.0) (Lambda (i)1.0) Ten)
Because the even fraction is essentially a division calculation sequence, the topic gives the k -term continuous fraction:
N1D1+N2?+NkDk
Can be converted to the following equivalent division calculation sequence:
N1/(D1+(N2/ (D 2+ ? + (nk /dk) ) ) )
And this division sequence can be represented by a recursive expression:
CF(1) N1/(D1+cF(2)) N1/(D1+ (n2 / (d2+cf< Span id= "mathjax-span-169" class= "Mo" > (3 ) ) ) Span id= "mathjax-span-174" class= "Mo" >) N1/(D1+(N2/(D2+(n3/ ( d3+cf (4< Span id= "mathjax-span-216" class= "Mo" >) ) ) ) ) Span id= "mathjax-span-221" class= "Mo" >) ?N1/(D1+(N2/(D2+(N3/(d3 +? + (nk/ dk) ) ) ) Span id= "mathjax-span-279" class= "Mo" >)
Where the function cF(i) denotes the first item of the continuous fraction .
sicp:1.37 recursive/iterative algorithm for infinite continuous fraction