Mini-Project
for
Calculus and Mathematica
Workshop

Name:  Don Anglen

Title:   Area Under a Curve

Description:  This lesson graphs trapezoids under a parabola
 to compare areas.  It explains some Mathematica  language,also.

Area Under a Curve

We will use the Package called (Needs Graphics Filled Plot).

Needs["Graphics`FilledPlot`"]

The equation of a parabola can be written in the form 
   y = ax€ + bx + c.  As a function it can be written
   f(x) = ax€ + bx + c.  We will use the parabola y = -3x€ + 7x
   most frequently unless we change the parameters "a", "b", and
   "c".  This paragraph is in "text" style:  no operations will
   perform.

This is an "input" cell:  operations will occur.

The ] on the right side of the screen are called "cells".  Each 
   cell is used for different outputs or operations.

Now we will look at a program and then explain it.

Clear[a,b,c,f,x,y]
f[x_] = a x^2 + b x + c
a = -3
b = 7
c = 0
Solve[f[x]==0,x]

{{x -> 0}, {x -> 7/3}}

The "Clear" command cleared the variables.  The second
   
   line is the command for a function.  In Mathematica. in
   
   order to multipley b times x, a space is needed.  The
   
   "^" is the command for a power of a number.  The fifth
   
   line will solve for x in the function.  Mathematica needs
   
   a "==" to solve the equation.  The ",x" means with respect
   
   to x.  The output is the ordered pair (0, 7/3).  These are
   
   the two points where the parabola will cross the x-axis.

We will find the area between the parabola and the x-axis.

First let's look at the graph.

Plot[f[x],{x, -1, 3}]

The "Plot" command plots the curve of the function f(x) from
   
   x = -1 to x = 3.  The commands in Mathematica start with a
   
   capital letter.

Plot[f[x],{x, -1, 3},
PlotRange->{-2,5}]

The second command gives the range of y from -2 to 5.

Plot[f[x],{x, -1, 3},
PlotRange->{-2,5},
AspectRatio->Automatic]

To make the difference between the units of the x and y axis 
   the same, Mathematica  has a command for that.

Plot[f[x],{x, -1, 3},
PlotRange->{-2,5},
AspectRatio->Automatic,
PlotStyle->{RGBColor[1,0,0]}]

There are several additional commands you could use next
   if you wish.  One would be color.

One way to find the area between the parabola and the positive 
x axis is to integrate the function between the two points on the                      
x axis where the curve intersects it.  These two points are the
roots of the function.  Solve for x.  -3 x€ + 7 x = 0.

Solve[-3 x^2 + 7 x == 0,x]

x = 0, x = 7/3

Connect some points on the curve.

Clear[f,x,jump]
f[x_]= -3 x^2 + 7 x; 
n=4;
functionplot=Plot[f[x],{x,0,7/3},
DisplayFunction->Identity];
jump := (7/3)/n; 
points = Table[{x,f[x]},{x,0,7/3,jump}];
pointplot = ListPlot[points, 
PlotStyle->{RGBColor[1,0,0]}, DisplayFunction->Identity];
brokenlineplot = Graphics[Line[points]];
Show[functionplot,pointplot,brokenlineplot,
DisplayFunction->$DisplayFunction];

Would you like to see a trapezoid under the parabola?  Of
   course!

Clear[trap]
trap[x_]:=Graphics[{GrayLevel[.75],
Polygon[{{x,0},{x,f[x]},
{x+jump,f[x+jump]},{x+jump,0}}]}]
Show[trap[2jump],functionplot,brokenlineplot,
Ticks->{{2jump,3jump},Automatic},
Axes->True];

You're just dying to see several trapezoids under the curve; 
   right?

Clear[trap]
trap[x_]:=Graphics[{GrayLevel[.75],
Polygon[{{x,0},{x,f[x]},
{x+jump,f[x+jump]},{x+jump,0}}]}]
Show[Table[trap[x],{x,0,7/3 - jump, jump}]];

How about finding the area of the sum of these trapezoids?
   Sure!

Clear[n,area]
jump := (7/3)/n; 
area[n_] = Sum[jump (f[x] + f[x + jump])/2,
              {x,0,7/3-jump,jump}]

area[4]

The command "N" will approximate this to a decimal.

N[area[4]]

5 trapezoids?  Substitute "5" in for "n".

N[area[5]]

The area is getting closer to the area of the
   parabola.

Let's find the area under the parabola.  It should be 
   a little more than the sum of the areas of the trapezoids.

Integrate:
     ¶ ÷ £                                                                                                                                                                                                     
   #º   (-3x€ + 7x)  dx                        =

¶ ÷ £
      [ -x‹ + (7/2)x€  ]                 =
                                   0

[ -(7/3)‹ + (7/2)(7/3)€ ] - [ -(0)‹ + (7/2)(0)€ ] =
    [ -(343/27) + (343/18) ] =
    ( -686 + 1029 ) / (54) =
    343/54

Mathematica can integrate for you.

Integrate[-3 x^2 + 7 x, {x, 0, 7/3}]

Voila!

Now let's compare areas.  The areas of 100 trapezoids
   and the area under the curve.

N[area[100]]

NIntegrate[-3 x^2 + 7 x, {x, 0, 7/3}]

With 100 trapezoids, it's getting closer.

Try different values for a, b, and c in the parabola
ax€ + bx + c = 0.