The other day I stumbled upon the following problem.
Start with a rectangular piece of card an integer number wide, by an integer number long, with one of those values being prime. Then cut four identical squares from each corner of the card. Fold up the four "flaps" to create an open topped box, where the corners have been cut in such a way to allow the maximum volume possible for the box. Once the box is made, it turns out that the base length is 4 times larger than the base width.
What are the dimensions of the original card?
I did solve the problem. But I still have a question. Let $L$ and $W$ be the length and width of the original paper and $x$ the length of the cut-off square. The volume of the box is a function $V(L, W, x)$.
$V(L,W,x) = x(L-2x)(W-2x)\tag{1}$
We also have that
$L-2x = 4(W-2x)\tag{2}$
I solved the problem by first finding the derivative of $V(L,W,x)$ with respect to $x$ and then making use of the second formula, finding a relationship between $W$ and $L$, and considering they're both whole and one of them is prime, I got the correct answers for $W$ and $L$ ($W = 3$, $L = 8$).
However, if I first substituted the second formula into $V(L,W,x)$ and then differentiate, I arrived at wrong results. I mean, if I first rewrite $V$ as
$V(W,x) = 4x(W-2x)^2$
Differentiate, find $x$ expressed with $W$, and substitute in $(2)$, I get wrong results. Why?