Differentiate then solve or vice versa. Why is there a difference?

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?

-
you use very strange notation – Adi Dani Nov 17 '12 at 14:28
@AdiDani: I'm new to this SE. I'll improve over time :) – Armen Tsirunyan Nov 17 '12 at 14:29
This is a good question. It would have been nice to explicitly show your results for each calculation so others don't have to reproduce the work. – Ross Millikan Nov 17 '12 at 16:02

The difference comes because in the first method, you are considering $L$ and $W$ to be fixed, then finding $x$ to maximize the volume. In the second, $L$ varies with $x$ to maintain the relationship $L-2x=4(W-2x)$ and $x$ is chosen to maximize the volume. At the optimum for this one, we have $x=\frac W6, L=3W$
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9071658849716187, "perplexity": 138.98844634328236}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-18/segments/1461860115836.8/warc/CC-MAIN-20160428161515-00017-ip-10-239-7-51.ec2.internal.warc.gz"}