While derivatives break a function down into its local rates of change, integration builds it back up. Integration is the process of adding up infinitely many tiny pieces to find a whole.
1. The Definite Integral as a Sum
We define the definite integral as the signed area under the curve from to . Formally, this is reached through a Riemann Sum: we divide the area into rectangles and take the limit as .
Instead of just looking at the formula, let’s watch the approximation get better as we add more rectangles.
Interactive Lab
import numpy as np
import matplotlib.pyplot as plt
def f(x): return x * np.sin(x) + 2
a, b = 0, 10
n = 10 # Change this to 5, 20, or 100 to see convergence
x = np.linspace(a, b, 1000)
x_rect = np.linspace(a, b, n, endpoint=False)
width = (b - a) / n
plt.plot(x, f(x), 'k', linewidth=2)
plt.bar(x_rect, f(x_rect), width=width, align='edge', alpha=0.3, color='blue', edgecolor='b')
plt.title(f"Riemann Sum Approximation (n={n})")
plt.show()
python
1import numpy as np
2import matplotlib.pyplot as plt
3
4def f(x): return x * np.sin(x)+2
5
6a, b =0, 10
7n =10# Change this to 5, 20, or 100 to see convergence
Computer scientists rarely integrate by hand. They use algorithms like the Trapezoidal Rule, which fits a line (trapezoid) between points instead of a flat rectangle. This usually converges much faster.
Interactive Lab
import numpy as np
def f(x): return np.exp(-x**2) # The Gaussian bell curve
a, b = 0, 1
n = 5
h = (b - a) / n
x = np.linspace(a, b, n + 1)
y = f(x)
# Trapezoidal rule: h/2 * (y0 + 2y1 + ... + yn)
area = (h/2) * (y[0] + 2 * np.sum(y[1:-1]) + y[-1])
print(f"Estimated area under e^(-x^2) from 0 to 1: {area:.6f}")
print("This is related to the Error Function (erf) used in Statistics.")
python
1import numpy as np
2
3def f(x): return np.exp(-x**2)# The Gaussian bell curve
4
5a, b =0, 1
6n =5
7h =(b - a)/ n
8
9x = np.linspace(a, b, n +1)
10y = f(x)
11
12# Trapezoidal rule: h/2 * (y0 + 2y1 + ... + yn)
13area =(h/2)*(y[0]+2* np.sum(y[1:-1])+ y[-1])
14
15print(f"Estimated area under e^(-x^2) from 0 to 1: {area:.6f}")
16print("This is related to the Error Function (erf) used in Statistics.")
3. The Fundamental Theorem of Calculus (FTC)
The FTC states that integration and differentiation are inverse operations. If is the antiderivative of , then:
This turns a hard problem of “infinite summing” into a simple problem of “subtraction.”
Knowledge Check
If velocity v(t) is the derivative of position s(t), what does the integral of v(t) represent?
Answer: Total displacement (change in position)
If velocity v(t) is the derivative of position s(t), what does the integral of v(t) represent?
4. Improper Integrals
Sometimes we need to integrate over an infinite interval, such as . These are vital for calculating total energy or probabilities in bell curves.
Knowledge Check
Does the integral of 1/x from 1 to infinity converge?
Answer: No, it diverges to infinity.
The antiderivative is ln(x). As x goes to infinity, ln(x) goes to infinity. The 'tail' is too fat to have finite area.
Does the integral of 1/x from 1 to infinity converge?
5. Summary Check
Knowledge Check
Which numerical method is generally more accurate for the same number of steps?
Answer: Trapezoidal Rule
Which numerical method is generally more accurate for the same number of steps?