Example 1: Example 1 (p. 678)

> f := x*y;

f := x*y

> g := x^2+y^2-4;

g := x^2+y^2-4

>

> Pobj := plot3d( f, x=0..3, y=0..3 ):

> Pobj;

[Maple Plot]

> Pcon := implicitplot3d( g=0, x=0..2,y=0..2,z=0..5, color=cyan, style=patchnogrid ):

> Pcon;

[Maple Plot]

>

> display( Pobj, Pcon );

[Maple Plot]

>

To understand the fundamental basis for the method of Lagrange multipliers, look at the contours of the objective function. Note that at the maximum the objective surface, the contour line for the objective function and the constraint surface are tangent. This means their normal vectors are parallel, i.e., grad f || grad g. This is the origin for the Lagrange equations: grad f = lambda grad g.

>

> display( Pobj, Pcon, style=contour, orientation=[-90,1], scaling=unconstrained );

[Maple Plot]

>

> fx := diff( f, x );

> fy := diff( f, y );

fx := y

fy := x

> gx := diff( g, x );

> gy := diff( g, y );

gx := 2*x

gy := 2*y

>

> LE := fx=lambda*gx, fy=lambda*gy;

LE := y = 2*lambda*x, x = 2*lambda*y

> LEsol := solve( {LE,g=0}, {x,y,lambda} );

LEsol := {lambda = 1/2, y = RootOf(_Z^2-2), x = Roo...

> LEsol2 := map( allvalues, {LEsol} );

LEsol2 := {{x = -sqrt(2), lambda = -1/2, y = sqrt(2...
LEsol2 := {{x = -sqrt(2), lambda = -1/2, y = sqrt(2...

>

> sol2 := {seq( eval( [x,y], s ), s=LEsol2 )};

sol2 := {[sqrt(2), -sqrt(2)], [-sqrt(2), sqrt(2)], ...

>