@@ -4,3 +4,6 @@ | |||||
*.log | *.log | ||||
*.synctex.gz | *.synctex.gz | ||||
# Matlab related | |||||
*.m~ | |||||
@@ -0,0 +1,41 @@ | |||||
% | |||||
% Optimization Techniques Assignment 1 report | |||||
% | |||||
% authors: | |||||
% Χρήστος Χουτουρίδης ΑΕΜ 8997 | |||||
% cchoutou@ece.auth.gr | |||||
\documentclass[a4paper, 11pt]{AUTHReport} | |||||
% Document configuration | |||||
\AuthorName{Χρήστος Χουτουρίδης} | |||||
\AuthorMail{cchoutou@ece.auth.gr} | |||||
\AuthorAEM{8997} | |||||
% \CoAuthorName{CoAuthor Name} | |||||
% \CoAuthorMail{CoAuthor Mail} | |||||
% \CoAuthorAEM{AEM} | |||||
% \WorkGroup{Ομάδα Χ} | |||||
\DocTitle{1η Εργαστηριακή Άσκηση} | |||||
\DocSubTitle{Ελαχιστοποίηση κυρτής συνάρτησης μιας μεταβλητής σε δοσμένο διάστημα} | |||||
\Department{Τμήμα ΗΜΜΥ. Τομέας Ηλεκτρονικής} | |||||
\ClassName{Τεχνικές Βελτιστοποίησης} | |||||
\InstructorName{Γ. Ροβιθάκης} | |||||
\InstructorMail{rovithak@auth.gr} | |||||
\CurrentDate{\today} | |||||
\begin{document} | |||||
\InsertTitle | |||||
\section{Εισαγωγή} | |||||
\end{document} |
@@ -0,0 +1,34 @@ | |||||
function [a, b, k] = bisection(fun, alpha, beta, epsilon, lambda) | |||||
% | |||||
% Detailed explanation goes here | |||||
% | |||||
% | |||||
% Error checking | |||||
if 2*epsilon >= lambda | |||||
error ('Convergence criteria not met') | |||||
end | |||||
% Init output vectors | |||||
a = alpha; | |||||
b = beta; | |||||
k=1; | |||||
while b(k) - a(k) > lambda | |||||
% bisect [a,b] | |||||
mid = (a(k) + b(k)) / 2; | |||||
x_1 = mid - epsilon; | |||||
x_2 = mid + epsilon; | |||||
% set new search reange | |||||
k = k + 1; | |||||
if subs(fun, x_1) < subs(fun, x_2) | |||||
a(k) = a(k-1); | |||||
b(k) = x_2; | |||||
else | |||||
a(k) = x_1; | |||||
b(k) = b(k-1); | |||||
end | |||||
end | |||||
@@ -0,0 +1,45 @@ | |||||
% | |||||
% Keeping l (accuracy) fix, test the iteration needed for different e | |||||
% values. | |||||
% | |||||
% Clear workspace and load the functions and region | |||||
clear | |||||
funGivenEnv; | |||||
% * lambda = 0.01 | |||||
% * epsilon: e < lambda/2 = 0.005 | |||||
% * de: A small step away from zero and lambda/2 | |||||
% de = 0.0001 | |||||
% * size: 25 points | |||||
size = 25; | |||||
lambda = 0.01; | |||||
de = 0.0001; | |||||
epsilon = linspace(de, (lambda/2)-de, size); | |||||
k = zeros(1,size); | |||||
% | |||||
% * Call the bisection method for each epsilon value for each function and | |||||
% keep the number of iterations needed. | |||||
% * Plot the (epsilon, iterations) for each function | |||||
% | |||||
i = 0; | |||||
for f = funs | |||||
i = i + 1; | |||||
j = 0; | |||||
for e = epsilon | |||||
j = j + 1; | |||||
[a, b, k(j)] = bisection(f, a_0, b_0, e, lambda); | |||||
end | |||||
subplot(1, 3, i) | |||||
plot(epsilon, k, '-b', 'LineWidth', 1.0) | |||||
title(titles(i), 'Interpreter', 'latex') | |||||
xlabel('epsilon') | |||||
ylabel('Iterations') | |||||
end | |||||
@@ -0,0 +1,18 @@ | |||||
% | |||||
% Select the given region: [-1,3] | |||||
a_0 = -1; | |||||
b_0 = 3; | |||||
% Setup the functions under test | |||||
syms x; | |||||
f_1 = (x-2)^2 + x*log(x+3); | |||||
f_2 = exp(-2*x) + (x-2)^2; | |||||
f_3 = exp(x)*(x^3 - 1) + (x-1)*sin(x); | |||||
funs = [f_1, f_2, f_3]; | |||||
% Setup the function titles | |||||
title_f1 = "$f_1(x) = (x - 2)^2 + x \cdot \ln(x + 3)$"; | |||||
title_f2 = "$f_2(x) = e^{-2x} + (x - 2)^2$"; | |||||
title_f3 = "$f_3(x) = e^x \cdot (x^3 - 1) + (x - 1) \cdot \sin(x)$"; | |||||
titles = [title_f1; title_f2; title_f3]; |