Optional Project 26: Area Under a Curve

Area under a Curve

 

In the broadest sense, Calculus is mostly concerned with two concepts: instantaneous rate of change and the area under a curve.

 

 

Suppose we wanted to know the area under the function f(x) = 2x from x = 1 to x = 3.

In this case, we can use basic geometry (area of a rectangle and triangle or area of a trapezoid) to calculate the area under the curve.

The area of the square is 4 sq. units (2x2).

 


 

However, if we wanted to calculate the area under the curve shown below, we can’t use a geometry formula….

OR CAN WE…

 

We can actually split the region up into many rectangles and calculate the sum of the rectangle areas to obtain an estimate of the area under the curve.

 

Let’s use the example 

and calculate the area from x = 1 to x = 6. 

We can split the region up into 5 rectangles.  Each rectangle will have base width = 1.  The height of the rectangle will be determined by the output of the function. 

Calculations:

 

All Rectangles have a base width of 1.  So the area of each rectangle is equal to the height of the rectangle (since area = b*h).


Green Rectangle:   Height = .1(1.5)^2+.3(1.5) = .675.  Area = .675 sq. units

Pink Rectangle:      Height = .1(2.5)^2+.3(2.5) = 1.375.  Area = 1.375 sq. units

Gray Rectangle:     Height = .1(3.5)^2+.3(3.5) = 2.275.  Area = 2.275 sq. units

Orange Rectangle: Height = .1(4.5)^2+.3(4.5) = 3.375  Area = 3.375 sq. units

Brown Rectangle:  Height = .1(5.5)^2+.3(5.5) = 4.675.  Area = 4.675 sq. units

 

Area Estimate: .675 +1.375 + 2.275 + 3.375 + 4.675 = 13.375 sq. units

 


Note: This process is called a midpoint Riemann sum.  This is because we use the midpoint of each interval to calculate the height of the rectangle.  You can also use the left endpoint or right endpoint to calculate the height as shown below.

We called the previous example an estimate of the area under the curve.  This is because the sum of the area of the rectangles is not exactly equal to the area under the curve.  However, if we use MORE RECTANGLES we can estimate the area under the curve more accurately.  The two graphs below show estimates of the area under a curve (different function) using 4 vs. 8 rectangles.

If we can do hundreds (or thousands) of rectangles, the error will become negligible. 

 

Optional Project 26The variables (co, lowerX, upperX) have been initialized.  There is also a working method called getYPoly. 


co is the coefficients of the polynomial from least to greatest (0,3,.1 in the first example)

lowerX is the lower bound for the region we are finding the area of (1 in the first example)

upperX is the upper bound for the region we are finding the area of (6 in the first example)

getYPoly(co, x) returns the y-value for the polynomial at the given x.


Example: if co = {0, 3, .1), then getYPoly(co, 2.0) returns 1.0


Task: Use the logic of estimating this area by calculating the sum of rectangles with width .01 from the lower bound to the upper bound.  Appropriately initialize the value for 'area' that represents the area under the curve of the polynomial from lowerX to upperX.



Note: A better term for what we are finding is net area under a curve.  In other words, if the polynomial is completely below the x-axis between lowerX and upperX all those "areas" are negative since the y-coordinate is negative.  This is what we want; we are using the term area loosely there.

**If your code works for 5 test cases, you can enter your e-mail address

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0