Feeds:
Posts

## The Farmer and the Fencing (Lagrangian)

In my last post on the Farmer and the Fencing optimization problem, I mentioned that separating the pen into two triangular pieces with a diagonal cross-section makes the problem a lot more complex and requires the use of Lagrangian methods to solve.  After conceiving the problem in 1999-2000 and setting up the Lagrangian system that would solve the problem in 2001-2002 I finally solved it this week by using Wolfram Alpha.  If anyone out there sees a good algebraic solution for the Lagrangian system of three equations with three unknowns, please let me know.

Given 100 feet of fencing, a rectangular pen with length $=x$, width $=y$ and a diagonal cross-section $=\sqrt{x^2+y^2}$, the perimeter constraint equation would be:

$2x+2y+\sqrt{x^2+y^2}=100$

The area equation we want to optimize is:

$A=x*y$

So, the Lagrangian process says that to maximize a function $f(x,y)$, with a given constraint $g(x,y)=C$, we need to set up a system based on the equality:

$\bigtriangledown f(x,y)=\lambda \bigtriangledown g(x,y)$

In this problem, $f(x,y)=A=xy$ and $g(x,y)=2x+2y+\sqrt{x^2+y^2}$.

So the gradient of $f(x,y)$, or $\bigtriangledown f(x,y)$ is:

$\bigtriangledown f(x,y)=(\frac{\partial f}{\partial x}, \frac{\partial f}{\partial y})$

And the gradient of $g(x,y)$, or $\bigtriangledown g(x,y)$ is:

$\bigtriangledown g(x,y)=(\frac{\partial g}{\partial x}, \frac{\partial g}{\partial y})$

So, going back to the functions we’re working with based on the perimeter and area, the Lagrangian set up would be:

$\bigtriangledown f(x,y)=\lambda \bigtriangledown g(x,y)$

$(y,x)=\lambda (2+\frac{x}{\sqrt{x^2+y^2}}, 2+\frac{y}{\sqrt{x^2+y^2}})$

This generates the system of equations:

$y=2\lambda+\frac{\lambda x}{\sqrt{x^2+y^2}}$

$x=2\lambda+\frac{\lambda y}{\sqrt{x^2+y^2}}$

$2x+2y+\sqrt{x^2+y^2}=100$

I must admit once again to resorting to a technological solution for this system.  Using Wolfram Alpha, we get the solution

$x=y=\frac{100}{4+\sqrt{2}}\approx 18.47$

This makes the cross-piece:

$\sqrt{x^2+y^2} =\frac{100}{\sqrt{9+4\sqrt{2}}} \approx 26.12$

Which of course means that the optimal area is once again generated by a square!  If we assumed this at the outset of the problem, it becomes much simpler (but less “fun”).  The permimeter in that case is:

$4x+x\sqrt{2}=100$

and

$x=\frac{100}{4+\sqrt{2}}$

I’ve been carrying this around with me for nearly 15 years and dug out the work I had originally done a few weeks ago to look at it “with fresh eyes.”  I found a few minor errors and was happy to use Wolfram Alpha to solve the system and finally generate a solution for this problem.