kill(all)$

simple optimization f(x,y) : 'fixed step,fx,fy,hessian', part 1b ,version 1.0a
peter.vlasschaert@gmail.com, 21/03/2019

How to show Maximum. (see part 1a).  ' plot of the function,contour '.
===============================

function : f(x,y)  = ?
================

p1:f(x,y):= 4 -x^2-y^2;

1e) concept : hessian (optimization)
==================

?  hessian;

We need second order derevatives 

a) normal derivatives. ('second order')
==================

∂f(x,y)/∂x = ?       =>  sec . order  : ∂(∂f(x,y)/∂x)/∂x
============

p1a:'diff(f(x,y),x) =diff(f(x,y),x);

 =>

p1a1::'diff(f(x,y),x,2) = diff(rhs(p1a),x);

∂f(x,y)/∂y = ?       =>  sec . order  : ∂(∂f(x,y)/∂y)/∂y
============

p1b:'diff(f(x,y),y) =diff(f(x,y),y);

 =>

p1b1::'diff(f(x,y),y,2) = diff(rhs(p1b),y);

b) mixed derivatives. ('second order')
==================

∂f(x,y)/∂x = ?       =>  sec . order  : ∂(∂f(x,y)/∂x)/∂y
============

p2a:p1a;

 =>

p2a1:'diff(lhs(p2a),y) = diff(lhs(p2a),y);

p2a2:lhs(p2a1) =ev(rhs(p2a1),diff);

∂f(x,y)/∂y = ?       =>  sec . order  : ∂(∂f(x,y)/∂y)/∂x
============

p2b:p1b;

 =>

p2b1:'diff(lhs(p2b),x) = diff(lhs(p2b),x);

p2b2:lhs(p2b1) =ev(rhs(p2b1),diff);

from : above 'help:hessian', matrix.

q1: How to construct matrix.  2  by 2, name 'H'
===================================

go to : Menu :algebra : Generate Matrix.

H: genmatrix( a, 2, 2);

q2:create Hessian
================

H[1,1] :v;

how to fill matrix => 
-----------------------------

H;

how to fill matrix => 'hessian'
-------------------------------------------
index : 1  =>  from 'a' elements : x
index :  2 =>  from 'a' elements : y

p3a1:H[1,1]: p1a1;
p3a2:H[1,2]: p2a2;
p3a3:H[2,1]: p2b2;
p3a4:H[2,2]: p1b1;

result : Hessian
=============

symbolic
========

p4:'H = H;

values rhs 'from above hessian', with 'HH'

values
======

qq1: value matrix
--------------------------

HH:genmatrix( b, 2, 2);

p4a1:HH[1,1]: rhs(p1a1);
p4a2:HH[1,2]: rhs(p2a2);
p4a3:HH[2,1]: rhs(p2b2);
p4a4:HH[2,2]: rhs(p1b1);

p4b:'HH =HH;

qq2: determinant(qq1)
----------------------------------

p4c:'determinant(lhs(p4b)) = determinant(rhs(p4b));

How to use : function hessian from 'above', name 'HM'
==============================================
M = Maxima

'see : concept hessian'

p5a:HM = hessian(f(x,y),[x,y]);

p5b:'determinant(lhs(p5a)) = determinant(rhs(p5a));

'see above : '
===========

result : 'p4b' =  'p5a'
result : 'p4c' = 'p5b'

Meaning  of hessian  (Optimization)
==============================
HM   = >  determinant (HM) > 0  
answer : Maximum or Minimum for f(x,y)
HM   = >  determinant (HM) < 0
answer : saddle point for f(x,y)

We see 'p5b': determinant positive value.
--------------------------------------------------------------

result : Max. or Min.
================

How to find out : Max or Min  =>  'h'
(check position  a[1,1])

h :  rhs(p5a);

check position: corresponding 'a[1,1]'

p6:p4;

check :  Maximum or Minimum 
==========================
=>  second order derivative 'sign' :  diff(f(x,y),x,2)

if h[1,1] <0 then disp(maximum) else disp(minimum);

rem : use  'disp' : Maxima

we will use 'hessian ' from maxima future parts optimization.

'------------------------------------------------------------------------------------------'