Area Between Curves

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

betCurves Package

Off[General::spell1];
Needs["Graphics`FilledPlot`"];
Needs["Graphics`Colors`"];
BeginPackage["AreabetweenCurves`"];

betCurves::usage = "leftcurves[f, g, n, {a, b}] approximates 
the area between two curves represented by the functions f and 
g in the interval from a to b by dividing the the x-axis 
into n rectangles.";

Begin["`Private`"];

betCurves[ f_, g_, n_, {a_, b_} ] :=
Module[ {dx, x, i, rectangles,rectangles1,rectangles2,
	min, max, curvef,curveg, poitns, areaapprox},
	dx = N[(b - a) / n] ;
	Do[
			x[i] = a + i dx,
			{i, 0, n} 
	] ;
	curvef={}; curveg={}; rectangles = {}; 
	rectangles1 = {}; rectangles2 = {};
	Do[
		min = Min[ f[x[i]], g[x[i]] ] ;
		max = Max[ f[x[i]], g[x[i]] ] ;
		AppendTo[ rectangles1, Line[{{x[i],min},
		{x[i+1],min}, {x[i+1],max},{x[i],max}, 
		{x[i],min}}] ] , {i, 0, n - 1}
	] ;
	rectangles1 = {rectangles1};
	
	Do[
			min = Min[ f[x[i]], g[x[i]] ] ;
			max = Max[ f[x[i]], g[x[i]] ] ;
			AppendTo[ rectangles2, Rectangle[ {x[i], min},
				{x[i+1], max} ] ], {i, 0, n - 1}
	] ;

	rectangles2 = {rectangles2} ;
	PrependTo[ rectangles2, GrayLevel[0.5] ];

	points = Table[{x, f[x]}, {x, a, b, 0.01 (b - a)} ] ;
	curvef = Map[ Line[#]&, {points} ] ;

	points = Table[{x, g[x]}, {x, a, b, 0.01 (b - a)} ] ;
	curveg = Map[ Line[#]&, {points} ] ;

	rectangles = {rectangles2,rectangles1,curvef,curveg}; 
	areaapprox =
		N[ Sum[ Abs[ f[x[i]] - g[x[i]] ] dx, 
		{i, 0, n-1} ], 10 ] ;
	Show[Graphics[ rectangles ], Axes-> Automatic] ;
	Print[ "Area of Rectangles = ", areaapprox ] ; ]

End[];


EndPackage[] ;

Notebook Overview

The area between two curves can be approximated by slicing it into strips (rectangles). For example, to approximate the area between the sine and cosine curves from Pi to - Pi, we can use 20 strips as shown below.

\(f[x_] := Cos[x]; 
g[x_] := Sin[x]; 
{a, b} = {\(-Pi\), Pi}; 

    FilledPlot[{f[x], g[x]}, {x, a, b}, 
      PlotStyle 
        -> {{Thickness[0.012], Red}, {Thickness[0.012], DarkGreen}}, 
      Fills -> {Blue}]; 
n = 20; 
betCurves[f, g, n, {a, b}]\)

The package curves[f, g, n, {a, b}] in the cell below will help you to approximate the area between curves given by f and g from a to b. By activating it and typing, curves[f, g, n, {a, b}] Mathematica will divide the area into n strips of width dx = (b-a)/n. The length of the slice with left point x is given by | f[x] - g[x] | so that its area is   | f[x] - g[x] |.dx . Hence, the sum of the areas of the strips approximates the area between curves given by f and g from a to b. The package also draws the strips and gives you the sum.

Note that the sum of the areas of the strips is a better and better approximation of the actual area if the width, dx, of the strips is taken smaller and smaller.

References to the Text

This NoteBook goes with Chapter 12 & 14 of the text.

Step-by-step

Find the area between the curves:

\(f[x_] := \@x\%3; 
g[x_] := x\^3; 
{a, b} = {0, 1}; 

    FilledPlot[{f[x], g[x]}, {x, a, b}, 
      PlotStyle 
        -> {{Thickness[0.012], Red}, {Thickness[0.012], DarkGreen}}, 
      Fills -> {Blue}]; 
n = 30; 
betCurves[f, g, n, {a, b}]\)

Practice Exercises

Find an integral expression for the bounded area between   y = f[x] (( = x)^4) - 1 and  y = g[x]  = x - (x^3).  Compare your answer to the drawings from the betCurves[.] function.

Here's a hint:

f[x_] := (x^4) - 1; \(g[x_] := x - x\^3; 
a\  = \ \(-2\); 
b\  = \ 2; 

    FilledPlot[{f[x], g[x]}, {x, a, b}, 
      PlotStyle 
        -> {{Thickness[0.012], Red}, {Thickness[0.012], DarkGreen}}, 
      Fills -> {Blue}]; 
Solve[f[x]\  == \ g[x]]\)

Example 12.3

Slice the region between the sine and cosine curves into rectangles and give a sum approximation for the area of one of these sectors.  Use Mathematica to compute your sum and use this package to verify that your formula is correct.

\(f[x_] := Sin[x]; 
g[x_] := Cos[x]; 
a\  = \ \(-6\); 
b\  = \ 6; 

    FilledPlot[{f[x], g[x]}, {x, a, b}, 
      PlotStyle 
        -> {{Thickness[0.012], Red}, {Thickness[0.012], DarkGreen}}, 
      Fills -> {Blue}]; \)

FindRoot[f[x] == g[x], {x, 1}]FindRoot[f[x] == g[x], {x, 4}]

f[(π/4)] == g[(π/4)]f[((5 π)/4)] == g[((5 π)/4)]

\(a\  = \ Pi/4; 
b\  = \ 5  Pi/4; 


    FilledPlot[{f[x], g[x]}, {x, a, b}, 
      PlotStyle 
        -> {{Thickness[0.012], Red}, {Thickness[0.012], DarkGreen}}, 
      Fills -> {Blue}]; 

    ∫\_a\%b\((Sin[x] - Cos[x])\) \[DifferentialD]x\)N[%, 10]betCurves[f, g, 20, {a, b}]

Exercises

Problem 14.4

Find an integral formula for the area between  y = (x^5) - (x^3)  and z = x - (x^3).  These curves cross at  x = -1,  x = 0,  x = +1.  Compute your integral(s) and use the betCurves[.] package to verify your answer.