-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.m
59 lines (45 loc) · 1.26 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% -------------------------------------------------------------------
% Non-Linear Optimization
% Author: Thiago Lima Silva ([email protected])
% -------------------------------------------------------------------
% Make sure the workspace is clean before we start
clc
clear
clear global
addpath(genpath('library'));
addpath(genpath('algorithms'));
addpath(genpath('testFunctions'));
%%
% intial point
x0=[-1; 2]; %%
% Ghraphic: plot the function to be minimized
xmin = -2;
xmax = 2;
dx = .05;
ymin = -1;
ymax = 3;
dy = .05;
[z,y]= meshgrid(xmin:dx:xmax, ymin:dy:ymax);
banana=10*z.^4 - 20*(z.^2).*y + 10*y.^2 + z.^2 -2*z + 5;
contour(z,y,banana,30);
axis('square');
hold all;
%% Creating an automatic diff object
% [x,y] = initVariablesADI(x0(1),x0(2));
% xk = [x;y]; %% initial point with ADI
xk = x0;
%% Anonymous functions
fbanana = @(xk) fban(xk);
gbanana = @(xk) gban(xk);
hbanana = @(xk) hban(xk);
fsquare = @(xk) squareX(xk);
%% Search direction method
optType = 4; % SteepestDescent = 1, Newton = 2, DFP = 3, BFGS = 4, SR1 = 5
%% Line search type
lsType = 1; % Armijo = 1, ArmijoGoldstein=2, Polynomial = 3
%% Invoking optimization algorithm
tic
% for i=1:100
[xs, fs, gs] = gradientDescent(fbanana, gbanana, hbanana, xk, optType, lsType);
% end
toc