-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.m
41 lines (30 loc) · 997 Bytes
/
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
%% This is a basic implementation of the ARC optimisation algorithm.
%% State the problem, initialise
% Create an objective function, gradient handle and hessian handle as
% symbolic objects
syms a b c;
f_sym = symfun(a^4 + b^2 + c^6, [ a b c]);
g_sym = gradient(f_sym);
H_sym = hessian(f_sym);
% Convert to matlab function handles
f = matlabFunction(f_sym,'Vars',{[ a b c]});
g = matlabFunction(g_sym,'Vars',{[ a b c]});
H = matlabFunction(H_sym,'Vars',{[ a b c]});
% Initial guess
x0 = [1 2 3];
%% If the input argument is two dimensional:
if length(x0) == 2
xmin = -5;
xmax = 5;
ymin= -5;
ymax = 5;
px = 100; % Points in either direction
py = 100;
figure('Name', 'Surface plot of f');
plotF( f, xmin, xmax, ymin, ymax, px, py );
end
%% Call the optimiser
% There is a problem in the lanczos algorithm
outputLevel = 2;
options = struct('outputLevel', outputLevel);
[MIN, iterates, gradients, k, RES] = ARC( f, g, H, x0, options );