% maxim, maximum till Q(x,y) = (x+sin(y))*exp(-x^2-y^2)
% Newtons metod på grad Q = 0
  clear
  x=0.4, y=0,  Q=(x+sin(y))*exp(-x^2-y^2)
  p=[x y]';  dpnorm=1;  iter=0;
  while dpnorm>1e-5
     s=x+sin(y);
    f=[1-2*x*s                               % f = grad Q
       cos(y)-2*y*s];            
    J=[-4*x-2*sin(y)     -2*x*cos(y)         % jacobianen till f
        -2*y     -2*x-3*sin(y)-2*y*cos(y)];
    dp=-J\f; p=p+dp; dpnorm=norm(dp,inf),  iter=iter+1;
    x=p(1); y=p(2);   Q=(x+sin(y))*exp(-x^2-y^2)
  end
  xy_maxkoord=p', Qmax=Q, iter

 
 
