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
- 1Identify the constraint and the objective function.
- 2Express the objective in terms of one variable.
- 3Find the derivative and set it equal to zero.
- 4Solve for the critical points.
- 5Verify max/min using the second derivative test.
- 6Check 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 the optimal cut size x.
Fence enclosure
Maximize area with a fixed amount of fencing.
Similar to the rectangle problem: the optimal shape is a square.
Can design
Minimize surface area for a fixed volume (cylinder).
A = 2πr² + 2πrh with V = πr²h constant.
Shortest distance
Find the point on a curve closest to a given point.
Minimize D² = (x − a)² + (f(x) − b)².
Related topics
Understanding Derivatives
Foundation for finding critical points
Chain Rule
Useful for complex optimization problems
Lagrange Multipliers
Coming soonOptimization with multiple constraints
Linear Programming
Coming soonOptimization for linear systems
Discussion
Questions, ideas or a different approach? Join the conversation.