sicp:1.37 recursive/iterative algorithm for infinite continuous fraction

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.