Chapter 3: Derivative Formulas through Geometry

Computing Derivatives

Now that we understand what derivatives mean, let’s learn how to compute them!

The Power Rule

For f(x) = xⁿ:

\[ \frac{d}{dx} x^n = nx^{n-1} \]

Let’s discover why this works using visual reasoning.

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style('whitegrid')
plt.rcParams['figure.figsize'] = (14, 10)

1. Derivative of x²

Consider f(x) = x²

Think of x² as the area of a square with side length x.

When x changes by dx:

  • New area = (x + dx)²

  • Change in area = (x + dx)² - x²

Let’s expand: $\((x + dx)^2 - x^2 = x^2 + 2x\cdot dx + (dx)^2 - x^2\)\( \)\(= 2x\cdot dx + (dx)^2\)$

For tiny dx, the (dx)² term is negligible:

\[ \frac{df}{dx} = \lim_{dx \to 0} \frac{2x\cdot dx + (dx)^2}{dx} = 2x \]
def visualize_derivative_x_squared():
    """Show geometric meaning of d(x²)/dx = 2x."""
    
    fig, ax = plt.subplots(1, 1, figsize=(10, 10))
    
    x = 3
    dx = 0.8
    
    # Original square
    square = plt.Rectangle((0, 0), x, x, fill=True, 
                          facecolor='lightblue', edgecolor='blue',
                          linewidth=2, label=f'Original: x² = {x}²')
    ax.add_patch(square)
    
    # Added strips
    # Right strip
    strip1 = plt.Rectangle((x, 0), dx, x, fill=True,
                          facecolor='lightgreen', edgecolor='green',
                          linewidth=2, alpha=0.7)
    ax.add_patch(strip1)
    ax.text(x + dx/2, x/2, f'x·dx', ha='center', va='center', 
           fontsize=14, fontweight='bold')
    
    # Top strip
    strip2 = plt.Rectangle((0, x), x, dx, fill=True,
                          facecolor='lightcoral', edgecolor='red',
                          linewidth=2, alpha=0.7)
    ax.add_patch(strip2)
    ax.text(x/2, x + dx/2, f'x·dx', ha='center', va='center',
           fontsize=14, fontweight='bold')
    
    # Corner square
    corner = plt.Rectangle((x, x), dx, dx, fill=True,
                          facecolor='yellow', edgecolor='orange',
                          linewidth=2, alpha=0.7)
    ax.add_patch(corner)
    ax.text(x + dx/2, x + dx/2, f'(dx)²', ha='center', va='center',
           fontsize=12, fontweight='bold')
    
    # Labels
    ax.text(x/2, -0.5, f'x = {x}', ha='center', fontsize=14, fontweight='bold')
    ax.text(x + dx/2, -0.5, f'dx = {dx}', ha='center', fontsize=14)
    ax.text(-0.5, x/2, f'x = {x}', va='center', fontsize=14, fontweight='bold')
    ax.text(-0.5, x + dx/2, f'dx = {dx}', va='center', fontsize=14)
    
    ax.set_xlim(-1, x + dx + 1)
    ax.set_ylim(-1, x + dx + 1)
    ax.set_aspect('equal')
    ax.grid(True, alpha=0.3)
    ax.set_title('Geometric Proof: d(x²)/dx = 2x', fontsize=16, fontweight='bold')
    
    plt.tight_layout()
    plt.show()
    
    print("Change in Area:\n")
    print(f"  Green strip: x · dx = {x} · {dx} = {x*dx:.2f}")
    print(f"  Red strip:   x · dx = {x} · {dx} = {x*dx:.2f}")
    print(f"  Yellow square: (dx)² = {dx}² = {dx**2:.2f}")
    print(f"\n  Total: 2x·dx + (dx)² = {2*x*dx + dx**2:.2f}")
    print(f"\n  Divide by dx: 2x + dx = {2*x + dx:.2f}")
    print(f"  As dx → 0:    2x = {2*x}")

visualize_derivative_x_squared()

2. The Power Rule

The same reasoning extends to any power:

\[ \frac{d}{dx} x^n = nx^{n-1} \]

Examples:

  • d(x³)/dx = 3x²

  • d(x⁴)/dx = 4x³

  • d(x⁻¹)/dx = -x⁻²

  • d(√x)/dx = d(x^(1/2))/dx = (1/2)x^(-1/2) = 1/(2√x)

def demonstrate_power_rule():
    """Test the power rule on various functions."""
    
    print("Power Rule: d(xⁿ)/dx = nxⁿ⁻¹\n")
    print("=" * 60)
    
    examples = [
        (3, "x³", "3x²"),
        (4, "x⁴", "4x³"),
        (-1, "x⁻¹ = 1/x", "-x⁻² = -1/x²"),
        (0.5, "x^(1/2) = √x", "(1/2)x^(-1/2) = 1/(2√x)"),
        (1, "x", "1")
    ]
    
    for n, func, deriv in examples:
        print(f"\nf(x) = {func}")
        print(f"f'(x) = {deriv}")
    
    print("\n" + "=" * 60)

demonstrate_power_rule()

Summary

Key Derivative Rules

  1. Power Rule: d(xⁿ)/dx = nxⁿ⁻¹

  2. Constant Multiple: d(cf)/dx = c·df/dx

  3. Sum Rule: d(f+g)/dx = df/dx + dg/dx

Example: $\( f(x) = 3x^4 - 5x^2 + 7 \)\( \)\( f'(x) = 12x^3 - 10x + 0 = 12x^3 - 10x \)$

Next: Chain rule and product rule!