Monday, August 10, 2009

gsp trick - shading areas using iteration

Using Iteration to Shade Areas in Sketchpad

These directions should assist in the construction of a trapezoidal estimate of the area under a function f(x) on an arbitrary x-interval (a,b).

1: Begin by plotting the new function f(x) = (x^2)/8. A function that is linear or very steep will not be helpful in the trouble-shooting of this type of construction. The function can be changed after the construction. Create a parameter (t[1] in the diagram) and give it a value of 5. This parameter will be used to define the number of sub-intervals of area. The value can be changed later to produce a better-fitting area estimate, but if it is too big, the widths will be inconveniently small during the rest of the construction process. Create a second parameter equal to t[1]-1. This will be the number of times that we want to iterate the first trapezoid, since the original trapezoid will not be part of the iteration. Create a third parameter equal to 1/t[1]. This will be the width of each interval. Next, create two independent points (A and B in the diagram below).

2: Select both points A and B and the x-axis and construct parallel (horizontal) lines through the points. Next, select both points and the x-axis and construct perpendicular lines through the points, as shown. Create the intersection C (as shown) and dilate that point by a factor of 1/t[1] with A as the center. Mark the vector from A to the dilated point. Now create a point D on the vertical line passing through A and translate D by the marked vector. D is the point we will iterate, and any structure dependent on D will be iterated to the specified depth.

3: Select D and the translation of D (Sketchpad will call this D') and go to "Measure" - "Abscissa (x)". It will create two new measurements, the x-values of each point. Now "Calculate" f(x[D]) and f(x[D']). Plot the two points ( x[D], f(x[D]) ) and ( x[D'], f(x[D']) ). Create a new parameter with value 0 and plot the two points ( x[D], 0 ) and ( x[D'], 0 ). These four plotted points are the vertices of our first trapezoid.

4: Create a quadrilateral interior using the four plotted points. Now select the point D and the parameter t[1]-1. Click "Transform", hold down the shift key and select the "Iterate To Depth" option that will appear. The pre-image D should be sent to D' in order to construct the iteration. I generally go into the structure menu and tell it to iterate "Non-Point Images Only" and I un-check "Tabulate Iterated Values".

5: Now the construction is in place and the function can be changed. The number of intervals can be changed (just change t[1] and the other parameters will respond accordingly) to give a smoother picture.

6: To shade the area between two functions, use the points ( x[D], g(x[D]) ) and ( x[D'], g(x[D']) ) instead of ( x[D], 0 ) and ( x[D'], 0 ).

7: One of the most common mistakes that I make is to iterate A, the point which determines the width of the interval. As the width of each trapezoid is a fraction of the horizontal distance between A and B, this will decrease with each iteration. First it will use AB/t[1], then A'B/t[1], then A''B/t[1]... and the iterated image will never get all the way across the interval. Instead iterate D, which will not change the distance between A and B, so the intervals will have constant width.

Note: This method creates an area that stretches and conforms predictably to any adjustment of the axes. I have made tools for this (available in some of the sketches on this page) and it should be noted that there are some complications regarding the square/rectangular axes when you try to generalize this process as a tool. This is because one sketch may contain multiple coordinate systems.

keywords: gsp, geometer's sketchpad, iteration, shaded area, integral area, integration, iterative, iterate, trapezoidal area approximation, step-by-step, tutorial, iterate to depth


  1. A terrific approach. Just what I was looking for for a sketch I was making. Any idea how to sum the areas?

  2. Yes, the last person has a good question. How do we now get the sum of the areas???

  3. The sum of the areas can be obtained by following directions in the sample sketches that come with Sketchpad.

    It's a pretty clever trick, really. It involves translating an independent point up (for example) by a unit distance numerically equivalent to the area of the iterated rectangle or trapezoid. This gives a vertical column of iterated points, the terminal point of which can be selected using the Transform menu, with the set of points selected. The original (independent) point and the terminal iterated point have y-values whose difference is the total area estimate.