Exercise 1.44
The idea of smoothing a function is an important concept in signal processing. If f is a function and dx is some small number, then the smoothed version of f is the function whose value at a point x is the average of f(x-dx), f(x), and f(x+dx).Write a procedure smooth that takes as input a procedure that computes f and returns a procedure that computes the smoothed f . It is sometimes valuable to repeatedly smooth a function (that is, smooth the smoothed function, and so on) to obtain the n-folds moothed function. Show how to generate the n-fold smoothed function of any given function using smooth and 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
标签:function,每日,smooth,sicp,fold,dx,1.44,smoothed,define
From: https://www.cnblogs.com/think2times/p/18396018