close all;
clear all;
clc;


%% Display function
[X,Y] = meshgrid(-30:2:30,-30:2:30);
Z = (X-2).^2 + 2*(Y-3).^2;
%surf(X,Y,Z);
contour(X,Y,Z,20);
hold on;
% Axis labels
xlabel ('X');
ylabel ('Y');
title ('f(x,y)=(x-2)² + 2(y-3)²');


%% Parameters
% Starting point
X=[30;20];
% Step size multiplier
alpha=0.05;


%% Gradient descent
for i=1:200    
    plot (X(1),X(2),'k.');
    X= X - alpha * [ 2*X(1)-4 ; 4*X(2)-12 ];
end


%% Diplay result
X
F=(X(1)-2).^2 + 2*(X(2)-3).^2


%% Expected output
% X =
%
%    2.0000
%    3.0000
%
%
% F =
%
%   3.9023e-16