Introduction to Integration

Introduction to Integration#

Integration is the opposite of differentiation, so it helps us find the answer to the question:

Suppose we have \(\frac{dy}{dx} = 2x\), then what is \(y\)?

From the previous section, we know the answer is \(x^2+C\), where \(C\) is a constant. So we would say that \(2x\) integrated is \(x^2+C\).

Graphically, we know differentiation gives us the gradient of a curve. Integration finds the area beneath a curve.

Hide code cell source

import numpy as np
import matplotlib.pyplot as plt 

x = np.linspace(0, 6, 100)
y = np.sin(x) + 4

x_rect = np.arange(0.5, 5.5, 0.5)

fig, ax = plt.subplots()
ax.plot(x, y)
ax.bar(x_rect, np.sin(x_rect) + 4, width=x_rect[1] - x_rect[0], 
       alpha=0.5, align='edge', ls='--', edgecolor='black')
ax.set_xticks([0.5, 5.5])
ax.set_xticklabels(['$a$', '$b$'])
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
ax.set_ylim(0, None)
ax.text(3.5, 4.5, '$y=\sin(x) + 4$')
plt.show()
../_images/9e91aa20ca93a33b8d2c340c4bec0beeaaf7a51682d5fa73026c34bea3f4712b.png

Suppose we wish to find the area under the curve between the \(x\) values \(a\) and \(b\) shaded in the graph above. Then we could find an approximate answer by creating the dashed retectangles above and summing their area.


We can use Python to perform this computation, it is known as a Reimann sum. To find a Reimann sum, the equation, \(y=\sin{(x)} + 4\) is computed for each of the rectangles above.

y_rect = np.sin(x_rect) + 4
y_rect
array([4.47942554, 4.84147098, 4.99749499, 4.90929743, 4.59847214,
       4.14112001, 3.64921677, 3.2431975 , 3.02246988, 3.04107573])

Next, we compute the area for each of the rectangle.

areas = y_rect * (x_rect[1] - x_rect[0])
areas
array([2.23971277, 2.42073549, 2.49874749, 2.45464871, 2.29923607,
       2.07056   , 1.82460839, 1.62159875, 1.51123494, 1.52053786])

And finally a summation is found.

np.sum(areas)
20.461620486839937

So an estimate of the integral of \(y=\sin{(x)} + 4\) is approximately 20.46 (to 2 s.f.).


We can see that this coarse representation would not give a perfect answer, however, the smaller the width of the rectangles, the better the estimation of the integral would be.

So if we could use rectangles of an infinitely small width we would find an answer with minimal error. This is what integration does. It creates an infinite number of rectangles under the curve all with an infinitely small width and sums their area to find the area under the curve.

Hide code cell source

x = np.linspace(-6, 6, 100)
y = x ** 2 - 2

fig, ax = plt.subplots()

ax.plot(x, y)
ax.fill_between(x, 0, y, where=(x >= -1.51) & (x <= 5), alpha=0.5)
ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
plt.show()
../_images/1e613e63faf7a9f23921fa3d93e5d9758ab9ac6bec95a822180a7040486bd0e7.png

So integration could be used to find the area shaded on the graph of \(y = x^2-2\) above. Note that when the curve is below the \(x\)-axis, integration finds the area bounded between the curve and the \(x\)-axis.

Notation#

We use the fact that \(2x\) integrated is \(x^2+C\) to help introduce the following notation for integration. If we want to integrate \(2x\), we write this as:

\[ \int 2x\;dx = x^2+C \]
  • The \(\int\) tells us we need to integrate.

  • The \(dx\) tells us to integrate with respect to \(x\). So we could write \(\int 2z\;dz = z^2 + C\), but in this case we have integrated with respect to \(z\).

  • We call \(\int 2x\;dx = x^2+C\) the integral.

Another notation often used is the following, if we have the function \(f(x)\), then we write this integrated as \(F(x)\). So if \(f(x) = 2x\), then \(F(x) = x^2+C\).

Integration finds the area under the curve. So if we want to find the area between two points (called limits) on the \(x\)-axis, say \(a\) and \(b\), we use the following notation:

\[ \int^a_b = f(x)\;dx \]

This tells us we want to find the integral of \(f(x)\) and then use that information to find the area under the curve between \(a\) and \(b\). We find this area using the formula below:

\[ \int^a_b = f(x)\;dx = F(b) - F(a) \]

This is explained in detail in the section on definite integrals.

  • When we are given limits, then we have a definite integral.

  • When we are not given limits, then we have an indefinite integral.

Rules for Integrals#

  1. We can split integrals over a sum. For example

    \[ \int (x^2+2x+7)\;dx = \int x^3\;dx + \int 2x\;dx + \int 7\;dx \]
  2. We can take constants out of the integral. For example

    \[ \int 6x^4 \;dx = 6\int x^4\;dx \]