Constained Extrema with Lagrange Method
finds extrema of f(x,y) with constrained g(x,y)
lagrange(f,g):= block(
z:f+k*g, s1:diff(z,x,1),
s2:diff(z,y,1),
s3:diff(z,k,1),
load(topoly_solver), realonly:true,
v:to_poly_solve([s1,s2,s3],[x,y,k]),
u1:diff(z,x,2),
u2:diff(z,y,2),
u3:diff(diff(z,x,2),y),
u4:diff(diff(z,y,2),x),
g1:diff(g,x),g2:diff(g,y),
H:matrix([0,g1,g2],[g1,u1,u4],[g2,u3,u2]),
for s in v do (
mn: subst(s, H),mn1:subst(s,z),
de:determinant(mn),
if de >0 then print ("Constrained_Extrema Max at",s,"f(z)=",mn1),
if de <0 then print ("Constrained_Extrema Min at",s,"f(z)=",mn1),
if de=0 then print ("Determinant is zero"),
ratprint:false,
wxdraw2d(xrange = [-8,8], yrange = [-8,8],
grid=true, xaxis = true, yaxis = true,
title = "f(x,y)-g(x,y)",
color = red,
implicit(f=mn1,x,-8,8,y,-8,8),
color =blue,
implicit(g,x,-8,8,y,-8,8))) )$
For the usage look at included file
Luigi Marino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lagrange_2.wxm
Type: application/octet-stream
Size: 5324 bytes
Desc: not available
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20090602/4eeb0d54/attachment.obj