diff --git a/.gitignore b/.gitignore index f6e6886..27d5772 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ *.log *.synctex.gz +# Matlab related +*.m~ + diff --git a/Work 1/report/report.pdf b/Work 1/report/report.pdf new file mode 100644 index 0000000..1e84614 Binary files /dev/null and b/Work 1/report/report.pdf differ diff --git a/Work 1/report/report.tex b/Work 1/report/report.tex new file mode 100644 index 0000000..90750b9 --- /dev/null +++ b/Work 1/report/report.tex @@ -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} diff --git a/Work 1/scripts/bisection.m b/Work 1/scripts/bisection.m new file mode 100644 index 0000000..735cd88 --- /dev/null +++ b/Work 1/scripts/bisection.m @@ -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 + diff --git a/Work 1/scripts/bisectionA_lamdaFixed.m b/Work 1/scripts/bisectionA_lamdaFixed.m new file mode 100644 index 0000000..3caa575 --- /dev/null +++ b/Work 1/scripts/bisectionA_lamdaFixed.m @@ -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 + + \ No newline at end of file diff --git a/Work 1/scripts/funGivenEnv.m b/Work 1/scripts/funGivenEnv.m new file mode 100644 index 0000000..e744843 --- /dev/null +++ b/Work 1/scripts/funGivenEnv.m @@ -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]; \ No newline at end of file