...you might recognize the following "story problem" from Calc. 1.
A farmer has 100m of fence. He wants to use it to fence in a rectangular field of the largest possible area, one side of which is already fenced. What will the dimensions of this field be?
Here we have a constraint on the length of the fence. This suggests that we use the constraint function g(x,y) = 2*x + y = 100. The function we want to maximize is the area of the field, given by f(x,y) = x*y. Of course, we could solve this using techniques from Calculus 1. But instead we will solve the problem using Lagrange multipliers.
We start by defining and plotting our constraint curve, g(x,y) = 100. Defining the curve is simple, and a little thought helps us find good ranges for x and y. Since x and y represent lengths of fence, their values cannot be negative. Since the farmer only has 100m of fence, neither x nor y can be greater than 100. We use constrained scaling to make our plot easier to interpret.
> g:=(x,y) -> 2*x+y;
> implicitplot3d(g(x,y)=100, x=0..100, y=0..100, z=-0.1..0.1, axes=BOX, scaling=constrained, orientation=[0,0]);
Next, we plot the contours of the area function f(x,y) that we wish to maximize. The area will be maximized where the line g(x,y)=100 is tangent to the contours of f(x,y). To better compare the two functions, we use the same x and y ranges for the countour plot that we did for the implicit plot of g.
> f:=(x,y) -> x*y;
> contourplot3d(f(x,y), x=0..100, y=0..100, axes=BOX, orientation=[0,0], color=f(x,y));
It looks like the contours of f are closest in slope to the line g(x,y)=100 for values of x less than 50. We now plot both functions together over that range.
> display([implicitplot3d(g(x,y)=100, x=0..50, y=0..100, z=-0.1..0.1), contourplot3d(f(x,y),x=0..50, y=0..100, color=f(x,y))], scaling=constrained, orientation=[0,0]);
The line g(x,y)=100 appears to be tangent to a contour of f somewhere between y=40 and y=60. We zoom in on that region, adding some extra contours to help us determine the exact point of tangency.
> display([implicitplot3d(g(x,y)=100, x=20..40, y=40..60, z=-0.1 .. 0.1, thickness=2), contourplot3d(f(x,y),x=20..40, y=40..60, contours=26, color=f(x,y))], axes=BOX, orientation=[0,0]);
We see that the farmer's field will have largest area when x is about 26 and y is about 48. We could continue to zoom in to refine this estimate, or we could solve the problem using substitution and standard max/min techniques from Calculus 1.
Compute or estimate to the nearest integer what values of x and y give a field of maximum area.