Exercise 3.82

1
2
3
4
5
6
7
8
9
(define (estimate-integral P x1 x2 y1 y2)
  (define experiment-stream
    (define test
      (lambda () (P (random-in-range (min x1 x2) (max x1 x2))
                    (random-in-range (min y1 y2) (max y1 y2)))))
    (cons-stream test experiment-stream))
  (let ((area (* (abs (- x2 x1)) (abs (- y2 y1)))))
    (stream-map (lambda (p) (* area p))
                (monte-carlo experiment-stream 0 0))))
Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 2.0 UK: England & Wales License.

Tags: ,

Leave a Reply

CAPTCHA Image

Powered by WP Hashcash

Please wrap all source codes with [code][/code] tags.