[plt-scheme] HtDP Exercise 23.4.1

From: Thomas Chust (chust at web.de)
Date: Wed Feb 11 09:15:36 EST 2009

2009-02-10 David Yrueta <dyrueta at gmail.com>:
> [...]
> (define (integrate-kepler f left right)
>   (local ((define (area-of-trap a b1 b2)
>             (* a  ( / ( + (f b1) (f b2)) 2)))
>           (define midpoint ( / (+ right left) 2))
>           (define alt-left (- midpoint left))
>           (define alt-right (- right midpoint)))
>     (+ (area-of-trap alt-left left midpoint)
>        (area-of-trap alt-right midpoint right))))
> Am I in the ballpark?
> [...]

Hello David,

this implementation of the integration function looks good. As
Matthias said, thinking about some tests could help you convince
yourself that it is correct ;-)

For example, the procedure should yield exact results for any linear
function (ie. any function of the form (lambda (x) (+ a (* b x))) with
arbitrary real a and b)...

cu,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.


Posted on the users mailing list.