Submitted to HEJ
Manuscript no.: ANM-010201-A
Articles Frontpage previous next

Introduction

Problem: Let $f$ be a positive valued (bounded) function on a closed (finite) interval $[a,b]$ of the real numbers. Compute the area of the region in the $x,y$ plane bounded by the graph of $f$, the $x$-axis and the straight lines $x=a,\ x=b$.

EXAMPLE 1.1.

$\scriptstyle>$ f:=x->x*sin(x)^2;


\begin{displaymath}f := x\rightarrow x\,{\rm sin}(x)^{2}\end{displaymath}

$\scriptstyle>$ plot(f(x),x=1..3,y=0..2,scaling=CONSTRAINED);

 
Figure 1:
\includegraphics[width=12cm]{int01.ps}

For ``general'' functions this looks like a hard problem. However, for some types of special functions (e.g. linear functions) the problem is easy. Let us look at stepfunctions. A stepfunction $g$ on $[a,b]$ is given by a subdivision of $[a,b]$, i.e. a finite sequence of numbers $a = a_0\leq a_1\leq \ldots \leq a_n=b$ and function values $v_1,\ldots,v_n$ such that $g(x) = v_i$ for all $x$ such that $a_{i - 1}<x\leq a_i$ for all $i$, whereas $g(x)=0$ for all $x\leq a$ and $x>b$.

Since stepfunctions play an important role we introduce the procedure stepfunction to produce them. It has two arguments, a subdivision $S$ and a list of function values $V$. With the notations above $S=[a_{0},\ldots,a_{n}]$ and $V=[v_{1},\ldots,v_{n}]$.

EXAMPLE 1.2.

$\scriptstyle>$ S:=[3,3.7,5,6.2,7.1,8]: V:=[2.5,-1,4.2,3,-2]:

$\scriptstyle>$ g:=stepfunction(S,V):

$\scriptstyle>$ plot(g,x=0..10,scaling=CONSTRAINED);

 
Figure 2:
\includegraphics[width=12cm]{int02.ps}

For positive stepfunctions the solution to the area problem is immediate and given by the formula

\begin{displaymath}\sum _{i=1}^{n}\,({a_{i}} - {a_{i - 1}})\,{v_{i}}.\end{displaymath}

Note that this formula makes sense for general stepfunctions: the resulting number represents the area above the $x$-axis minus the area below the $x$-axis. The procedure int_step yields the above sum for given $S$ and $V$.

EXAMPLE 1.3.

For the stepfunction $g$ in Example 1.2. the area under the graph of $g$ is

$\scriptstyle>$ int_step(S,V);


\begin{displaymath}
6.39
\end{displaymath}

Now back to the problem for general functions. The idea is to approximate such a function $f$ by stepfunctions. E.g., a continuous function can be well approximated with constant on sufficiently small intervals. Let us look at the function $f$ of Example 1.1.

EXAMPLE 1.4.

Take a regular subdivision of $[a,b]$, i.e. a subdivision into $n$ subintervals of equal length.

$\scriptstyle>$ f:=x->x*sin(x)^2:

$\scriptstyle>$ n:=10:

$\scriptstyle>$ S:=[seq(1.+2*`i`/n,`i`=0..n)];

\begin{eqnarray*}
\lefteqn{S := [1., \,1.200000000, \,1.400000000, \,1.600000000...
...00000, \,2.600000000, \,2.800000000, \,3.]
\mbox{\hspace{178pt}}
\end{eqnarray*}



For the value of the stepfunction on $[a_{i - 1},a_{i}]$ we choose $f(a_{i})$. Hence

$\scriptstyle>$ V:=[seq(f(S[`i`]),`i`=2..n+1)];

\begin{eqnarray*}
\lefteqn{V := [1.042436229, \,1.359555639, \,1.598635820, \,
1...
....6909283272, \,.3142077702, \,
.05974457007]\mbox{\hspace{20pt}}
\end{eqnarray*}



$\scriptstyle>$ g:=stepfunction(S,V):

$\scriptstyle>$ plot(\{f(x),g(x)\},x=1..3);

 
Figure 3:
\includegraphics[width=12cm]{int03.ps}

This plot shows the function $f$ and its approximating stepfunction $g$. Some daemon (in fact Maple's procedure int) tells us that the area under the graph of $f$ equals to $2.264846340$ whereas the area under the graph of $g$ is given by

$\scriptstyle>$ int_step(S,V);


\begin{displaymath}
2.191860385
\end{displaymath}

which can be rounded to $2.192$. Neither very good nor totally bad as an approximation. We can get a better approximation by increasing the number of subintervals:

$\scriptstyle>$ n:=50: S:=[seq(1.+2*`i`/n,`i`=0..n)]:

$\scriptstyle>$ V:=[seq(f(S[`i`]),`i`=2..n+1)]:

$\scriptstyle>$ g:=stepfunction(S,V):

$\scriptstyle>$ plot(\{f(x),g(x)\},x=1..3,numpoints=500); g:='g':

 
Figure 4:
\includegraphics[width=12cm]{int04.ps}

$\scriptstyle>$ int_step(S,V);


\begin{displaymath}
2.251554949
\end{displaymath}

rounded to $2.252$, a much better approximation.

Exercise 1.1.

Consider the function

\begin{displaymath}f\ :\ x\rightarrow \sqrt{1 - x^{2}}.\end{displaymath}

The region under the graph of $f$ between $x=0,\ x=1$ is a $90$ degree circle sector. Hence the area equals to $\pi/4$. Use the above method of approximation by regular stepfunctions to find an approximation of $\pi$. How many subintervals are needed to approximate $\pi$ with an error less then or equal to $1/50$?

The Maple package ``student'' contains the functions leftsum and rightsum, which are in case of regular subdivision the same as the function int_step. I.e., the function leftsum (rightsum) computes a numerical approximation to a definite integral using rectangles. The height of each rectangle is determined by the value of the function at the left (right) side of each subinterval. A graph of the approximation can be obtained by the Maple procedure leftbox (rightbox).

Exercise 1.2.

Approximate the function

\begin{displaymath}f(x) = \sqrt{1 + x^{3}}\end{displaymath}

on the intarval $[4,6]$ by regular stepfunctions using the procedure
  • leftsum,
  • rightsum
with an error less than $0.01$. How many subintervals were needed in each case?

Submitted to HEJ
Manuscript no.: ANM-010201-A
Articles Frontpage previous next