Blob


1 ;; Exercise 1.30. The sum procedure above generates a linear recursion. The procedure can be rewritten so that the sum is performed iteratively. Show how to do this by filling in the missing expressions in the following definition:
3 (define (sum term a next b)
4 (define (iter a result)
5 (if (> a b)
6 result
7 (iter (next a) (+ (term a) result))))
8 (iter a 0))
10 (define (integral f a b dx)
11 (define (add-dx x) (+ x dx))
12 (* (sum f (+ a (/ dx 2.0)) add-dx b)
13 dx))
15 (define (cube x) (* x x x))
17 (define (test-case actual expected)
18 (load-option 'format)
19 (newline)
20 (format #t "Actual: ~A Expected: ~A" actual expected))
24 (test-case (integral cube 0.0 1.0 0.001) 0.25)