sicp每日一题[1.44]

59 篇文章 0 订阅
14 篇文章 0 订阅

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(xdx),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 nfolds 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值