OptimizationTechniques/Work 1/scripts/golden_section/golden_section_over_lambda.m

39 lines
805 B
Matlab

%
% Test the iteration needed for different lambda values.
%
% Clear workspace and load the functions and interval
clear
addpath('..');
GivenEnv;
% * lambda_min: 0.0001
% * lambda_max: 0.1
% * N: 50 points
N = 50;
lambda_min = 0.0001;
lambda_max = 0.1;
lambda = linspace(lambda_min, lambda_max, N);
k = zeros(1, N); % preallocate k
%
% * Call the golden_sector method for each lambda value for each function and
% keep the number of iterations needed.
% * Plot the iterations k(lambda) for each function
%
for i = 1:length(funs)
for j = 1:N
[a, b, k(j)] = golden_section(funs{i}, a_0, b_0, lambda(j));
end
subplot(1, length(funs), i)
plot(lambda, k, '-b', 'LineWidth', 1.0)
title(titles(i), 'Interpreter', 'latex')
xlabel('lambda')
ylabel('Iterations')
end