# 2.5 Classification of critical points

```#
#
#                                              WORKSHEET#16
#
#                                     Classification of critical points
#
#
--------------------------------------------------------------------------------
# In this worksheet we continue the study of the critical points of the the function f(x,y)
# from worksheet#15.  This is done through the hessian matrix.
--------------------------------------------------------------------------------
> f:=(x,y)->sin(y-x^2-1)+cos(2*y^2-x);

2               2
f := (x,y) -> sin(y - x  - 1) + cos(2 y  - x)
--------------------------------------------------------------------------------
> f1:=D[1](f);f2:=D[2](f);

2                   2
f1 := (x,y) -> - 2 cos(- y + x  + 1) x - sin(- 2 y  + x)

2                   2
f2 := (x,y) -> cos(- y + x  + 1) + 4 sin(- 2 y  + x) y
--------------------------------------------------------------------------------
> with(linalg);
Warning: new definition for   norm
Warning: new definition for   trace

adjoint, angle, augment, backsub, band, basis, bezout, blockmatrix,

charmat, charpoly, col, coldim, colspace, colspan, companion, concat, cond,

copyinto, crossprod, curl, definite, delcols, delrows, det, diag, diverge,

dotprod, eigenvals, eigenvects, entermatrix, equal, exponential, extend,

ffgausselim, fibonacci, frobenius, gausselim, gaussjord, genmatrix, grad,

hadamard, hermite, hessian, hilbert, htranspose, ihermite, indexfunc,

innerprod, intbasis, inverse, ismith, iszero, jacobian, jordan, kernel,

laplacian, leastsqrs, linsolve, matrix, minor, minpoly, mulcol, mulrow,

multiply, norm, normalize, nullspace, orthog, permanent, pivot, potential,

randmatrix, randvector, rank, ratform, row, rowdim, rowspace, rowspan,

rref, scalarmul, singularvals, smith, stack, submatrix, subvector,

sumbasis, swapcol, swaprow, sylvester, toeplitz, trace, transpose,

vandermonde, vecpotent, vectdim, vector]
--------------------------------------------------------------------------------
> ?hessian;
--------------------------------------------------------------------------------
> H:=hessian(f(x,y),[x,y]);

H :=               2       2                2                 2
[4 sin(- y + x  + 1) x  - 2 cos(- y + x  + 1) - cos(- 2 y  + x),

2                     2
- 2 sin(- y + x  + 1) x + 4 cos(- 2 y  + x) y]

2                     2
[- 2 sin(- y + x  + 1) x + 4 cos(- 2 y  + x) y,

2                    2       2              2
sin(- y + x  + 1) - 16 cos(- 2 y  + x) y  + 4 sin(- 2 y  + x)]
--------------------------------------------------------------------------------
# Note that this matrix is symmetric.  A critical point will be a local mimimum if all the
# eigenvalues of the hessian, when evaluated at the critical point, are positive and a local
# maximum if they are all negative.  If all eigenvalues at the critical point are non-zero,but
# some are negative and some are positive, then the critical point is a saddle point.  This
# works for all dimensions.
--------------------------------------------------------------------------------
> ?eigenvalues
--------------------------------------------------------------------------------
> fsolve ({f1(x,y),f2(x,y)},{x,y},{x=0.36..0.38,y=-0.44..-0.42});

{x = .3728572391, y = -.4317738060}
--------------------------------------------------------------------------------
> assign(");
--------------------------------------------------------------------------------
> print(x,y,f1(x,y),f2(x,y),f(x,y));

-10                 -9
.3728572391, -.4317738060, .529485605*10   , -.3778129031*10  , 0
--------------------------------------------------------------------------------
> print(H(x,y));

2
[4 %2 x(.3728572391, -.4317738060)

2
- 2 cos(- y + x  + 1)(.3728572391, -.4317738060) - %1,

- .7457144782 %2 - 1.727095224 %1]

2
[ - .7457144782 %2 - 1.727095224 %1, %2 - 16 %1 y(.3728572391, -.4317738060)

2
+ 4 sin(- 2 y  + x)(.3728572391, -.4317738060)]

2
%1 :=             cos(- 2 y  + x)(.3728572391, -.4317738060)

2
%2 :=            sin(- y + x  + 1)(.3728572391, -.4317738060)
--------------------------------------------------------------------------------
#
> x;y;

.3728572391

-.4317738060
--------------------------------------------------------------------------------
# Thus even though x and y have been assigned values H has not.  H is a 2 by 2 matrix
# whose entries are H[1,1], H[1,2], etc.  The entries have been assigned values.
--------------------------------------------------------------------------------
> H[1,1];

-.4439099168
--------------------------------------------------------------------------------
> ?matrix
--------------------------------------------------------------------------------
> A:=matrix(2,2,[H[1,1],H[1,2],H[2,1],H[2,2]]);

[ -.4439099168  -2.472809702 ]
A := [                            ]
[ -2.472809702  -1.982857912 ]
--------------------------------------------------------------------------------
> eigenvals(A);

-3.803148007, 1.376380179
--------------------------------------------------------------------------------
# Thus this crirical point is a saddle point, that is the in some directions near the critical
# point the function is increasing and in others it is decreasing.  We'll try one more critical
# point.
--------------------------------------------------------------------------------
> x:='x':y:='y':
> fsolve({f1(x,y),f2(x,y)},{x,y},{x=-1.4..-1.0,y=0.8..1.2});

{y = .9743122425, x = -1.243023962}
--------------------------------------------------------------------------------
> assign(");
--------------------------------------------------------------------------------
> print(x,y,f1(x,y),f2(x,y),f(x,y));

-8               -9
-1.243023962, .9743122425, -.3406151520*10  , .393574498*10  , -2.
--------------------------------------------------------------------------------
> A:=matrix(2,2,[H[1,1],H[1,2],H[2,1],H[2,2]]);

[  7.180434282  -1.411201046 ]
A := [                            ]
[ -1.411201046   16.18854953 ]
--------------------------------------------------------------------------------
> eigenvals(");

6.964531797, 16.40445202
--------------------------------------------------------------------------------
# Both eigenvalues are positive so this is a local minimum.  Actually this is a global
# minimum.  To see this note that the value of f(x,y) is -2 and then just recall the definition
# of f(x,y).

```