-
Notifications
You must be signed in to change notification settings - Fork 0
/
main1.m
33 lines (28 loc) · 1.1 KB
/
main1.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
% Main Script
clear all; close all;
% Drawing contour lines of the rosenbrock function near the minimum
[xgrid, ygrid] = meshgrid(-1.2:0.1:1.2, -0.5:0.1:1.5);
row = size(xgrid,1); col = size(xgrid,2);
for i = 1:row
for j = 1:col
x = [xgrid(i,j); ygrid(i,j)];
func(i,j) = rosenbrock(x);
end
end
figure;
contour(xgrid, ygrid,func,30); title('Contour Lines of Rosenbrock Function')
% Convergence properties of BT steepest descent algorithm
x0 = [-1.2 1]'; % starting point of search
%[sol, hist, telapsed] = Linesearchcover(@rosenbrock, @rosenGradient, x0);
[sol, hist, telapsed] = Linesearchcover3(@rosenbrock, @rosenGradient, x0);
for i = 1:length(hist) % no of iterations actually run
funchist(i) = rosenbrock(hist(:,i));
end
semilogy(1:length(hist), funchist) % takes log of y-axis alone
xlabel('Iterations'); ylabel('Error of |f - f*|');
title('Convergence Evaluation')
% plotting the convergence on the contour plot ...
figure;
contour(xgrid, ygrid,func,30); grid;title('Contour Lines of Rosenbrock Function')
hold on;
plot(hist(1,:), hist(2,:), 'ko-')