-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteepest_armijo.m
40 lines (36 loc) · 1.31 KB
/
steepest_armijo.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
function [Solution, A, Iterate]= steepest_armijo(x,tao,beta,obj,g, epsilon)
% file name: steepest_armijo.m
% This is for the steepest descent (gradient) method using the Armijo step-size rule.
% It terminates when the norm of the gradient is less than a given small number 'epsilon'(>0).
% The function is defined in the file 'Rosenbrock.m'.
% The gradient is given the file 'Rosenbrock_grad.m'.
k=1; % the index of iterations (search steps)
axes('FontSize',20);
% Iteration procedure
while norm(g) > epsilon
d = -g; % steepest descent direction
a = 1;
newobj = rosenbrock(x + a*d);
while (newobj-obj) > a * beta * g'*d
a = a*tao;
newobj = rosenbrock(x + a*d);
end
if (mod(k,100)==1)
% fprintf('Number of iteration is: %10u\n',k);
plot(x(1),x(2),'ro','LineWidth',15); grid,
title(['Iteration = ',num2str(k)]);
xlabel('x_1','FontSize',28),ylabel('x_2','FontSize',28),
pause(0.1);
end
x = x + a*d;
obj = newobj;
g = rosenbrock_grad(x);
A(k) = a;
Solution(k,:)= x;
Iterate(k) = k;
k = k + 1;
end
% Iteration end
A = A';
%Iterate = Iterate';
x, k % Display x and k