1.29
1 (define (sum term a next b) 2 (if (> a b) 3 0 4 (+ (term a) 5 (sum term (next a) next b)))) 6 7 (define (cube x) 8 (* x x x)) 9 10 11 12 (define (integral f a b n) 13 (define (helper f a b n k) 14 (define (next k) 15 (+ a (* k (/ (- b a) n)))) 16 (cond ((= k n) (f (next k))) 17 ((= k 0) (+ (f (next k)) 18 (helper f a b n 1))) 19 ((= (remainder k 2) 0) (+ (* 2 (f (next k))) 20 (helper f a b n (+ k 1)))) 21 (else (+ (* 4 (f (next k))) 22 (helper f a b n (+ k 1)))))) 23 (/ (* (helper f a b n 0) (/ (- b a) n)) 3)) 24 25 26 27 ----- 出现 xxxx is not applicable 的错误, 有可能是由于把函数写成了中缀表达式的情况.
1.30
1 (define (sum term a next b) 2 (define (iter a result) 3 (if (= a b) 4 result 5 (iter (next a) (+ result 6 (term a))))) 7 (iter a 0))
1.31
---> 没必要写,和前面差不多
1.32
1 (define (accumulate combiner null-value term a next b) 2 (if (> a b) 3 null-value 4 (combiner (term a) 5 (accumulate combiner null-value term (next a) next b))))
1.33
----> 类似 不写了就...
时间: 2024-11-05 14:42:09