Integral calculus is mainly concerned with the area below the graph of a function. Let’s investigate that.

Geometry and Areas

The most common areas used in integration are triangles, \(A = \frac{1}{2} bh\), and rectangles, \(A = bh\), where \(b\) is the base, the \(x\)-axis, and \(h\) is the height, the \(y\)-axis.

def area(b, h, polygon="rectangle"):
  if polygon == "triangle":
    A = 1/2 * (b * h)
  else:
    A = b * h
  return A

Distance as Area

A vehicle travels at 50 mi/hr for 2 hr. How far has the vehicle traveled?

The intuition behind this is that we can take the area of the rectangle we get when inspecting the area under the function \(v(x) = 50\).

import matplotlib.pyplot as plt
import numpy as np

plt.axis([0, 10, 0, 100])
## [0, 10, 0, 100]
plt.axhline(50, ls="--", c="black")
plt.fill_between([0,2], [50])

area(2, 50)
## 100

Distance as Area II

The velocity of a moving object is given by \(v(x) = 3x\), where \(x\) is in hours and \(v\) is in miles per hour. Find the area under the graph (a) during the first 3 hr (b) between the third hour and the fifth hour.

def v(x):
  return 3 * x
  
x = np.arange(0, 10)
y = v(x)

plt.plot(x, y, c="black", ls="--")
plt.fill_between(x, y, where=x<3, interpolate=True)

We can interpret this as the area of a triangle, hence

area(3, v(3), "triangle")
## 13.5

In the second case

plt.plot(x, y, c="black", ls="--")
plt.fill_between(x, y, where=np.logical_and(x >= 3, x <= 5))

We can interpret this as the area of a triangle on top of a rectangle, hence

area(5 - 3, v(3)) + area(5 - 3, v(5) - v(3), "triangle")
## 24.0

Riemann Summation

To find the area under the graph of curved lines, over an interval \([a, b]\) we use Riemann sums which are a way to approximate areas using rectangles or trapezoids. These can be interpreted as subintervals \(\Delta x\), and the more of them we use, the more accurate our approximation becomes. The subintervals can be found with \(\Delta x = (b - a)/n\) where \(n\) is the number of subintervals we want to use. The area under the curve can be approximated with summation notation as

\[\sum_{i}^{n} f(x_i) \Delta x\]

Example

Let’s consider the graph of

\[f(x) = 600x - x^2\]

over the interval [0, 600].

  • Approximate the area by dividing the interval into 6 subintervals.
def f(x):
  return (600 * x) - x**2

def subint(a, b, n):
  return (b - a) / n
  
deltax = subint(0, 600, 6)
deltax
## 100.0
area = 0

for i in np.arange(0, 600, deltax):
  x = i
  area += f(x) * deltax

area
## 35000000.0

Definite Integrals

As the number of subdivisions (or subintervals) \(n\) increases, the width of each rectangle \(\Delta x\) decreases. If \(n\) is allowed to approach infinity, then \(\Delta x\) approaches 0, and the area approximation becomes more exact. The exact area under the graph of a continuous function over an interval is given by a definite integral.

Let \(y = f(x)\) be continuous and nonnegative, \(f(x) \geq 0\), over an interval \([a, b]\). A definite integral (or the area) is the limit as \(n \to \infty\) (equivalently, \(\Delta x \to 0\)) of the Riemann sum of the areas of rectangles under the graph of the function over that interval.

\[\lim_{\Delta x \to 0} \sum_{i=1}^{n} f(x_i) \Delta x\] or, in equivalent notation

\[\int_{a}^{b} f(x) dx\]