理系学生日記

おまえはいつまで学生気分なのか

問題1-44

平滑化関数を返す関数をつくるお。

(define dx 0.001)

(define (smooth f)
  (lambda (x)
    (/ (+ (f (- x dx))
	  (f x)
	  (f (+ x dx)))
       3)))

x^2の平滑化関数を使ってみる。

gosh> ((smooth square) 1)
1.0000006666666665

あんましおもしろくない。

n重平滑化関数 (n-fold smoothed function)をかく。

(define (n-fold-smooth f n)
  ((repeated smooth n) f))

したら、

gosh> ((n-fold-smooth square 5) 3.0)
9.000003333333332

やっぱしおもしろくない。