Skip to content
All apps

Optimisation: the largest rectangle

About this app

Drag a rectangle inside a triangle and watch its area function. Follow the objective, constraint, substitution and differentiation to find the maximum.

The problem

A right triangle with base b and height h should contain an axis-aligned rectangle of maximum area. The rectangle’s upper right corner lies on the hypotenuse y = h · (1 − x/b). The objective is A = x · y, and the constraint links y to x. Substituting gives A(x) = h · x · (1 − x/b), a downward-opening parabola. Setting A′(x) = h · (1 − 2x/b) = 0 gives x = b/2, y = h/2 and A_max = h · b/4, exactly half of the triangle’s area.

What the app shows

On the left you see the triangle and the rectangle whose corner slides along the line; on the right the graph of A(x) with the current point. Width x, height y(x) and area A(x) are listed in the “Rectangle” panel. Sliders change the base b and height h. The info panel walks through the solution in five steps: objective, constraint, substitution, derivative, result.

Things to try

Move x and notice how the rectangle first grows and then gets flatter while A(x) traces an arch. “Scan” sweeps x automatically, and “Jump to maximum” sets x = b/2. Change b and h: the maximum moves with them, but the ratio stays the same, half the width and half the height.

Frequently asked questions

How do you solve an optimization problem with a constraint?
First write down the objective function, for example the area A = x · y. Use the constraint to express one variable in terms of the other and substitute, so A depends on a single variable. Then differentiate, solve A′ = 0 and check with A″ or the endpoints that you have a maximum.
What is the largest rectangle that fits in a right triangle?
For a right triangle with legs b and h, the axis-aligned rectangle with width b/2 and height h/2 has the largest area. That area is h · b/4, half of the triangle’s area h · b/2.
How do you know it is a maximum and not a minimum?
For A(x) = h · x · (1 − x/b), the second derivative A″(x) = −2h/b is negative, so the parabola opens downwards. At the endpoints x = 0 and x = b the area is zero. Therefore x = b/2 is the global maximum.
What can I adjust in the app?
You drag the rectangle’s width x, change the triangle’s base b and height h, and see A(x) plotted live. A button jumps to the maximum, and the info panel shows the five-step solution.

Subject: Analysis (one-dimensional)

More from Analysis (one-dimensional)

A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps