[plt-scheme] HtDP Exercise 23.4.1

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Feb 10 09:40:49 EST 2009

David, it is entirely safe to navigate around the mathematics  
sections in the book. As someone pointed out, they exist because it's  
so easy to use Scheme to bring across rather complex mathematical  
concepts. Indeed, you won't believe it but by reaching part VI, you  
have mastered a significant chunk of mathematics that you would have  
never considered within reach had I told you at the outset of your  
studies that you'd understand rudimentary concepts from "higher"  
algebra (advanced college material).

If you want to figure out some basics, try this.

  Can you draw the curve for (define (f x) x), (define (g x) 10), and  
(define (h x) (- 10 x)) between 0 and 10?

  Can you determine the area that is enclosed by f, g, and h, the X  
and Y axis between 0 and 10?

  If so, how did you compute those?

These are special cases for the exercise that you are tackling. If  
your solution comes close to your answers, you know it works for  
special cases. That's good. For somewhat more advanced uses, you  
would consider more sophisticated cases, such as sin, cos, expt, etc.  
In all those cases, mathematics tells you how to come up with a close- 
enough answer through a few calculations.

And that's the whole point of testing. You hope that it works for the  
rest of it.

Give it a try. -- Matthias

On Feb 9, 2009, at 9:47 PM, David Yrueta wrote:

> Hi Thomas --
> Thank you for the link.  I'm not familiar with the mathematical  
> notation used to represent the trapezoid rule function, but it  
> resembles Scheme enough to give me some clue on how to go forward.
> Here's my best effort at translation:
> For this problem, argument "a" signifies the x-axis coordinate for  
> the "left interval" and argument "b" signifies the x-axis  
> coordinate for "right interval."
> The length of each interval is equal to it's y-coordinate value,  
> which can be derived by applying function f to it's x-coordinate.  
> The length of each interval also equals the two base lengths of a  
> trapezoid.  The altitude of the trapezoid is equal to the  
> difference between the x-coordinate values of a and b.  So, if the  
> area of a trapezoid = altitude * ((base1+ base2) / 2), then the  
> formula for the area under the curve equals  [(b - a) * ((f a) + (f  
> b) / 2)].
> To calculate the areas for two trapezoids, one needs only to divide  
> the interval between a and b by 2, apply f to that value, and then  
> use the result as base2 for the trapezoid with (f a) as base1, and  
> base1 for the trapezoid with (f b) as base2.
> Does that sound about right?  If so, I'll translate it to Scheme.   
> Perhaps that would make my thoughts easier to evaluate.
> Thanks for the time!
> Thanks,
> Dave
> On Mon, Feb 9, 2009 at 5:33 PM, Thomas Chust <chust at web.de> wrote:
> 2009/2/10 David Yrueta <dyrueta at gmail.com>:
> > [...] Still don't really understand how this relates to the  
> question of computing the
> > "area of each trapezoid," though. [...]
> Hello,
> http://en.wikipedia.org/wiki/Trapezoidal_rule has some figures that
> may make the idea behind this integration method more clear: The graph
> of the function is approximated by a polyline -- in the special case
> of Kepler's rule a very coarse one with only two edges; the
> approximation of the integral is the area of the polygon bounded by
> this polyline, the two integration interval boundaries and the
> coordinate axis of the integration variable.
> cu,
> Thomas
> --
> When C++ is your hammer, every problem looks like your thumb.
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.