Exercise 1.44
The idea of smoothing a function is an important concept in signal processing. If f f f is a function and d x dx dx is some small number, then the smoothed version of f f f is the function whose value at a point x x x is the average of f ( x − d x ) , f ( x ) , a n d f ( x + d x ) f(x-dx), f(x), and f(x+dx) f(x−dx),f(x),andf(x+dx). Write a procedure s m o o t h smooth smooth that takes as input a procedure that computes f f f and returns a procedure that computes the s m o o t h e d f smoothed\ f smoothed f. It is sometimes valuable to repeatedly smooth a function (that is, smooth the smoothed function, and so on) to obtain the n − f o l d s m o o t h e d f u n c t i o n n-folds\ moothed\ function n−folds moothed function. Show how to generate the n n n-fold smoothed function of any given function using s m o o t h smooth smooth and r e p e a t e d repeated repeated from Exercise 1.43.
这道题难度不大,smooth 函数返回一个计算3个数平均值的 lambda 函数就行。
(define dx 0.0001)
(define (smooth f)
(lambda (x) (/ (+ (f (- x dx))
(f x)
(f (+ x dx)))
3)))
(define (n-fold-smooth f n)
(repeated f n))
((smooth square) 5)
((smooth inc) 5)
((n-fold-smooth square 2) 5)
((n-fold-smooth inc 10) 5)
; 执行结果
25.000000006666667
6.0
625
15