The process of integration is about making the logical connection that the antiderivative of a function \(f\) does in fact lead to the exact area under the graph of \(f\). That’s what’s called the fundamental theorem of calculus

The Fundamental Theorem of Calculus

The area under the graph of a nonnegative continuous function \(f\) over an interval \([a, b]\) is determined as an area function \(A\), which is an antiderivative of \(f\); that is, \(\frac{d}{dx}A(x) = f(x)\). We use the areas of rectangles and triangles to find the area under the curve of constant functions (straight-line functions). We use Riemann sums to approximate the areas under curve-line functions.

Let \(f\) be any continous function over the interval \([a, b]\) and \(F\) be any antiderivative of \(F\). Then the definite integral of \(f\) from \(a\) to \(b\) is

\[\int_a^b f(x) dx = F(b) - F(a)\]

Evaluating these integrals is called integration.

Examples

Find the area under the graph of \(f(x) = \frac{1}{5} x^2 + 3\) over the interval [2, 5].

import sympy as sp
import numpy as np
import matplotlib.pyplot as plt

def f(x):
  return 1/5 * x**2 + 3
  
x = np.linspace(0, 10)

plt.plot(x, f(x))
plt.fill_between(x, f(x), where=[(x >= 2) and (x <= 5) for x in x], color="green", alpha=0.3)

x = sp.symbols("x")
sp.integrate(f(x), (x, 2, 5))
## 16.8000000000000

Find the area under the graph of \(f(x) = x^2 + 1\) over the interval [-1, 2].

def f(x):
  return x**2 + 1
  
x = np.linspace(-5, 5)

plt.plot(x, f(x))
plt.fill_between(x, f(x), where=[(x >= -1) and (x <= 2) for x in x], color="green", alpha=0.3)

x = sp.symbols("x")
sp.integrate(f(x), (x, -1, 2))
## 6

Evaluate \(\int_{-1}^{4} (x^2 - x)dx\).

x = sp.symbols("x")
antideriv = sp.integrate(x**2 - x, x)
antideriv
## x**3/3 - x**2/2
def f(x):
  return x**3/3 - x**2/2
  
x = np.linspace(-5, 10)
plt.plot(x, f(x))
plt.fill_between(x, f(x), where=[(x >= -1) and (x <= 4) for x in x], color="green", alpha=0.3)

x = sp.symbols("x")
sp.integrate(x**2 - x, (x, -1, 4)).evalf()
## 14.1666666666667

Evaluate the integral of \(\int_{-1}^{2}(-x^3 + 3x - 1)dx\).

x = sp.symbols("x")
antideriv = sp.integrate(-x**3 + 3*x - 1, x)
antideriv
## -x**4/4 + 3*x**2/2 - x
def f(x):
  return -x**4/4 + 3*x**2/2 - x
  
x = np.linspace(-5, 10)
plt.plot(x, f(x))
plt.fill_between(x, f(x), where=[(x >= -1) or (x <= 2) for x in x], color="red", alpha=0.3)

x = sp.symbols("x")
sp.integrate(-x**3 + 3*x - 1, (x, -1, 2)).evalf()
## -2.25000000000000

Total Profit from Marginal Profit

Northeast Airlines determines that the marginal profit resulting from the sale of \(x\) seats on a jet traveling from Atlanta to Kansas City, in hundreds of dollars, is given by

\[P^\prime(x) = \sqrt{x} - 6\] Find the total profit when 60 seats are sold.

def pprime(x):
  return np.sqrt(x) - 6

x = np.linspace(0, 80)

plt.plot(x, pprime(x))
plt.fill_between(x, pprime(x), where=[pprime(x) < 0 for x in x], color="red", alpha=0.3)
plt.fill_between(x, pprime(x), where=[pprime(x) > 0 for x in x], color="green", alpha=0.3)

# find the antiderivative, the profit at 60
x = sp.symbols("x")

# use sympy's square; numpy's breaks
P = sp.integrate(sp.sqrt(x) - 6, x)
P
## 2*x**(3/2)/3 - 6*x
P.subs({x:60}).evalf() * 100
## -5016.13323034067

Alternatively,

sp.integrate(sp.sqrt(x) - 6, (x, 0, 60)).evalf() * 100
## -5016.13323034067