Optimization Problems
Learn to find maximum and minimum values using derivatives. Master critical points, the second derivative test, and real-world optimization applications.
Problem Statement
Find the dimensions of a rectangle with a fixed perimeter of 16 units that maximize the area.
Analysis:
Constraint: 2w + 2h = 16, so h = 8 - w
Objective: Maximize A(w) = w · h = w(8 - w) = 8w - w²
Method: Find where A'(w) = 0
Solution: w = 4, h = 4 (square), Max Area = 16
Intuition
Optimization problems use derivatives to find maximum or minimum values. At these optimal points, the derivative equals zero (horizontal tangent), making them critical points.
Key Concept: To optimize f(x), find where f'(x) = 0 (critical points), then use the second derivative test: if f''(x) < 0, it's a maximum; if f''(x) > 0, it's a minimum.
For our rectangle problem, A(w) = 8w - w² gives A'(w) = 8 - 2w. Setting this to zero: 8 - 2w = 0, so w = 4. Since A''(w) = -2 < 0, this is indeed a maximum. Interestingly, the optimal shape is a square!
General Strategy:
- Identify constraint and objective function
- Express objective in terms of one variable
- Find derivative and set equal to zero
- Solve for critical points
- Verify max/min using second derivative test
- Check boundary points if applicable
Interactive Visualization
Adjust the rectangle width to see how the area changes. Notice the area is maximized when the rectangle becomes a square (w = h = 4).
Area Function: A(w) = w(8-w)
Rectangle (Perimeter = 16)
Try it: Drag the red point or slider to change the rectangle width. Notice that the area is maximized when w = 4 (making it a square), where the derivative A'(w) = 0. This is a critical point!
Implementation
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize_scalar
def optimization_problem():
"""
Problem: Maximize area of rectangle with fixed perimeter
Given: Perimeter = 16
Find: Dimensions (width, height) that maximize area
Constraint: 2w + 2h = 16 => h = 8 - w
Objective: A(w) = w * h = w(8 - w) = 8w - w²
"""
# Define area function (to maximize)
def area(w):
return w * (8 - w)
# Define negative area (to minimize, equivalent to maximizing area)
def neg_area(w):
return -area(w)
# Method 1: Using calculus (derivative = 0)
# A(w) = 8w - w²
# A'(w) = 8 - 2w
# Critical point: 8 - 2w = 0 => w = 4
w_critical = 4
h_critical = 8 - w_critical
max_area_analytical = area(w_critical)
print("=== Analytical Solution (Calculus) ===")
print(f"Critical point: w = {w_critical}, h = {h_critical}")
print(f"Maximum area: {max_area_analytical}")
# Verify it's a maximum (second derivative test)
# A''(w) = -2 < 0, so it's a maximum ✓
print(f"Second derivative: A''(w) = -2 (< 0, confirms maximum)")
# Method 2: Using numerical optimization
result = minimize_scalar(neg_area, bounds=(0, 8), method='bounded')
w_optimal = result.x
h_optimal = 8 - w_optimal
max_area_numerical = -result.fun
print("\n=== Numerical Solution (scipy) ===")
print(f"Optimal width: {w_optimal:.4f}")
print(f"Optimal height: {h_optimal:.4f}")
print(f"Maximum area: {max_area_numerical:.4f}")
# Visualize
w_values = np.linspace(0, 8, 100)
area_values = [area(w) for w in w_values]
plt.figure(figsize=(10, 6))
plt.plot(w_values, area_values, 'b-', linewidth=2, label='A(w) = w(8-w)')
plt.plot(w_critical, max_area_analytical, 'ro', markersize=10,
label=f'Maximum: ({w_critical}, {max_area_analytical})')
plt.axvline(w_critical, color='r', linestyle='--', alpha=0.5)
plt.xlabel('Width (w)')
plt.ylabel('Area (A)')
plt.title('Optimization: Maximize Rectangle Area')
plt.legend()
plt.grid(True)
plt.show()
return w_critical, h_critical, max_area_analytical
# Run optimization
width, height, area = optimization_problem()
print(f"\nResult: {width} × {height} rectangle with area {area}")Classic Optimization Problems
Box Volume
Maximize volume by cutting corners from a square sheet
V(x) = x(a-2x)², find optimal cut size x
Fence Enclosure
Maximize area with fixed amount of fencing
Similar to rectangle problem, optimal is square
Can Design
Minimize surface area for fixed volume (cylinder)
A = 2πr² + 2πrh with V = πr²h constant
Shortest Distance
Find point on curve closest to a given point
Minimize D² = (x-a)² + (f(x)-b)²
Related Topics
Derivatives
Foundation for finding critical points
Chain Rule
Useful for complex optimization problems
Lagrange MultipliersComing Soon
Optimization with multiple constraints
Linear ProgrammingComing Soon
Optimization for linear systems