Optimization

Find the maximum or minimum value of a function subject to a constraint: the fundamental tool for real-world decision-making problems.

maximise f subject to a constraint g=0\text{maximise } f \text{ subject to a constraint } g = 0

Solve a problem with Optimization

Type the problem. The solver will use Optimization where Optimization is the right tool, and tell you when it is not.

Drag one in or paste from the clipboard. JPEG, PNG or WebP. You get the transcription to check before anything is solved.

How to get a better answer
  • Paste the whole problem, including the instruction word — "simplify", "solve for x" and "factor" lead to three different answers.
  • Say what you have already tried. "I got x = 4 and the book says 2" turns a solution into a diagnosis.
  • Set the level in the settings button. A calculus shortcut is not a better answer if you have not met derivatives yet.
  • For a photo, get the whole problem in frame and hold the page flat — you get the transcription to fix before anything is solved.

What each symbol means

What Optimization takes
ff
gg
Optimization
SymbolMeaning
ffThe objective function—the quantity you want to maximize or minimize, such as profit, area, cost, or production. If ff measures profit, maximizing ff increases earnings; if ff measures cost, minimizing ff saves money.
ggThe constraint function, set equal to zero; it represents a restriction that the optimal solution must satisfy, such as a budget limit, total hours available, or a geometric requirement. Misreading g=0g = 0 as an inequality or rearranging it wrong ruins the solution.

When to use it

When you need to make a decision that optimizes one thing (profit, distance, material) while respecting a limitation (budget, time, supply).

Level

Usually taught in: Calculus I · Appears on: AP Calculus

Worked examples

1. Maximize a product with a sum constraint

Problem

Find the maximum value of f(x,y)=xyf(x, y) = xy subject to the constraint x+y=6x + y = 6.
  1. y=6xy = 6 - x

    Rearrange the constraint g=x+y6=0g = x + y - 6 = 0 to solve for yy in terms of xx.

  2. f(x)=x(6x)=6xx2f(x) = x(6 - x) = 6x - x^2

    Substitute the expression for yy into ff to write it as a single-variable function.

  3. dfdx=62x\frac{df}{dx} = 6 - 2x

    Differentiate f(x)f(x) with respect to xx to find critical points.

  4. 62x=0    x=36 - 2x = 0 \implies x = 3

    Set the derivative equal to zero and solve for the critical point.

  5. y=63=3y = 6 - 3 = 3

    Substitute x=3x = 3 back into the constraint to find yy.

  6. f(3,3)=33=9f(3, 3) = 3 \cdot 3 = 9

    Evaluate ff at the critical point to find the maximum value.

Answer: x=3,y=3, and the maximum value is 9x = 3, y = 3, \text{ and the maximum value is } 9

Substituting the constraint into the objective function reduces this to a single-variable optimization problem. The first derivative test then finds where the function stops increasing, which is the maximum. This method is quick when one constraint can be easily solved for one variable.

2. Minimize a sum of squares with a linear constraint

Problem

Find the minimum value of f(x,y)=x2+4y2f(x, y) = x^2 + 4y^2 subject to 2x+y=82x + y = 8.
  1. y=82xy = 8 - 2x

    Rearrange the constraint to express yy in terms of xx.

  2. f(x)=x2+4(82x)2f(x) = x^2 + 4(8 - 2x)^2

    Substitute y=82xy = 8 - 2x into the objective function.

  3. f(x)=x2+4(6432x+4x2)=x2+256128x+16x2=17x2128x+256f(x) = x^2 + 4(64 - 32x + 4x^2) = x^2 + 256 - 128x + 16x^2 = 17x^2 - 128x + 256

    Expand (82x)2(8 - 2x)^2 and simplify by collecting like terms. Watch for sign errors when subtracting.

  4. dfdx=34x128\frac{df}{dx} = 34x - 128

    Differentiate the single-variable function.

  5. 34x128=0    x=12834=641734x - 128 = 0 \implies x = \frac{128}{34} = \frac{64}{17}

    Solve for the critical point. The fraction 6417\frac{64}{17} is already in lowest terms.

  6. y=826417=13612817=817y = 8 - 2 \cdot \frac{64}{17} = \frac{136 - 128}{17} = \frac{8}{17}

    Substitute back into the constraint to find yy.

  7. f(6417,817)=(6417)2+4(817)2=4096289+256289=4352289f\left(\frac{64}{17}, \frac{8}{17}\right) = \left(\frac{64}{17}\right)^2 + 4\left(\frac{8}{17}\right)^2 = \frac{4096}{289} + \frac{256}{289} = \frac{4352}{289}

    Substitute the critical point back into the original objective function and simplify.

Answer: x=6417,y=817, and the minimum value is 435228915.06x = \frac{64}{17}, y = \frac{8}{17}, \text{ and the minimum value is } \frac{4352}{289} \approx 15.06

This problem requires careful algebra with fractions. After substitution, the objective becomes a quadratic in one variable; since the coefficient of x2x^2 is positive, the critical point is a minimum. Fractions often appear in real applications, so checking arithmetic at each step prevents cascading errors.

3. Allocate hours between two crews to maximize output

Problem

