CalculusBeginner

Integration Basics

Learn about antiderivatives and the area under curves. Master the Fundamental Theorem of Calculus and understand how integration reverses differentiation.

Problem Statement

Given a function f(x) = x², find the area under the curve from x = 0 tox = b using integration.

Example:

Input: f(x) = x², bounds [0, 2]

Output: ∫₀² x² dx = 8/3 ≈ 2.667

Method: F(x) = x³/3, so F(2) - F(0) = 8/3

Intuition

Integration calculates the area under a curve. While derivatives measure rates of change, integrals measure accumulation. The definite integral ∫ₐᵇ f(x) dx represents the total area between the function f(x) and the x-axis from a to b.

Key Concept: The Fundamental Theorem of Calculus connects differentiation and integration. If F'(x) = f(x), then ∫ₐᵇ f(x) dx = F(b) - F(a). This means we can find areas by finding antiderivatives!

For f(x) = x², the antiderivative is F(x) = x³/3 (since d/dx[x³/3] = x²). To find the area from 0 to 2, we evaluate F(2) - F(0) = 8/3 - 0 = 8/3 ≈ 2.667.

Riemann Sums:

We can approximate the area using rectangles (Riemann sums). As we use more rectangles, the approximation gets closer to the exact integral value.

Interactive Visualization

Drag the upper bound to see how the area under the curve changes. Notice the Riemann rectangles approximating the integral.

∫₀^2.00 x² dx = 2.667
xy01202468f(x) = x²Area = 2.667
Function
f(x) = x²
Antiderivative
F(x) = x³/3
Definite Integral
∫₀^2.00 = 2.667

Try it: Drag the red point to change the upper bound. The shaded area represents the definite integral ∫₀^b x² dx = [x³/3]₀^b = b³/3. Notice how the area grows as you increase b.

Implementation

integration.py
import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate

def numerical_integration(f, a, b, n=1000):
    """
    Calculate definite integral using Riemann sum (midpoint rule)
    ∫ₐᵇ f(x) dx ≈ Σ f(xᵢ) · Δx
    
    Args:
        f: Function to integrate
        a: Lower bound
        b: Upper bound
        n: Number of subdivisions
    
    Returns:
        Approximate value of the integral
    """
    dx = (b - a) / n
    total = 0
    
    for i in range(n):
        x_mid = a + (i + 0.5) * dx
        total += f(x_mid) * dx
    
    return total

# Example: ∫₀² x² dx
f = lambda x: x**2
a, b = 0, 2

# Numerical integration
result_numerical = numerical_integration(f, a, b)
print(f"Numerical: ∫₀² x² dx ≈ {result_numerical:.4f}")

# Analytical solution: F(x) = x³/3
# ∫₀² x² dx = [x³/3]₀² = 8/3 - 0 = 2.6667
F = lambda x: x**3 / 3
result_analytical = F(b) - F(a)
print(f"Analytical: ∫₀² x² dx = {result_analytical:.4f}")

# Using scipy for verification
result_scipy, error = integrate.quad(f, a, b)
print(f"SciPy: {result_scipy:.4f}")

# Visualize
x = np.linspace(0, 2, 100)
y = f(x)

plt.fill_between(x, 0, y, alpha=0.3, label=f'Area = {result_analytical:.4f}')
plt.plot(x, y, 'b-', linewidth=2, label='f(x) = x²')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Integration: Area Under Curve')
plt.legend()
plt.grid(True)
plt.show()

Key Properties

Linearity

∫[af(x) + bg(x)]dx = a∫f(x)dx + b∫g(x)dx

Constants and sums can be separated

Reverses Differentiation

d/dx[∫f(x)dx] = f(x)

Integration undoes differentiation

Additivity

∫ₐᶜf(x)dx = ∫ₐᵇf(x)dx + ∫ᵇᶜf(x)dx

Areas can be split and combined

Zero Width

∫ₐᵃf(x)dx = 0

No area when bounds are equal

Related Topics

Derivatives

The inverse operation of integration

Substitution RuleComing Soon

Integration technique for composite functions

Integration by PartsComing Soon

Integration technique for products

ApplicationsComing Soon

Volume, work, and physics applications

Discussion