# [Maxima] Finding mix/max of f(x,y)

Mario Rodriguez biomates at telefonica.net
Fri Oct 17 15:00:28 CDT 2008

```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
> (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);   */

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

/* vector gradiente de la funcion */

/* 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));