A construction crew splits 40 hours total between two teams. Team A completes 5 units of work per hour, and Team B completes 3 units per hour. Find how many hours each team should work to maximize the total units completed.
  1. Let x= hours for Team A,y= hours for Team B\text{Let } x = \text{ hours for Team A}, \quad y = \text{ hours for Team B}

    Define variables for the hours worked by each team.

  2. f(x,y)=5x+3yf(x, y) = 5x + 3y

    Write the objective function: total units equals units per hour for each team multiplied by hours worked.

  3. x+y=40x + y = 40

    Write the constraint: the two teams' hours must sum to 40.

  4. y=40xy = 40 - x

    Rearrange the constraint to express yy in terms of xx.

  5. f(x)=5x+3(40x)=5x+1203x=2x+120f(x) = 5x + 3(40 - x) = 5x + 120 - 3x = 2x + 120

    Substitute the constraint into the objective function.

  6. dfdx=2\frac{df}{dx} = 2

    Differentiate. The derivative is constant and positive, so ff always increases with xx.

  7. x=40,y=0x = 40, \quad y = 0

    Since ff increases as xx increases and x40x \le 40, the maximum occurs at the boundary: assign all hours to Team A.

  8. f(40,0)=5(40)+3(0)=200f(40, 0) = 5(40) + 3(0) = 200

    Evaluate the objective at the optimal allocation.

Answer: x=40 hours for Team A,y=0 hours for Team B, maximum output =200 unitsx = 40 \text{ hours for Team A}, y = 0 \text{ hours for Team B}, \text{ maximum output } = 200 \text{ units}

When the objective function is linear (no squares or products), the optimum occurs at a boundary of the feasible region, not at an interior critical point. This makes practical sense: since Team A is more productive, assign all available time to Team A. Always check whether critical points lie within the feasible region and whether the extremum is interior or on the boundary.

Common mistakes

Where Optimization usually goes wrong
Answer came out wrong
Finding critical points of ff without applying the constraint, then claiming those are the optimal values.
Substitute the constraint into ff first, then find critical points of the resulting single-variable function.
Rearranging g=0g = 0 incorrectly, such as writing x+y=6x + y = 6 as y=x6y = x - 6 instead of y=6xy = 6 - x.
Rewrite g=0g = 0 step-by-step and double-check by substituting back: if x+y6=0x + y - 6 = 0, then y=6xy = 6 - x, verified because x+(6x)6=0x + (6 - x) - 6 = 0.
Forgetting to check boundary values when the feasible region has endpoints, such as when x0x \ge 0 or xmaxx \le \text{max}.
After finding critical points, also evaluate the objective at any boundaries imposed by the problem context, and compare all candidates to find the true optimum.
The mistakeWhy it is wrongThe fix
Finding critical points of ff without applying the constraint, then claiming those are the optimal values.Critical points of ff alone ignore the constraint g=0g = 0 and may not even satisfy it, so they cannot be the constrained optimum.Substitute the constraint into ff first, then find critical points of the resulting single-variable function.
Rearranging g=0g = 0 incorrectly, such as writing x+y=6x + y = 6 as y=x6y = x - 6 instead of y=6xy = 6 - x.A sign error in the constraint propagates through every subsequent calculation, yielding a wrong answer that satisfies a different constraint.Rewrite g=0g = 0 step-by-step and double-check by substituting back: if x+y6=0x + y - 6 = 0, then y=6xy = 6 - x, verified because x+(6x)6=0x + (6 - x) - 6 = 0.
Forgetting to check boundary values when the feasible region has endpoints, such as when x0x \ge 0 or xmaxx \le \text{max}.For constrained problems over a bounded region, the optimum may lie at an endpoint rather than at an interior critical point, especially if the objective is linear or monotone.After finding critical points, also evaluate the objective at any boundaries imposed by the problem context, and compare all candidates to find the true optimum.

Tips and when to use something else

  • When the constraint is a simple equation, substitution is often faster than Lagrange multipliers (which you will meet in Calculus II). Use substitution first unless the constraint is complicated.
  • If a critical point falls outside the feasible region—for instance, if x=40x = 40 but the problem says x30x \le 30—evaluate the boundary point instead. The optimum for the constrained problem may not be a critical point of the unconstrained function.
  • Always interpret your answer: does it make practical sense? If you minimize cost and get a negative value, something is wrong with your setup or algebra.
  • Sketch the constraint curve and level curves of ff (if two-variable) to visualize whether you expect a maximum, minimum, or neither in the feasible region.

Frequently asked questions

How do I know whether I should maximize or minimize?
Read the problem carefully for words like maximize, minimize, largest, smallest, or best. If the context is unclear, ask: what quantity does the company or person want to improve? Businesses maximize profit and minimize cost; physics problems often minimize energy or maximize efficiency.
What if there is no critical point inside the constraint region?
If the derivative is always positive or always negative, the objective is monotone (always increasing or decreasing). The optimum then occurs at a boundary of the feasible region. This is typical when the objective is linear, like f(x)=2x+5f(x) = 2x + 5, which has no interior critical points.
Can I have more than one constraint?
Yes, but Calculus I typically handles one main constraint using substitution. Multiple constraints require Lagrange multipliers (Calculus III). If you have two constraints, try to combine them into one equation or substitute one into the other first.
Do I always get a global maximum or minimum?
Not necessarily. If the feasible region is unbounded—for instance, x+y=10x + y = 10 with no restriction other than non-negativity—then an objective like f=x+yf = x + y has no maximum. Always state the domain explicitly and verify that your answer exists and makes sense within it.

Need a different method?

The full solver is not scoped to one formula — type any problem and it will pick the method.

Open the math solver

Reviewed 2026-09-18