# Rectangular boxes: handle with care

A rectangular box (aka parallelepiped) looks like a sturdy object:

But this particular box, with dimensions 7.147 by 6.021 by 4.095, took me the better part of an hour to figure out.

It was a part of a numerical methods assignment: find the dimensions of a box with given volume ${V}$, surface area ${S}$, and diameter ${D}$ (i.e., space diagonal). Algebraic approach leads to pretty ugly expressions, which is the motivation for a numerical method. Specifically, the task was to apply the Newton-Raphson method to the map

$\displaystyle F(x,y,z) = \begin{pmatrix} xyz-V \\ 2(xy+yz+xz)-S \\ x^2+y^2+z^2-D^2 \end{pmatrix}$

Of course, I understood that not every triple ${(V,S,D)}$ is attainable. Also realized that the Jacobian of ${F}$ is degenerate when two of the coordinates coincide, which is a problem for the method. So I thought: let’s generate some random ${x,y,z}$ values that are not too close to one another, and give students the resulting parameters ${V,S,D}$.

With ${x=7.147}$, ${y=6.021}$, and ${z=4.095}$ the parameters are ${V=176.216}$, ${S=193.91}$, and ${D=10.203}$. Sure, a little rounding can’t hurt when numbers are of this size and we are quite far from the critical points of ${F}$. So I put ${V=176}$, ${S=194}$ and ${D=10}$ in one of the versions of the assignment.

But the Newton-Raphson method would not converge… because no such box exists! The rounding did hurt after all.

This motivated me to describe all attainable triples ${(V,S,D)}$ explicitly, which ended up being less of a chore than I expected. It helps to realize that ${(x+y+z)^2 = D^2+S}$, which reduces the search to the intersection of the sphere ${x^2+y^2+z^2=D^2}$ with the plane ${x+y+z=\sqrt{D^2+S}}$. This is a circle (called ${C}$ below), and the allowed range for ${V}$ is between the minimum and maximum of ${xyz}$ on ${C}$.

This goes into Calculus 3 territory. Using Lagrange multipliers with two constraints looks like a tedious job. Instead, I decided to parametrize ${C}$. Its center is ${(c,c,c)}$ where ${c=\dfrac13\sqrt{D^2+S}}$. The radius is ${\displaystyle r = \sqrt{ D^2 - \frac13(D^2+S)}=\frac13 \sqrt{6D^2-3S}}$. We also need an orthonormal basis of the subspace ${x+y+z=0}$: the vectors

$\displaystyle \frac{1}{\sqrt{6}} \langle 2, -1, -1\rangle \quad \text{and}\quad \frac{1}{\sqrt{2}} \langle 0, 1, -1\rangle$

do the job.

So, the circle ${C}$ is parametrized by

$\displaystyle x = c+\frac{2r}{\sqrt{6}} \cos t \\ y = c-\frac{r}{\sqrt{6}} \cos t +\frac{r}{\sqrt{2}} \sin t \\ z = c-\frac{r}{\sqrt{6}} \cos t -\frac{r}{\sqrt{2}} \sin t$

This is not as bad as it looks: the product ${xyz}$ simplifies to

$\displaystyle xyz = c^3 - \frac{cr^2}{2} + \frac{r^3\sqrt{6}}{18} \cos 3t$

which tells us right away that the volume ${V}$ lies within

$\displaystyle c^3 - \frac{cr^2}{2} \pm \frac{r^3\sqrt{6}}{18}$

In terms of the original data ${S,D}$ the bounds for ${V}$ take the form

$\displaystyle \frac{5S-4D^2}{54}\sqrt{S+D^2} \pm \frac{\sqrt{2}}{54} (2D^2-S)^{3/2}$

(And of course, ${V}$ cannot be negative even if the lower bound is.) It is easy to see that ${2D^2-S\ge 0}$ with equality only for a cube; however ${2D^2-S}$ can be relatively small even when the box does not look very cube-ish. For the box pictured above, the tolerance ${\frac{\sqrt{2}}{54} (2D^2-S)^{3/2}}$ is approximately ${1.4}$; after rounding ${S\approx 194 }$ and ${D\approx 10}$ this drops to ${0.38}$, and the desired volume of ${176}$ is way out of the allowable range ${181\pm 0.38}$.

Yes, the set of attainable triples ${(V,S,D)}$ is quite thin. Parallelepipeds are fragile objects: handle them with care.

## 4 thoughts on “Rectangular boxes: handle with care”

1. Call $A = x+y+z$, $B = xy + yz+ zx$ and $C = xyz$. Then x, y, z are the roots of the polynomial $x^{3} - A x^{2} + B x - C$. The $A, B, C$ can be expressed in terms of V, S, D, so why don’t you apply Newton-Raphson for the function $f: \mathbb{R} \rightarrow \mathbb{R}$, $f(x) = x^{3} - A x^{2} + B x - C$ ? You want that $A, B, C$ are such that the polynomial has 3 real, non-negative solutions.

1. L says:

I knew the number of variables could be reduced, but the topic of the assignment was Newton-Raphson for nonlinear systems of equations. I wanted a system that is not too complicated and would admit a simple, “practical” interpretation, such as designing a shape with desired parameters.

1. OK, but the number of variables are not reduced here. You just look for all the roots of a function of degree 3. Just forget that’s a formula for this, you just have to pick the right initial points for the algorithm (take the derivative of f for this, for example), then run the algorithm three times. Besides, I bet that in terms of S, D, V, the condition for the polynomial to have all roots real and moreover nonnegative have nice geometrical interpretations (like isoperimetric, isodiametric inequalities for parallelipipeds).

2. L says:

I think that picking right initial points to find all three roots might take more computations or human effort (repeated guess and check) than working with the system. The system has multiple roots too, but they are permutations of x,y,z, so it does not matter to which we converge. Starting with three unequal positive values of x,y,z, the method converged in all tests that I ran (when the solution existed).

But an interesting point about nonnegativity of roots as a criterion for solvability; this ought to be a shorter path to the characterization of attainable (S,D,V) than in my post.