Finding mix/max of f(x,y)



Dotan Cohen escribi?:
> I am trying to figure out how to find the min/max of a
> threee-dimensional function with Maxima.
> 
> For instance, I am playing with the function f(x,y)=x^3+3*x*y-6*x*y
> On paper I can easily find f'x f''xx f'y f''yy f''xy and find the
> critical points, then check each one. Is there a simpler way to do
> this in Maxima? I have googled but not found anything of this sort
> (though there is a lot of good info about Maxima floating around the
> 'net).
> 
> Just to prove that I'm not asking someone to do my homework (and yes,
> this _is_ a homework question), the solution set is {(0,0,), (0,2),
> (1,1), (-1,1)}.
> 

I've written this program time ago. Sorry, comments are in Spanish, but 
I hope you'll get the idea:


/*************  begin Maxima Session  ********************/

/* Analiza los puntos criticos de una funcion de  */
/* variables independientes x e y.                */
/* Ejemplos de uso:                               */
/*     extremos(exp(x-y)*x*y);                    */
/*     extremos(y^2 + (x + 1)^2*y + (x + 1)^4);   */


load(vect)$

extremos(expr):=
   block([gr,cr,he,x,y,mn,de],

     /* vector gradiente de la funcion */
     gr: grad(expr),

     /* hessiano */
     he: hessian(expr, [x,y]),

     /* Resuelve para x e y el gradiente nulo */
     cr: solve(ev(express(gr),diff), [x,y]),

     /* s recorre las soluciones encontradas por solve */
     for s in cr do (

       /* valor numerico del hessiano para la soluci?n s */
       mn: subst(s, he),

       /* determinante del hessiano */
       de: determinant(mn),

       /* controla el tipo de punto critico */
       if de > 0
         then if mn[1,1] > 0
                then print("Minimo relativo en ", s)
                else print("Maximo relativo en ", s)
         else if de < 0
                then print("Punto silla en ", s)
                else print("Determinante nulo en ", s) ) )$

f(x, y) := x^3+3*x*y-6*x*y $

extremos(f(x,y));

/* your solutions: */
load(draw)$
draw3d(
   explicit(x^3+3*x*y-6*x*y, x,-3,3,y,-3,3),
   point_size = 3, color = red, point_type = filled_circle,
   points([[0,0,f(0, 0)],[0,2,f(0, 2)],[1,1,f(1, 1)],[-1,1,f(-1, 1)]]))$

/*************  end Maxima Session  ********************/

-- 
Mario Rodriguez