diff --git a/NotProgramming/ELAC/elacProjectA/project.tex b/NotProgramming/ELAC/elacProjectA/project.tex
index 3c0d7ef2..59a14d83 100644
--- a/NotProgramming/ELAC/elacProjectA/project.tex
+++ b/NotProgramming/ELAC/elacProjectA/project.tex
@@ -16,602 +16,9 @@
\begin{document}
\maketitle
-\section{Regular expression}
-We are given following regular expression:
-\[ a^* + ba^*b + bba^*\]
-
-\section{Examples of accepted strings}
-\begin{enumerate}
-\item $ \varepsilon $
-\item a
-\item bab
-\item bba
-\item bb
-\end{enumerate}
-
-\section{Building NFA using Thompson construction algorithm}
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q0) [state, initial, initial text = {}] {$q_0$};
-\node (q1) [state, accepting, right = of q0] {$q_1$};
-
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\end{tikzpicture}
-\caption{Operator 'a'} \label{fig:operatorA}
-\end{figure}
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q0) [state, initial, initial text = {}] {$q_2$};
-\node (q1) [state, accepting, right = of q0] {$q_3$};
-
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\end{tikzpicture}
-\caption{Operator 'b'} \label{fig:operatorB}
-\end{figure}
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q0) [state, initial, initial text = {}] {$q_4$};
-\node (q1) [state, right = of q0] {$q_0$};
-\node (q2) [state, right = of q1] {$q_1$};
-\node (q3) [state, accepting, right = of q2] {$q_5$};
-
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q1) edge node {a} (q2);
-\path [-stealth, thick]
- (q2) [bend left] edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q2) edge node {$\varepsilon$} (q3);
-\end{tikzpicture}
-\caption{Operator '$a^*$'} \label{fig:operatorAstar}
-\end{figure}
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q6) [state, initial, initial text = {}] {$q_2$};
-\node (q0) [state, right = of q6] {$q_4$};
-\node (q1) [state, right = of q0] {$q_0$};
-\node (q2) [state, right = of q1] {$q_1$};
-\node (q3) [state, accepting, right = of q2] {$q_5$};
-
-\path [-stealth, thick]
- (q6) edge node {$b$} (q0);
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q1) edge node {a} (q2);
-\path [-stealth, thick]
- (q2) [bend left] edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q2) edge node {$\varepsilon$} (q3);
-\end{tikzpicture}
-\caption{Operator '$ba^*$'} \label{fig:operatorbastar}
-\end{figure}
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q6) [state, initial, initial text = {}] {$q_6$};
-\node (q0) [state, right = of q6] {$q_4$};
-\node (q1) [state, right = of q0] {$q_0$};
-\node (q2) [state, right = of q1] {$q_1$};
-\node (q3) [state, right = of q2] {$q_5$};
-\node (q7) [state, accepting, right = of q3] {$q_7$};
-
-\path [-stealth, thick]
- (q6) edge node {$b$} (q0);
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q1) edge node {a} (q2);
-\path [-stealth, thick]
- (q2) [bend left] edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q2) edge node {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q3) edge node {$b$} (q7);
-
-\end{tikzpicture}
-\caption{Operator '$ba^*b$'} \label{fig:operatorbastarb}
-\end{figure}
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q8) [state, initial, initial text = {}] {$q_2$};
-\node (q9) [state, right = of q8] {$q_3$};
-\node (q4) [state, accepting, right = of q9] {$q_{4}$};
-
-\path [-stealth, thick]
- (q8) edge node {$b$} (q9);
-\path [-stealth, thick]
- (q9) edge node {$b$} (q4);
-
-
-\end{tikzpicture}
-\caption{Operator '$bb$'} \label{fig:operatorbb}
-\end{figure}
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q8) [state, initial, initial text = {}] {$q_2$};
-\node (q9) [state, right = of q8] {$q_3$};
-\node (q0) [state, right = of q9] {$q_4$};
-\node (q1) [state, right = of q0] {$q_0$};
-\node (q2) [state, right = of q1] {$q_1$};
-\node (q3) [state, accepting, right = of q2] {$q_5$};
-
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q1) edge node {a} (q2);
-\path [-stealth, thick]
- (q2) [bend left] edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q2) edge node {$\varepsilon$} (q3);
-
-\path [-stealth, thick]
- (q8) edge node {$b$} (q9);
-\path [-stealth, thick]
- (q9) edge node {$b$} (q4);
-\end{tikzpicture}
-\caption{Operator '$bba^*$'} \label{fig:operatorbbastar}
-\end{figure}
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q10) [state, initial, initial text = {}] {$q_{10}$};
-% a*
-
-\node (q0) [state, above right = of q10] {$q_4$};
-\node (q1) [state, right = of q0] {$q_0$};
-\node (q2) [state, right = of q1] {$q_1$};
-\node (q3) [state, right = of q2] {$q_5$};
-% ba*b
-\node (q4) [state, below right = of q10] {$q_6$};
-\node (q5) [state, right = of q4] {$q_8$};
-\node (q6) [state, right = of q5] {$q_9$};
-\node (q7) [state, right = of q6] {$q_{12}$};
-\node (q8) [state, right = of q7] {$q_{13}$};
-\node (q9) [state, right = of q8] {$q_7$};
-
-\node (q11) [state, accepting, above right = of q9] {$q_{11}$};
-
-\path [-stealth, thick]
- (q10) edge node {$\varepsilon$} (q0);
-
-\path [-stealth, thick]
- (q10) edge node {$\varepsilon$} (q4);
-
-% a*
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q1) edge node {a} (q2);
-\path [-stealth, thick]
- (q2) [bend left] edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q2) edge node {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q3) edge node {$\varepsilon$} (q11);
-
-% ba*b
-\path [-stealth, thick]
- (q4) edge node {$b$} (q5);
-\path [-stealth, thick]
- (q5) edge node {$\varepsilon$} (q6);
-\path [-stealth, thick]
- (q5) edge [bend right] node[below left] {$\varepsilon$} (q8);
-\path [-stealth, thick]
- (q6) edge node {a} (q7);
-\path [-stealth, thick]
- (q7) [bend left] edge node {$\varepsilon$} (q6);
-\path [-stealth, thick]
- (q7) edge node {$\varepsilon$} (q8);
-\path [-stealth, thick]
- (q8) edge node {$b$} (q9);
-\path [-stealth, thick]
- (q9) edge node {$\varepsilon$} (q11);
-\end{tikzpicture}
-\caption{Operator '$a^*+ba^*b$'} \label{fig:operatorastarOrbastarb}
-\end{figure}
-
-\begin{figure}[!htb]
-\begin{tikzpicture} [node distance = 1.5cm, on grid, auto]
-
-\node (q12) [state, initial, initial text = {}] {$q_{12}$};
-
-\node (q10) [state, above right = of q12] {$q_{10}$};
-% a*
-
-\node (q0) [state, above right = of q10] {$q_4$};
-\node (q1) [state, right = of q0] {$q_0$};
-\node (q2) [state, right = of q1] {$q_1$};
-\node (q3) [state, right = of q2] {$q_5$};
-% ba*b
-\node (q4) [state, below right = of q10] {$q_6$};
-\node (q5) [state, right = of q4] {$q_8$};
-\node (q6) [state, right = of q5] {$q_9$};
-\node (q7) [state, right = of q6] {$q_{12}$};
-\node (q8) [state, right = of q7] {$q_{13}$};
-\node (q9) [state, right = of q8] {$q_7$};
-
-\node (q11) [state, above right = of q9] {$q_{11}$};
-
-\node (q13) [state, accepting, below right = of q11] {$q_{13}$};
-
-% bba*
-\node (q14) [state, below right = of q12] {$q_{14}$};
-\node (q15) [state, right = of q14] {$q_{15}$};
-\node (q16) [state, right = of q15] {$q_{16}$};
-\node (q17) [state, right = of q16] {$q_{17}$};
-\node (q18) [state, right = of q17] {$q_{18}$};
-\node (q19) [state, right = of q18] {$q_{19}$};
-
-\path [-stealth, thick]
- (q12) edge node {$b$} (q14);
-
-\path [-stealth, thick]
- (q14) edge node {$b$} (q15);
-\path [-stealth, thick]
- (q15) edge node {$b$} (q16);
-\path [-stealth, thick]
- (q16) edge node {$\varepsilon$} (q17);
-\path [-stealth, thick]
- (q16) edge [bend right] node[below left] {$\varepsilon$} (q19);
-\path [-stealth, thick]
- (q17) edge node {$a$} (q18);
-\path [-stealth, thick]
- (q18) edge node {$\varepsilon$} (q19);
-\path [-stealth, thick]
- (q18) [bend left] edge node {$\varepsilon$} (q17);
-\path [-stealth, thick]
- (q19) edge [bend right] node {$b$} (q13);
-
-\path [-stealth, thick]
- (q12) edge node {$\varepsilon$} (q10);
-
-\path [-stealth, thick]
- (q10) edge node {$\varepsilon$} (q0);
-
-\path [-stealth, thick]
- (q10) edge node {$\varepsilon$} (q4);
-
-% a*
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q1) edge node {a} (q2);
-\path [-stealth, thick]
- (q2) [bend left] edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q2) edge node {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q3) edge node {$\varepsilon$} (q11);
-
-% ba*b
-\path [-stealth, thick]
- (q4) edge node {$b$} (q5);
-\path [-stealth, thick]
- (q5) edge node {$\varepsilon$} (q6);
-\path [-stealth, thick]
- (q5) edge [bend left] node[below left] {$\varepsilon$} (q8);
-\path [-stealth, thick]
- (q6) edge node {a} (q7);
-\path [-stealth, thick]
- (q7) [bend left] edge node {$\varepsilon$} (q6);
-\path [-stealth, thick]
- (q7) edge node {$\varepsilon$} (q8);
-\path [-stealth, thick]
- (q8) edge node {$b$} (q9);
-\path [-stealth, thick]
- (q9) edge node {$\varepsilon$} (q11);
-\path [-stealth, thick]
- (q11) edge node {$\varepsilon$} (q13);
-
-% bba*
-
-\end{tikzpicture}
-\caption{Operator '$a^*+ba^*b + bba^*$'} \label{fig:final}
-\end{figure}
-
-\begin{figure}[!htb]
-\begin{tikzpicture} [node distance = 1.5cm, on grid, auto]
-
-\node (q12) [state, initial, initial text = {}] {$q_{0}$};
-
-\node (q10) [state, above right = of q12] {$q_{1}$};
-% a*
-
-\node (q0) [state, above right = of q10] {$q_3$};
-\node (q1) [state, right = of q0] {$q_6$};
-\node (q2) [state, right = of q1] {$q_9$};
-\node (q3) [state, right = of q2] {$q_{12}$};
-% ba*b
-\node (q4) [state, below right = of q10] {$q_4$};
-\node (q5) [state, right = of q4] {$q_7$};
-\node (q6) [state, right = of q5] {$q_{10}$};
-\node (q7) [state, right = of q6] {$q_{13}$};
-\node (q8) [state, right = of q7] {$q_{15}$};
-\node (q9) [state, right = of q8] {$q_{17}$};
-
-\node (q11) [state, above right = of q9] {$q_{18}$};
-
-\node (q13) [state, accepting, below right = of q11] {$q_{19}$};
-
-% bba*
-\node (q14) [state, below right = of q12] {$q_{2}$};
-\node (q15) [state, right = of q14] {$q_{5}$};
-\node (q16) [state, right = of q15] {$q_{8}$};
-\node (q17) [state, right = of q16] {$q_{11}$};
-\node (q18) [state, right = of q17] {$q_{14}$};
-\node (q19) [state, right = of q18] {$q_{16}$};
-
-\path [-stealth, thick]
- (q12) edge node {$b$} (q14);
-
-\path [-stealth, thick]
- (q14) edge node {$b$} (q15);
-\path [-stealth, thick]
- (q15) edge node {$b$} (q16);
-\path [-stealth, thick]
- (q16) edge node {$\varepsilon$} (q17);
-\path [-stealth, thick]
- (q16) edge [bend right] node[below left] {$\varepsilon$} (q19);
-\path [-stealth, thick]
- (q17) edge node {$a$} (q18);
-\path [-stealth, thick]
- (q18) edge node {$\varepsilon$} (q19);
-\path [-stealth, thick]
- (q18) [bend left] edge node {$\varepsilon$} (q17);
-\path [-stealth, thick]
- (q19) edge [bend right] node {$b$} (q13);
-
-\path [-stealth, thick]
- (q12) edge node {$\varepsilon$} (q10);
-
-\path [-stealth, thick]
- (q10) edge node {$\varepsilon$} (q0);
-
-\path [-stealth, thick]
- (q10) edge node {$\varepsilon$} (q4);
-
-% a*
-\path [-stealth, thick]
- (q0) edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q1) edge node {a} (q2);
-\path [-stealth, thick]
- (q2) [bend left] edge node {$\varepsilon$} (q1);
-\path [-stealth, thick]
- (q2) edge node {$\varepsilon$} (q3);
-\path [-stealth, thick]
- (q3) edge node {$\varepsilon$} (q11);
-
-% ba*b
-\path [-stealth, thick]
- (q4) edge node {$b$} (q5);
-\path [-stealth, thick]
- (q5) edge node {$\varepsilon$} (q6);
-\path [-stealth, thick]
- (q5) edge [bend left] node[below left] {$\varepsilon$} (q8);
-\path [-stealth, thick]
- (q6) edge node {a} (q7);
-\path [-stealth, thick]
- (q7) [bend left] edge node {$\varepsilon$} (q6);
-\path [-stealth, thick]
- (q7) edge node {$\varepsilon$} (q8);
-\path [-stealth, thick]
- (q8) edge node {$b$} (q9);
-\path [-stealth, thick]
- (q9) edge node {$\varepsilon$} (q11);
-\path [-stealth, thick]
- (q11) edge node {$\varepsilon$} (q13);
-
-% bba*
-
-\end{tikzpicture}
-\caption{Operator '$a^*+ba^*b + bba^*$' - changed names of states} \label{fig:finalBetter}
-\end{figure}
-
-\section{Transforming NFA into DFA using subset algorithm}
-I will use $\epsilon_{cl}$ instead of $\epsilon$-closure for brevity sake.
-Final state - $\underline{q_{19}}$ was marked with an $\underline{underline}$ and so did all the states of DFA that contain it.
-\[ A = \epsilon_{cl}(q_0) = (q_0, q_1, q_3, q_4, q_6, q_{12}, q_{18}, \underline{q_{19}}) = \underline{A} \]
-\[ \epsilon_{cl}(move(\underline{A}, a)) = (\epsilon_{cl}(move(q_0, q_1, q_3, q_4, q_6, q_{12}, q_{18}, \underline{q_{19}}, a))) = \epsilon_{cl}(q_9) = (q_6, q_9, q_{12}, q_{18}, \underline{q_{19}}) = \underline{B} \]
-\[ A = \epsilon_{cl}(move(\underline{A}, b)) = \epsilon_{cl}(move(q_0, q_1, q_3, q_4, q_6, q_{12}, q_{18}, \underline{q_{19}}, b))) = \epsilon_{cl}(q_2, q_7) = (q_2, q_7, q_{10}, q_{15}) = C \]
-\[ \epsilon_{cl}(move(\underline{B}, a)) = \epsilon_{cl}(move(q_6, q_9, q_{12}, q_{18}, \underline{q_{19}}), a) = \epsilon_{cl}(q_9) = (q_6, q_9, q_{12}, q_{18}, \underline{q_{19}}) = \underline{B} \]
-\[ \epsilon_{cl}(move(\underline{B}, b)) = \epsilon_{cl}(move(q_6, q_9, q_{12}, q_{18}, \underline{q_{19}}), b) = \emptyset \]
-\[ \epsilon_{cl}(move(C, a)) = \epsilon_{cl}(move(q_2, q_7, q_{10}, q_{15}), a) = \epsilon_{cl}(q_{13}) = (q_{10}, q_{13}, q_{15}) = D \]
-\[ \epsilon_{cl}(move(C, b)) = \epsilon_{cl}(move((q_2, q_7, q_{10}, q_{15}), b) = \epsilon_{cl}(q_{17}) = (q_{17}, q_{18}, \underline{q_{19}}) = \underline{E} \]
-\[ \epsilon_{cl}(move(D, a)) = \epsilon_{cl}(move((q_{10}, q_{13}, q_{15}), a) = \epsilon_{cl}(q_{13}) = (q_{10}, q_{13}, q_{15}) = D \]
-\[ \epsilon_{cl}(move(D, b)) = \epsilon_{cl}(move(q_{10}, q_{13}, q_{15}, b) = \epsilon_{cl}(q_{17}) = (q_{17}, q_{18}, \underline{q_{19}}) = \underline{E} \]
-\[ \epsilon_{cl}(move(\underline{E}, a)) = \epsilon_{cl}(move(q_{17}, q_{18}, \underline{q_{19}}), a) = \epsilon_{cl}(\emptyset) = \emptyset \]
-\[ \epsilon_{cl}(move(\underline{E}, b)) = \epsilon_{cl}(move(q_{17}, q_{18}, \underline{q_{19}}), b) = \epsilon_{cl}(\emptyset) = \emptyset \]
-
-\subsection{State table}
-\begin{center}
-\begin{tabular}{||c c c||}
- \hline
- State & a & b \\
- \hline
-$\underline{A}$ & $\underline{B}$ & C\\
- \hline
- $\underline{B}$ & $\underline{B}$ & $\emptyset$ \\
- \hline
- C & D & $\underline{E}$\\
- \hline
- D & D & $\underline{E}$\\
- \hline
- $\underline{E}$ & $\emptyset$ & $\emptyset$\\
- \hline
-$\emptyset$ & $\emptyset$ & $\emptyset$\\
- \hline
-\end{tabular}
-\end{center}
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
- \node (q0) [state, accepting, initial, initial text = {}] {A};
- \node (q1) [state, accepting, above right = of q0] {B};
- \node (q2) [state, below right = of q0] {C};
- \node (q3) [state, accepting, above right = of q2] {E};
- \node (q4) [state, below right = of q2] {D};
- \node (q5) [state, right = of q1] {$\emptyset$};
-
- \path [-stealth, thick]
- (q0) edge node {$a$} (q1);
-
- \path [-stealth, thick]
- (q0) edge node {$b$} (q2);
-
- \path [-stealth, thick]
- (q1) edge [loop] node {$a$} (q1);
-
- \path [-stealth, thick]
- (q2) edge node {$b$} (q4);
-
- \path [-stealth, thick]
- (q2) edge node {$b$} (q3);
-
- \path [-stealth, thick]
- (q4) edge [bend right] node {$b$} (q3);
-
- \path [-stealth, thick]
- (q4) edge [loop] node {$a$} (q4);
-
- \path [-stealth, thick]
- (q1) edge [bend left] node {$a$} (q5);
-
- \path [-stealth, thick]
- (q3) edge node {$a, b$} (q5);
-
- \path [-stealth, thick]
- (q5) edge [loop] node {$a, b$} (q5);
-
-
-
-
-\end{tikzpicture}
-\caption{DFA graph before minimalization} \label{dfaNominimalization}
-\end{figure}
-
-\section{Constructing minimal state DFA}
-
-\begin{tabular}{|*{7}{c|}}
- \cline{1-1}
- $\underline{A}$ \\ \cline{1-2}
- $\underline{B}$ & $x_1$ \\ \cline{1-3}
- C & $x_1$ & $x_1$ \\ \cline{1-4}
- D & $x_1$ & $x_1$ & $x_2$ \\ \cline{1-5}
- $\underline{E}$ & $x_1$ & $x_1$ & $x_1$ & $x_1$ \\ \cline{1-6}
- $\emptyset$ & $x_1$ & $x_1$ & $x_2$ & $x_2$ & $x_1$ \\ \hline
- & $\underline{A}$ & $\underline{B}$ & C & D & $\underline{E}$ & $\emptyset$ \\ \hline
-\end{tabular}
-
-\begin{enumerate}
- \item First I marked (with $x_1$) all the pairs in which at least one of them were final state:
- \[ ([\underline{A}, \emptyset], [\underline{A}, \underline{E}], [\underline{A}, D], [\underline{A}, C], [\underline{A}, \underline{B}]) \]
- \[ ([\underline{B}, \emptyset], ([\underline{B}, \underline{E}], ([\underline{B}, D], ([\underline{B}, C]) \]
- \[ ([\underline{E}, \emptyset], [\underline{E}, C], [\underline{E}, D])\]
-
- \item We are left with the pairs:
- \[ ([\emptyset , C], [\emptyset , D], [D , C] ) \]
- For pair: $ [\emptyset , C] $ C goes to final state $\underline{E}$ on transition 'b' therefore we mark it with $x_2$
- For pair: $ [\emptyset , D] $ D goes to final state $\underline{E}$ on transition 'b' therefore we mark it with $x_2$
- For pair: $ [D , C] $ both C and D go to final state $\underline{E}$ on transition 'b' therefore we mark it with $x_2$
-\end{enumerate}
-
-No states could be minimized! Therefore our final minimal state DFA looks like this:
-
-\begin{figure}[!htb]
-\centering
-\begin{tikzpicture} [node distance = 2cm, on grid, auto]
-
-\node (q0) [state, accepting, initial, initial text = {}] {A};
-\node (q1) [state, accepting, above right = of q0] {B};
-\node (q2) [state, below right = of q0] {C};
-\node (q3) [state, accepting, above right = of q2] {E};
-\node (q4) [state, below right = of q2] {D};
-\node (q5) [state, right = of q1] {$\emptyset$};
-
-\path [-stealth, thick]
-(q0) edge node {$a$} (q1);
-
-\path [-stealth, thick]
-(q0) edge node {$b$} (q2);
-
-\path [-stealth, thick]
-(q1) edge [loop] node {$a$} (q1);
-
-\path [-stealth, thick]
-(q2) edge node {$a$} (q4);
-
-\path [-stealth, thick]
-(q2) edge node {$b$} (q3);
-
-\path [-stealth, thick]
-(q4) edge node {$b$} (q3);
-
-\path [-stealth, thick]
-(q1) edge [bend left] node {$a, b$} (q5);
-
-\path [-stealth, thick]
-(q3) edge [below loop] node {$a$} (q3);
-
-\path [-stealth, thick]
-(q3) edge node {$a$} (q5);
-
-\path [-stealth, thick]
-(q4) edge [bend right] node {$a$} (q5);
-
-\path [-stealth, thick]
-(q5) edge [loop] node {$a, b$} (q5);
-
-
-
-
-
-\end{tikzpicture}
-\caption{DFA graph after minimalization} \label{dfaMinimalization}
-\end{figure}
-
-
-
-
+ \input{sections/01-regular-expression}
+ \input{sections/02-examples-of-accepted-strings}
+ \input{sections/03-building-nfa-using-thompson-construction-algorithm}
+ \input{sections/04-transforming-nfa-into-dfa-using-subset}
+ \input{sections/05-constructing-minimal-state-dfa}
\end{document}
diff --git a/NotProgramming/ELAC/elacProjectA/sections/01-regular-expression.tex b/NotProgramming/ELAC/elacProjectA/sections/01-regular-expression.tex
new file mode 100644
index 00000000..2cb13c69
--- /dev/null
+++ b/NotProgramming/ELAC/elacProjectA/sections/01-regular-expression.tex
@@ -0,0 +1,4 @@
+\section{Regular expression}
+We are given following regular expression:
+\[ a^* + ba^*b + bba^*\]
+
diff --git a/NotProgramming/ELAC/elacProjectA/sections/02-examples-of-accepted-strings.tex b/NotProgramming/ELAC/elacProjectA/sections/02-examples-of-accepted-strings.tex
new file mode 100644
index 00000000..49e2999b
--- /dev/null
+++ b/NotProgramming/ELAC/elacProjectA/sections/02-examples-of-accepted-strings.tex
@@ -0,0 +1,9 @@
+\section{Examples of accepted strings}
+\begin{enumerate}
+\item $ \varepsilon $
+\item a
+\item bab
+\item bba
+\item bb
+\end{enumerate}
+
diff --git a/NotProgramming/ELAC/elacProjectA/sections/03-building-nfa-using-thompson-construction-algorithm.tex b/NotProgramming/ELAC/elacProjectA/sections/03-building-nfa-using-thompson-construction-algorithm.tex
new file mode 100644
index 00000000..f536fd30
--- /dev/null
+++ b/NotProgramming/ELAC/elacProjectA/sections/03-building-nfa-using-thompson-construction-algorithm.tex
@@ -0,0 +1,418 @@
+\section{Building NFA using Thompson construction algorithm}
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q0) [state, initial, initial text = {}] {$q_0$};
+\node (q1) [state, accepting, right = of q0] {$q_1$};
+
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\end{tikzpicture}
+\caption{Operator 'a'} \label{fig:operatorA}
+\end{figure}
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q0) [state, initial, initial text = {}] {$q_2$};
+\node (q1) [state, accepting, right = of q0] {$q_3$};
+
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\end{tikzpicture}
+\caption{Operator 'b'} \label{fig:operatorB}
+\end{figure}
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q0) [state, initial, initial text = {}] {$q_4$};
+\node (q1) [state, right = of q0] {$q_0$};
+\node (q2) [state, right = of q1] {$q_1$};
+\node (q3) [state, accepting, right = of q2] {$q_5$};
+
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q1) edge node {a} (q2);
+\path [-stealth, thick]
+ (q2) [bend left] edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q2) edge node {$\varepsilon$} (q3);
+\end{tikzpicture}
+\caption{Operator '$a^*$'} \label{fig:operatorAstar}
+\end{figure}
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q6) [state, initial, initial text = {}] {$q_2$};
+\node (q0) [state, right = of q6] {$q_4$};
+\node (q1) [state, right = of q0] {$q_0$};
+\node (q2) [state, right = of q1] {$q_1$};
+\node (q3) [state, accepting, right = of q2] {$q_5$};
+
+\path [-stealth, thick]
+ (q6) edge node {$b$} (q0);
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q1) edge node {a} (q2);
+\path [-stealth, thick]
+ (q2) [bend left] edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q2) edge node {$\varepsilon$} (q3);
+\end{tikzpicture}
+\caption{Operator '$ba^*$'} \label{fig:operatorbastar}
+\end{figure}
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q6) [state, initial, initial text = {}] {$q_6$};
+\node (q0) [state, right = of q6] {$q_4$};
+\node (q1) [state, right = of q0] {$q_0$};
+\node (q2) [state, right = of q1] {$q_1$};
+\node (q3) [state, right = of q2] {$q_5$};
+\node (q7) [state, accepting, right = of q3] {$q_7$};
+
+\path [-stealth, thick]
+ (q6) edge node {$b$} (q0);
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q1) edge node {a} (q2);
+\path [-stealth, thick]
+ (q2) [bend left] edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q2) edge node {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q3) edge node {$b$} (q7);
+
+\end{tikzpicture}
+\caption{Operator '$ba^*b$'} \label{fig:operatorbastarb}
+\end{figure}
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q8) [state, initial, initial text = {}] {$q_2$};
+\node (q9) [state, right = of q8] {$q_3$};
+\node (q4) [state, accepting, right = of q9] {$q_{4}$};
+
+\path [-stealth, thick]
+ (q8) edge node {$b$} (q9);
+\path [-stealth, thick]
+ (q9) edge node {$b$} (q4);
+
+
+\end{tikzpicture}
+\caption{Operator '$bb$'} \label{fig:operatorbb}
+\end{figure}
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q8) [state, initial, initial text = {}] {$q_2$};
+\node (q9) [state, right = of q8] {$q_3$};
+\node (q0) [state, right = of q9] {$q_4$};
+\node (q1) [state, right = of q0] {$q_0$};
+\node (q2) [state, right = of q1] {$q_1$};
+\node (q3) [state, accepting, right = of q2] {$q_5$};
+
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q1) edge node {a} (q2);
+\path [-stealth, thick]
+ (q2) [bend left] edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q2) edge node {$\varepsilon$} (q3);
+
+\path [-stealth, thick]
+ (q8) edge node {$b$} (q9);
+\path [-stealth, thick]
+ (q9) edge node {$b$} (q4);
+\end{tikzpicture}
+\caption{Operator '$bba^*$'} \label{fig:operatorbbastar}
+\end{figure}
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q10) [state, initial, initial text = {}] {$q_{10}$};
+% a*
+
+\node (q0) [state, above right = of q10] {$q_4$};
+\node (q1) [state, right = of q0] {$q_0$};
+\node (q2) [state, right = of q1] {$q_1$};
+\node (q3) [state, right = of q2] {$q_5$};
+% ba*b
+\node (q4) [state, below right = of q10] {$q_6$};
+\node (q5) [state, right = of q4] {$q_8$};
+\node (q6) [state, right = of q5] {$q_9$};
+\node (q7) [state, right = of q6] {$q_{12}$};
+\node (q8) [state, right = of q7] {$q_{13}$};
+\node (q9) [state, right = of q8] {$q_7$};
+
+\node (q11) [state, accepting, above right = of q9] {$q_{11}$};
+
+\path [-stealth, thick]
+ (q10) edge node {$\varepsilon$} (q0);
+
+\path [-stealth, thick]
+ (q10) edge node {$\varepsilon$} (q4);
+
+% a*
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q1) edge node {a} (q2);
+\path [-stealth, thick]
+ (q2) [bend left] edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q2) edge node {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q3) edge node {$\varepsilon$} (q11);
+
+% ba*b
+\path [-stealth, thick]
+ (q4) edge node {$b$} (q5);
+\path [-stealth, thick]
+ (q5) edge node {$\varepsilon$} (q6);
+\path [-stealth, thick]
+ (q5) edge [bend right] node[below left] {$\varepsilon$} (q8);
+\path [-stealth, thick]
+ (q6) edge node {a} (q7);
+\path [-stealth, thick]
+ (q7) [bend left] edge node {$\varepsilon$} (q6);
+\path [-stealth, thick]
+ (q7) edge node {$\varepsilon$} (q8);
+\path [-stealth, thick]
+ (q8) edge node {$b$} (q9);
+\path [-stealth, thick]
+ (q9) edge node {$\varepsilon$} (q11);
+\end{tikzpicture}
+\caption{Operator '$a^*+ba^*b$'} \label{fig:operatorastarOrbastarb}
+\end{figure}
+
+\begin{figure}[!htb]
+\begin{tikzpicture} [node distance = 1.5cm, on grid, auto]
+
+\node (q12) [state, initial, initial text = {}] {$q_{12}$};
+
+\node (q10) [state, above right = of q12] {$q_{10}$};
+% a*
+
+\node (q0) [state, above right = of q10] {$q_4$};
+\node (q1) [state, right = of q0] {$q_0$};
+\node (q2) [state, right = of q1] {$q_1$};
+\node (q3) [state, right = of q2] {$q_5$};
+% ba*b
+\node (q4) [state, below right = of q10] {$q_6$};
+\node (q5) [state, right = of q4] {$q_8$};
+\node (q6) [state, right = of q5] {$q_9$};
+\node (q7) [state, right = of q6] {$q_{12}$};
+\node (q8) [state, right = of q7] {$q_{13}$};
+\node (q9) [state, right = of q8] {$q_7$};
+
+\node (q11) [state, above right = of q9] {$q_{11}$};
+
+\node (q13) [state, accepting, below right = of q11] {$q_{13}$};
+
+% bba*
+\node (q14) [state, below right = of q12] {$q_{14}$};
+\node (q15) [state, right = of q14] {$q_{15}$};
+\node (q16) [state, right = of q15] {$q_{16}$};
+\node (q17) [state, right = of q16] {$q_{17}$};
+\node (q18) [state, right = of q17] {$q_{18}$};
+\node (q19) [state, right = of q18] {$q_{19}$};
+
+\path [-stealth, thick]
+ (q12) edge node {$b$} (q14);
+
+\path [-stealth, thick]
+ (q14) edge node {$b$} (q15);
+\path [-stealth, thick]
+ (q15) edge node {$b$} (q16);
+\path [-stealth, thick]
+ (q16) edge node {$\varepsilon$} (q17);
+\path [-stealth, thick]
+ (q16) edge [bend right] node[below left] {$\varepsilon$} (q19);
+\path [-stealth, thick]
+ (q17) edge node {$a$} (q18);
+\path [-stealth, thick]
+ (q18) edge node {$\varepsilon$} (q19);
+\path [-stealth, thick]
+ (q18) [bend left] edge node {$\varepsilon$} (q17);
+\path [-stealth, thick]
+ (q19) edge [bend right] node {$b$} (q13);
+
+\path [-stealth, thick]
+ (q12) edge node {$\varepsilon$} (q10);
+
+\path [-stealth, thick]
+ (q10) edge node {$\varepsilon$} (q0);
+
+\path [-stealth, thick]
+ (q10) edge node {$\varepsilon$} (q4);
+
+% a*
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q1) edge node {a} (q2);
+\path [-stealth, thick]
+ (q2) [bend left] edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q2) edge node {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q3) edge node {$\varepsilon$} (q11);
+
+% ba*b
+\path [-stealth, thick]
+ (q4) edge node {$b$} (q5);
+\path [-stealth, thick]
+ (q5) edge node {$\varepsilon$} (q6);
+\path [-stealth, thick]
+ (q5) edge [bend left] node[below left] {$\varepsilon$} (q8);
+\path [-stealth, thick]
+ (q6) edge node {a} (q7);
+\path [-stealth, thick]
+ (q7) [bend left] edge node {$\varepsilon$} (q6);
+\path [-stealth, thick]
+ (q7) edge node {$\varepsilon$} (q8);
+\path [-stealth, thick]
+ (q8) edge node {$b$} (q9);
+\path [-stealth, thick]
+ (q9) edge node {$\varepsilon$} (q11);
+\path [-stealth, thick]
+ (q11) edge node {$\varepsilon$} (q13);
+
+% bba*
+
+\end{tikzpicture}
+\caption{Operator '$a^*+ba^*b + bba^*$'} \label{fig:final}
+\end{figure}
+
+\begin{figure}[!htb]
+\begin{tikzpicture} [node distance = 1.5cm, on grid, auto]
+
+\node (q12) [state, initial, initial text = {}] {$q_{0}$};
+
+\node (q10) [state, above right = of q12] {$q_{1}$};
+% a*
+
+\node (q0) [state, above right = of q10] {$q_3$};
+\node (q1) [state, right = of q0] {$q_6$};
+\node (q2) [state, right = of q1] {$q_9$};
+\node (q3) [state, right = of q2] {$q_{12}$};
+% ba*b
+\node (q4) [state, below right = of q10] {$q_4$};
+\node (q5) [state, right = of q4] {$q_7$};
+\node (q6) [state, right = of q5] {$q_{10}$};
+\node (q7) [state, right = of q6] {$q_{13}$};
+\node (q8) [state, right = of q7] {$q_{15}$};
+\node (q9) [state, right = of q8] {$q_{17}$};
+
+\node (q11) [state, above right = of q9] {$q_{18}$};
+
+\node (q13) [state, accepting, below right = of q11] {$q_{19}$};
+
+% bba*
+\node (q14) [state, below right = of q12] {$q_{2}$};
+\node (q15) [state, right = of q14] {$q_{5}$};
+\node (q16) [state, right = of q15] {$q_{8}$};
+\node (q17) [state, right = of q16] {$q_{11}$};
+\node (q18) [state, right = of q17] {$q_{14}$};
+\node (q19) [state, right = of q18] {$q_{16}$};
+
+\path [-stealth, thick]
+ (q12) edge node {$b$} (q14);
+
+\path [-stealth, thick]
+ (q14) edge node {$b$} (q15);
+\path [-stealth, thick]
+ (q15) edge node {$b$} (q16);
+\path [-stealth, thick]
+ (q16) edge node {$\varepsilon$} (q17);
+\path [-stealth, thick]
+ (q16) edge [bend right] node[below left] {$\varepsilon$} (q19);
+\path [-stealth, thick]
+ (q17) edge node {$a$} (q18);
+\path [-stealth, thick]
+ (q18) edge node {$\varepsilon$} (q19);
+\path [-stealth, thick]
+ (q18) [bend left] edge node {$\varepsilon$} (q17);
+\path [-stealth, thick]
+ (q19) edge [bend right] node {$b$} (q13);
+
+\path [-stealth, thick]
+ (q12) edge node {$\varepsilon$} (q10);
+
+\path [-stealth, thick]
+ (q10) edge node {$\varepsilon$} (q0);
+
+\path [-stealth, thick]
+ (q10) edge node {$\varepsilon$} (q4);
+
+% a*
+\path [-stealth, thick]
+ (q0) edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q0) edge [bend right] node[below left] {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q1) edge node {a} (q2);
+\path [-stealth, thick]
+ (q2) [bend left] edge node {$\varepsilon$} (q1);
+\path [-stealth, thick]
+ (q2) edge node {$\varepsilon$} (q3);
+\path [-stealth, thick]
+ (q3) edge node {$\varepsilon$} (q11);
+
+% ba*b
+\path [-stealth, thick]
+ (q4) edge node {$b$} (q5);
+\path [-stealth, thick]
+ (q5) edge node {$\varepsilon$} (q6);
+\path [-stealth, thick]
+ (q5) edge [bend left] node[below left] {$\varepsilon$} (q8);
+\path [-stealth, thick]
+ (q6) edge node {a} (q7);
+\path [-stealth, thick]
+ (q7) [bend left] edge node {$\varepsilon$} (q6);
+\path [-stealth, thick]
+ (q7) edge node {$\varepsilon$} (q8);
+\path [-stealth, thick]
+ (q8) edge node {$b$} (q9);
+\path [-stealth, thick]
+ (q9) edge node {$\varepsilon$} (q11);
+\path [-stealth, thick]
+ (q11) edge node {$\varepsilon$} (q13);
+
+% bba*
+
+\end{tikzpicture}
+\caption{Operator '$a^*+ba^*b + bba^*$' - changed names of states} \label{fig:finalBetter}
+\end{figure}
+
diff --git a/NotProgramming/ELAC/elacProjectA/sections/04-transforming-nfa-into-dfa-using-subset.tex b/NotProgramming/ELAC/elacProjectA/sections/04-transforming-nfa-into-dfa-using-subset.tex
new file mode 100644
index 00000000..03c68af1
--- /dev/null
+++ b/NotProgramming/ELAC/elacProjectA/sections/04-transforming-nfa-into-dfa-using-subset.tex
@@ -0,0 +1,84 @@
+\section{Transforming NFA into DFA using subset algorithm}
+I will use $\epsilon_{cl}$ instead of $\epsilon$-closure for brevity sake.
+Final state - $\underline{q_{19}}$ was marked with an $\underline{underline}$ and so did all the states of DFA that contain it.
+\[ A = \epsilon_{cl}(q_0) = (q_0, q_1, q_3, q_4, q_6, q_{12}, q_{18}, \underline{q_{19}}) = \underline{A} \]
+\[ \epsilon_{cl}(move(\underline{A}, a)) = (\epsilon_{cl}(move(q_0, q_1, q_3, q_4, q_6, q_{12}, q_{18}, \underline{q_{19}}, a))) = \epsilon_{cl}(q_9) = (q_6, q_9, q_{12}, q_{18}, \underline{q_{19}}) = \underline{B} \]
+\[ A = \epsilon_{cl}(move(\underline{A}, b)) = \epsilon_{cl}(move(q_0, q_1, q_3, q_4, q_6, q_{12}, q_{18}, \underline{q_{19}}, b))) = \epsilon_{cl}(q_2, q_7) = (q_2, q_7, q_{10}, q_{15}) = C \]
+\[ \epsilon_{cl}(move(\underline{B}, a)) = \epsilon_{cl}(move(q_6, q_9, q_{12}, q_{18}, \underline{q_{19}}), a) = \epsilon_{cl}(q_9) = (q_6, q_9, q_{12}, q_{18}, \underline{q_{19}}) = \underline{B} \]
+\[ \epsilon_{cl}(move(\underline{B}, b)) = \epsilon_{cl}(move(q_6, q_9, q_{12}, q_{18}, \underline{q_{19}}), b) = \emptyset \]
+\[ \epsilon_{cl}(move(C, a)) = \epsilon_{cl}(move(q_2, q_7, q_{10}, q_{15}), a) = \epsilon_{cl}(q_{13}) = (q_{10}, q_{13}, q_{15}) = D \]
+\[ \epsilon_{cl}(move(C, b)) = \epsilon_{cl}(move((q_2, q_7, q_{10}, q_{15}), b) = \epsilon_{cl}(q_{17}) = (q_{17}, q_{18}, \underline{q_{19}}) = \underline{E} \]
+\[ \epsilon_{cl}(move(D, a)) = \epsilon_{cl}(move((q_{10}, q_{13}, q_{15}), a) = \epsilon_{cl}(q_{13}) = (q_{10}, q_{13}, q_{15}) = D \]
+\[ \epsilon_{cl}(move(D, b)) = \epsilon_{cl}(move(q_{10}, q_{13}, q_{15}, b) = \epsilon_{cl}(q_{17}) = (q_{17}, q_{18}, \underline{q_{19}}) = \underline{E} \]
+\[ \epsilon_{cl}(move(\underline{E}, a)) = \epsilon_{cl}(move(q_{17}, q_{18}, \underline{q_{19}}), a) = \epsilon_{cl}(\emptyset) = \emptyset \]
+\[ \epsilon_{cl}(move(\underline{E}, b)) = \epsilon_{cl}(move(q_{17}, q_{18}, \underline{q_{19}}), b) = \epsilon_{cl}(\emptyset) = \emptyset \]
+
+\subsection{State table}
+\begin{center}
+\begin{tabular}{||c c c||}
+ \hline
+ State & a & b \\
+ \hline
+$\underline{A}$ & $\underline{B}$ & C\\
+ \hline
+ $\underline{B}$ & $\underline{B}$ & $\emptyset$ \\
+ \hline
+ C & D & $\underline{E}$\\
+ \hline
+ D & D & $\underline{E}$\\
+ \hline
+ $\underline{E}$ & $\emptyset$ & $\emptyset$\\
+ \hline
+$\emptyset$ & $\emptyset$ & $\emptyset$\\
+ \hline
+\end{tabular}
+\end{center}
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+ \node (q0) [state, accepting, initial, initial text = {}] {A};
+ \node (q1) [state, accepting, above right = of q0] {B};
+ \node (q2) [state, below right = of q0] {C};
+ \node (q3) [state, accepting, above right = of q2] {E};
+ \node (q4) [state, below right = of q2] {D};
+ \node (q5) [state, right = of q1] {$\emptyset$};
+
+ \path [-stealth, thick]
+ (q0) edge node {$a$} (q1);
+
+ \path [-stealth, thick]
+ (q0) edge node {$b$} (q2);
+
+ \path [-stealth, thick]
+ (q1) edge [loop] node {$a$} (q1);
+
+ \path [-stealth, thick]
+ (q2) edge node {$b$} (q4);
+
+ \path [-stealth, thick]
+ (q2) edge node {$b$} (q3);
+
+ \path [-stealth, thick]
+ (q4) edge [bend right] node {$b$} (q3);
+
+ \path [-stealth, thick]
+ (q4) edge [loop] node {$a$} (q4);
+
+ \path [-stealth, thick]
+ (q1) edge [bend left] node {$a$} (q5);
+
+ \path [-stealth, thick]
+ (q3) edge node {$a, b$} (q5);
+
+ \path [-stealth, thick]
+ (q5) edge [loop] node {$a, b$} (q5);
+
+
+
+
+\end{tikzpicture}
+\caption{DFA graph before minimalization} \label{dfaNominimalization}
+\end{figure}
+
diff --git a/NotProgramming/ELAC/elacProjectA/sections/05-constructing-minimal-state-dfa.tex b/NotProgramming/ELAC/elacProjectA/sections/05-constructing-minimal-state-dfa.tex
new file mode 100644
index 00000000..14a441f8
--- /dev/null
+++ b/NotProgramming/ELAC/elacProjectA/sections/05-constructing-minimal-state-dfa.tex
@@ -0,0 +1,83 @@
+\section{Constructing minimal state DFA}
+
+\begin{tabular}{|*{7}{c|}}
+ \cline{1-1}
+ $\underline{A}$ \\ \cline{1-2}
+ $\underline{B}$ & $x_1$ \\ \cline{1-3}
+ C & $x_1$ & $x_1$ \\ \cline{1-4}
+ D & $x_1$ & $x_1$ & $x_2$ \\ \cline{1-5}
+ $\underline{E}$ & $x_1$ & $x_1$ & $x_1$ & $x_1$ \\ \cline{1-6}
+ $\emptyset$ & $x_1$ & $x_1$ & $x_2$ & $x_2$ & $x_1$ \\ \hline
+ & $\underline{A}$ & $\underline{B}$ & C & D & $\underline{E}$ & $\emptyset$ \\ \hline
+\end{tabular}
+
+\begin{enumerate}
+ \item First I marked (with $x_1$) all the pairs in which at least one of them were final state:
+ \[ ([\underline{A}, \emptyset], [\underline{A}, \underline{E}], [\underline{A}, D], [\underline{A}, C], [\underline{A}, \underline{B}]) \]
+ \[ ([\underline{B}, \emptyset], ([\underline{B}, \underline{E}], ([\underline{B}, D], ([\underline{B}, C]) \]
+ \[ ([\underline{E}, \emptyset], [\underline{E}, C], [\underline{E}, D])\]
+
+ \item We are left with the pairs:
+ \[ ([\emptyset , C], [\emptyset , D], [D , C] ) \]
+ For pair: $ [\emptyset , C] $ C goes to final state $\underline{E}$ on transition 'b' therefore we mark it with $x_2$
+ For pair: $ [\emptyset , D] $ D goes to final state $\underline{E}$ on transition 'b' therefore we mark it with $x_2$
+ For pair: $ [D , C] $ both C and D go to final state $\underline{E}$ on transition 'b' therefore we mark it with $x_2$
+\end{enumerate}
+
+No states could be minimized! Therefore our final minimal state DFA looks like this:
+
+\begin{figure}[!htb]
+\centering
+\begin{tikzpicture} [node distance = 2cm, on grid, auto]
+
+\node (q0) [state, accepting, initial, initial text = {}] {A};
+\node (q1) [state, accepting, above right = of q0] {B};
+\node (q2) [state, below right = of q0] {C};
+\node (q3) [state, accepting, above right = of q2] {E};
+\node (q4) [state, below right = of q2] {D};
+\node (q5) [state, right = of q1] {$\emptyset$};
+
+\path [-stealth, thick]
+(q0) edge node {$a$} (q1);
+
+\path [-stealth, thick]
+(q0) edge node {$b$} (q2);
+
+\path [-stealth, thick]
+(q1) edge [loop] node {$a$} (q1);
+
+\path [-stealth, thick]
+(q2) edge node {$a$} (q4);
+
+\path [-stealth, thick]
+(q2) edge node {$b$} (q3);
+
+\path [-stealth, thick]
+(q4) edge node {$b$} (q3);
+
+\path [-stealth, thick]
+(q1) edge [bend left] node {$a, b$} (q5);
+
+\path [-stealth, thick]
+(q3) edge [below loop] node {$a$} (q3);
+
+\path [-stealth, thick]
+(q3) edge node {$a$} (q5);
+
+\path [-stealth, thick]
+(q4) edge [bend right] node {$a$} (q5);
+
+\path [-stealth, thick]
+(q5) edge [loop] node {$a, b$} (q5);
+
+
+
+
+
+\end{tikzpicture}
+\caption{DFA graph after minimalization} \label{dfaMinimalization}
+\end{figure}
+
+
+
+
diff --git a/NotProgramming/ENUME/projectA/projectA.tex b/NotProgramming/ENUME/projectA/projectA.tex
index 4e9d2900..c69d8150 100755
--- a/NotProgramming/ENUME/projectA/projectA.tex
+++ b/NotProgramming/ENUME/projectA/projectA.tex
@@ -45,1832 +45,24 @@ linkto=all,
\chapter{Problem 1 - Finding machine epsilion}
-\section{Problem}
-Write a program finding macheps in the MATLAB environment
-\section{Theoretical Introduction}
-\subsection{Definition of machine epsilion}
-Machine epsilion is the maximal possible relative error of the floating-point representation. (Tatjewski, p.14)
-Machine epsilion is equal to $2^{-t}$ where t is number of bits in the mantissa.
-In our case where we use IEEE Standard 754, mantissa is 53 bits long with first bit omitted as it is always equal to '1', so we technicaly work with 52 bits mantissa which makes the machine epsilion equal to: $2^{-52} = 2.220446\mathrm{e}{-16}$
-
-\newpage
-\subsection{Practical applications of machine epsilion}
-Since macheps is connected to IEEE754 standard it is always equal to the same number, which means that we can safely compare results from different machines without worrying about their individual errors. Before standards, everyone could use any way of representing floats.
-
-Macheps is also essential when we calculate cumulation of errors of given mathematical operation.
-
-\newpage
-\section{Solution}
-
-
-\hyperlink{function1_macheps}{Code for finding macheps} shifts macheps one bit to the right each iteration (by dividing by 2), it ends when we run out of mantissa bits which renders us unable to save smaller number. Due to underflow the value of macheps becomes 0 and therefore 1.0 > (macheps / 2) > 1.0 will become false.
-\newpage
-\section{Results}
-\hyperlink{function1_display}{Code for displaying results}\\
-Display calculated macheps:
- \[2.220446049250313\mathrm{e}{-16}\]
-
-Display actual eps:
- \[2.220446049250313\mathrm{e}{-16}\]
-
-Display $2^{-52}$:
- \[2.220446049250313\mathrm{e}{-16}\]
-
-Display difference between calculated macheps and actual eps:
- \[0\]
-
-Display difference between $2^{-52}$ and actual eps:
- \[0\]
-
-Display difference between calculated macheps and $2^{-52}$:
- \[0\]
-
-As expected they are all equal to each other. It means that our method of calculating macheps was correct.
-
-\chapter{Problem 2 - Solving a system of n linear equations - indicated method}
-
-\section{Problem}
-Write a program solving a system of \textit{n} linear equations Ax = b using the indicated method (Gaussian elimination with partial pivoting).
-
-\section{Theoretical Introduction}
-Gaussian elimination with partial pivoting consists of 3 main steps:
-\subsection{Transform matrix into upper-triangular matrix}
-
-\subsubsection{Starting conditions}
-We start with the system of linear equations looking like this:
-
-\[
-\begin{matrix}
-
-&a_{11}x_1 &{}+&a_{12}x_2&+&\dots&+&a_{1n}x_n &=&b_1,\\
-
-&a_{21}x_1 &{}+&a_{22}x_2&+&\dots&+&a_{2n}x_n &=&b_2,\\
-
-&\vdots &&\vdots & & & & \vdots & &\vdots\\
-
-&a_{n1}x_1&{}+&a_{n2}x_2&+&\dots &+&a_{nn}x_n&=&b_n.
-
-\end{matrix}
-\]
-
-In order for this method to work all the elements of "diagonal" line:
-\[ a_{11}, a_{22}, \dots, a_{nn} \]
-Must be different from zero since We will be dividing by them.
-
-We will denote rows as '$w_i$' where 'i' is number of the row.
-
-\subsubsection{Zeroing first column}
-We start transforming the system by "zeroing" elements in first column excluding first row element. We do it by multiplying first row by $l_{i1}$, where:
-\[ l_{i1} = \frac{ a_{i1}^{(1)} }
-{ a_{11}^{(1)} } \]
-And then substracting what we got ($ l_{i1}w_1 $), from \textit{i} row.
-
-Doing so we obtain a system of linear equations:
-
-\[
-\begin{matrix}
-
-&a_{11}x_1 &{}+&a_{12}x_2&+&\dots&+&a_{1n}x_n &=&b_1,\\
-
-&0 &{}+&(a_{22} - a_{12}l_{21})x_2&{}+&\dots&{}+&(a_{2n} - a_{1n}l_{21})x_n &=&b_2 - b_{1}l_{21},\\
-
-&\vdots &&\vdots & & & & \vdots & &\vdots\\
-
-&0&{}+&(a_{n2} - a_{12}l_{n1})x_2&+&\dots &+&(a_{nn} - a_{1n}l_{n1})x_n&=&b_n - b_{1}l_{n1}.
-
-\end{matrix}
-\]
-
-\subsubsection{Zeroing second column}
-We continue onto the second column, this time we will zero all elements except first and second rows.
-Row multiplier becomes:
-\[ l_{i2} = \frac{ a_{i2}^{(2)} }{ a_{22}^{(2)} } \]
-Where:
-\[ a_{22}^{(2)} = (a_{22} - a_{12}l_{21}) \]
-And:
-\[ a_{i2}^{(2)} = (a_{i2} - a_{12}l_{i1}) \]
-\newpage
-They are modified values obtained from previous step.
-We continue as in the first step and we end up with:
-
-\[
-\begin{matrix}
-
-&a_{11}x_1 &{}+&a_{12}x_2&+&\dots&+&a_{1n}x_n &=&b_1,\\
-
-&0 &{}+& a_{22}^{(2)}x_2&{}+&\dots&{}+& a_{2n}^{(2)}x_n &=&b_2^{(2)},\\
-
-&\vdots &&\vdots & & & & \vdots & &\vdots\\
-
-&0 &{}+& 0 &{}+&\dots&{}+& a_{nn}^{(3)}x_n &=&b_2^{(3)},
-
-\end{matrix}
-\]
-
-\subsubsection{Zeroing next columns}
-We repeat this process $n-1$ times and we end up with upper triangular matrix:
-
-\[
-\begin{matrix}
-
-&a_{11}x_1 &{}+&a_{12}x_2&+&\dots&+&a_{1n}x_n &=&b_1,\\
-
-&0 &{}+& a_{22}^{(2)}x_2&{}+&\dots&{}+& a_{i2}^{(2)}x_n &=&b_2^{(2)},\\
-
-&\vdots &&\vdots & & & & \vdots & &\vdots\\
-
-&0 &{}+& 0 &{}+&\dots&{}+& a_{nn}^{(n)}x_n &=&b_2^{(n)},
-
-\end{matrix}
-\]
-
-\subsection{Backward substitution}
-After transforming the system we solve the system from last to first. \\
-First we calculate value of last element:
-\[ x_n = \frac{b_n}{a_{nn}} \]
-Then one "above":
-\[ x_{n-1} = \frac{ b_{n-1} - a_{n-1, n}x_n}{a_{n-1, n-1}} \]
-And so on, for $x_k$:
-\[ x_{k} = \frac{b_k - \sum_{j = k + 1}^n a_{kj}x_j}{a_{kk}} \]
-
-\newpage
-\subsection{Partial Pivoting}
-Gaussian elimination method has one flaw, where it can come into halt if:
-\[ a_{kk}^{(k)} = 0 \]
-To avoid it we use method of pivoting, in our case we will use partial pivoting method.
-We do it before each Gaussian elimination step since this will lead to smaller error.
-\\We first find a row $i$ such that:
-\[ |{a_{ik}^{k}}| = \underset{j}{max} \{ |{a_{kk}^{k}}|, |{a_{k+1, k}^{k}}|, \cdots, |{a_{nk}^{k}}|\} \]
-
-Then we swap this row with k-th row. Since the matrix we use is assumed to be nonsingular then $|{a_{ik}^{k}}| \neq 0$ will be always true. After that we continue with the Gaussian elimination method.
-
-Let's compare full pivoting to partial pivoting.
-Full pivoting carries more computational load. It comes from the fact that:
-In full pivoting we need to compare absolute values of the matrix elements. (Which gives us $ k^2-1$ comparisons every step as opposed to $k-1$ for partial pivoting). We also have column interchanges and corresponsing interchanges in the order of elements of \textbf{x}.
-Therefore when it comes to speed, partial pivoting is faster than full pivoting.
-
-\newpage
-\section{Results}
-\subsection{2a)}
-Solutions vectors for matrix A and vector A and n = 10 \\
-Without residual correction:
-\[ x_{algorithm} = \left(\begin{array}{cc}
--0.930024655110760 \\
--1.223407298665613 \\
--1.273530574219411 \\
--1.230517757325955 \\
--1.151356031091789 \\
--1.056883669282743 \\
--0.952628310089775 \\
--0.834334594319914 \\
--0.683708806203301 \\
--0.450125157623323
-\end{array} \right)
-\]
-With residual correction:
-\[ x_{algorithm} = \left(\begin{array}{cc}
--0.930024655110760 \\
--1.223407298665613 \\
--1.273530574219411 \\
--1.230517757325955 \\
--1.151356031091788 \\
--1.056883669282743 \\
--0.952628310089775 \\
--0.834334594319914 \\
--0.683708806203301 \\
--0.450125157623323
-\end{array} \right)
-\]
-Matlab method:
-\[
-x_{Matlab Method} = \left( = \begin{array}{cc}
--0.930024655110760 \\
--1.223407298665612 \\
--1.273530574219411 \\
--1.230517757325956 \\
--1.151356031091789 \\
--1.056883669282743 \\
--0.952628310089775 \\
--0.834334594319914 \\
--0.683708806203301 \\
--0.450125157623323
-\end{array} \right)
-\]
-Error for 'A' system of equations for algorithm before residual correction: \[ 1.986027322597818e-15 \]
-Error for 'A' system of equations for algorithm after residual correction: \[ 1.986027322597818e-15 \]
-Error for 'A' system of equations for matlab method: \[ 3.383918772654241 \]
-\newpage
-\subsection{2b)}
-Solutions vectors for matrix B and vector B and n = 10
-Without residual correction:
-\[ x_{algorithm} = 10^{14} * \left(\begin{array}{cc}
--0.000050600471710 \\
- 0.001764889142984 \\
--0.022358533990003 \\
- 0.142964542843099 \\
--0.526425616773059 \\
- 1.184552423606169 \\
--1.655429692441864 \\
- 1.402099618098568 \\
--0.659000958954395 \\
- 0.131884594651908 \\
-\end{array} \right)
-\]
-With residual correction:
-\[ x_{algorithm} = 10^{14} * \left(\begin{array}{cc}
--0.000050600463347 \\
- 0.001764888849422 \\
--0.022358530253741 \\
- 0.142964518868662 \\
--0.526425528251739 \\
- 1.184552223980917 \\
--1.655429412965713 \\
- 1.402099381042299 \\
--0.659000847398248 \\
- 0.131884572303072 \\
-\end{array} \right)
-\]
-Matlab method:
-\[
-x_{Matlab Method} = 10^{14} * \left( = \begin{array}{cc}
--0.000050613652388 \\
-0.001765340333555 \\
--0.022364164880105 \\
-0.143000107689097 \\
--0.526555232536911 \\
-1.184841538613606 \\
--1.655830695338199 \\
-1.402437027506887 \\
--0.659158629093553 \\
-0.131915987214953 \\
-\end{array} \right)
-\]
-Error for 'B' system of equations for algorithm before residual correction: \[ 3.775702543583306e-04 \]
-Error for 'B' system of equations for algorithm after residual correction: \[ 7.395459186003887e-04 \]
-Error for 'B' system of equations for matlab method: \[ 2.611906929269057e-04 \]
-
-\newpage
-\section{Discussion of results}
-\hyperlink{function2_plot}{Code for generating plots}\\
-As we can see error for 'B' system of equations increased after our residual correction. But that's just one matrix and vector pair, after testing more pairs we get following graphs (Tested on systems of equations from a) and b) respectively, with maximum size of matrices and vectors equal to 100):
-\begin{center}
- \includegraphics[scale=0.5]{errorsA.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.5]{errorsB.eps}
-\end{center}
-As we can see our residual correction method \textbf{does} work for Matrix B and Vector B and decreases the error drastically.
-
-\subsection{Errors in b)}
-Matrix B suffers from relatively huge errors. Where do they come from?
-Matrix B is a variant of Hilbert matrix.
-Equation for generating elements of this matrix is as follows:
-\[ b_{ij} = \frac{5}{8(i + j + 1)} \]
-Equation for generating elements of the Hilbert matrix is as follows:
-\[ b_{ij} = \frac{1}{(i + j - 1)} \]
-The only thing that changes are the constants, we have 5 instead of 1 in the numerator and 8 in front of the summation in the denominator and +1 instead of -1. For sufficiently huge 'i' and 'j' those differences hardly matter.
-Hilbert matrix is badly conditioned. It's condtion number for \textit{n} size hilbert matrix is equal to:
-\[ \mathcal{O}(\frac{e^{3.5255n}}{sqrt(n)}) \]
-Let's calculate condition number of matrix B in matlab:
-\begin{simplechar}
-\begin{lstlisting}
-cond(matrixB(10))
-ans = 2.428027097978043e+14
-\end{lstlisting}
-\end{simplechar}
-
-And compare it with condition number of matrix A:
-\begin{simplechar}
-\begin{lstlisting}
-cond(matrixA(10))
-ans = 4.550344127923193
-\end{lstlisting}
-\end{simplechar}
-As we can see the difference is huge, conditon number of matrix B for 10 elements is $10^{14}$ times bigger than for matrix A. This explains big errors for matrix B.
-
-
-
-
-
-
-
-
-
-
-
-\addtocontents{toc}{\protect\newpage}
-\chapter{Problem 3 - Solving a system of n linear equations - iterative algorithm}
-
-\section{Problem}
-Write a general program for solving the system of n linear equations Ax = b using the Gauss-Seidel \textbf{and} Jacobi iterative algorithms.
-
-We are given following system:
-\[
-\systeme{10x_1-4x_2+x_3+2x_4=-8, 2x_1-6x_2+3x_3-x_4=-12, x_1+4x_2-12x_3+x_4=4, 2x_1+3x_2-3x_3-10x_4=1}
-\]
-
-Then we need to compare the results of iterations plotting norm of the solution error versus the iteration number \textbf{k}, untill we get accuracy better than $10^{-10}$.
-
-We should also try to solve the equations from problem 2a) and 2b) for n = 10 using iterative method of our choice.
-
-
-\section{Theoretical introduction}
-
-Itertaive methods differ from the Gauss elimination method since they will improve with each iteration and we don't have the guarantee of how many iterations will be neeeded before we reach the solution. Increasing iterations, decreases error of solution.
-
-In general:
-We start with:
- \textbf{$x^{(0)}$ } - being the best known approximation of the solution point
-
-And we generate next vectors \textbf{$x^{i+1}$} in such way:
-\[ \mathbf{x^{i+1}} = \mathbf{M}\mathbf{x^{(i)}} + \mathbf{w} \]
-
-Where $\mathbf{M}$ is some matrix.
-
-\subsection{Procedure}
-
-\subsubsection{Decomposing matrix}
-For both Jacobi and Gauss-Seidel method we first decompose starting matrix $ \mathbf{A} $ to:
-\[ \mathbf{A} = \mathbf{L} + \mathbf{D} + \mathbf{U} \]
-where:
-$ \mathbf{L} $ - Subdiagonal matrix
-$ \mathbf{D} $ - Diagonal matrix
-$ \mathbf{U} $ - Matrix with entries over the diagonal.
-
-For example:
-For:
-\[ \mathbf{A} = \begin{bmatrix}
-2 & 3 & 3\\
-1 & 2 & 3\\
-1 & 1 & 2
-\end{bmatrix}
-\]
-
-We can get:
-\[ \mathbf{L} = \begin{bmatrix}
-0 & 0 & 0\\
-1 & 0 & 0\\
-1 & 1 & 0
-\end{bmatrix}
-\]
-\[ \mathbf{D} = \begin{bmatrix}
-2 & 0 & 0\\
-0 & 2 & 0\\
-0 & 0 & 2
-\end{bmatrix}
-\]
-\[ \mathbf{U} = \begin{bmatrix}
-0 & 3 & 3\\
-0 & 0 & 3\\
-0 & 0 & 0
-\end{bmatrix}
-\]
-
-so:
-
-\[ \mathbf{A} = \mathbf{L} + \mathbf{D} + \mathbf{U} \]
-
-\[
-\begin{bmatrix}
-2 & 3 & 3\\
-1 & 2 & 3\\
-1 & 1 & 2
-\end{bmatrix}
-=
-\begin{bmatrix}
-0 & 0 & 0\\
-1 & 0 & 0\\
-1 & 1 & 0
-\end{bmatrix}
-+
-\begin{bmatrix}
-2 & 0 & 0\\
-0 & 2 & 0\\
-0 & 0 & 2
-\end{bmatrix}
-+
-\begin{bmatrix}
-0 & 3 & 3\\
-0 & 0 & 3\\
-0 & 0 & 0
-\end{bmatrix}
-\]
-
-\subsubsection{Jacobi's method}
-After decomposing matrix we can write the system of equations
-\[ \mathbf{A}\mathbf{x} = \mathbf{b} \]
-in the form:
-\[ \mathbf{D}\mathbf{x} = -(\mathbf{L}+\mathbf{U})\mathbf{x}+\mathbf{b}
-\]
-
-If we assume that diagonal entries of matrix \textbf{A} are nonzero, then matrix \textbf{D} is nonsingular therefore we can propose such an iterative method:
-\[ \mathbf{x}^{i+1} = -\mathbf{D}^{-1}(\mathbf{L}+\mathbf{U})\mathbf{x}^{(i)}+\mathbf{D}^{-1}\mathbf{x}
-\]
-This is the Jacobi's method.
-We can rewritte this equation in the form of \textit{n} independent scalar equations:
-
-\[
-{x}_j^{i+1} = -\frac{1}{d_{jj}}(
-\sum^n_{k=1} (l_{jk} + u_{jk})x_k^{(i)}+b_j)
-) \]
-Where $d_{jj}$; $l_{jk}$; $u_{jk}$ are the elements of the respective matrixes \textbf{D}, \textbf{L}, \textbf{U}
-
-Thanks to this we can do those computations in paraller, totally or partially if we are using a computer that enables a parallelization of the computations.
-
-\paragraph{Converging}
-Jacobi's method is convergent if we have strong diagonal dominance of the matrix \textbf{A}. (More on that in discussion of results)
-
-
-\subsubsection{Gauss-Seidel method}
-After decomposing matrix we can write the system of equations
-\[ \mathbf{A}\mathbf{x} = \mathbf{b} \]
-in the form:
-\[ (\mathbf{L}+\mathbf{D})\mathbf{x} = -\mathbf{U}\mathbf{x}+\mathbf{b}
-\]
-Again, we assume that \textbf{D} is nonsingular, in doing so we propose following iterative method:
-\[ \mathbf{D}\mathbf{x}^{(i+1)} = -\mathbf{L}\mathbf{x}^{(i+1)}-\mathbf{U}\mathbf{x}^{(i)}+\mathbf{b}
-\]
-Since matrix \textbf{L} is subdiagonal, provided that we organise the calculation of elements of the vector $x^{(i_1)}$ in a proper way, it does not hurt that $x^{(i_1)}$ is on the right side of the equation.
-\newpage
-In order to organise the calculation in the correct way we:
-First take into account the structure of matrixes \textbf{D} and \textbf{L}:
-\[
-\begin{bmatrix}
-d_{11}x_1^{(i_1)}\\
-d_{22}x_2^{(i_1)}\\
-d_{33}x_3^{(i_1)}\\
-\vdots\\
-d_{nn}x_n^{(i_1)}
-\end{bmatrix}
-=
--
-\begin{bmatrix}
-0 & 0 & 0 & \cdots & 0\\
-l_{21} & 0 & 0 & \cdots & 0\\
-l_{32} & l_{32} & 0 & \cdots & 0\\
-\vdots & \vdots & \vdots & \vdots & \vdots\\
-l_{n1} & l_{n2} & l_{n3} & \cdots & 0
-\end{bmatrix}
-\begin{bmatrix}
-x_1^{(i_1)}\\
-x_2^{(i_1)}\\
-x_3^{(i_1)}\\
-\vdots\\
-x_n^{(i_1)}
-\end{bmatrix}
--
-\mathbf{w}^{(i)}
-\]
-Where
-\[ \mathbf{w}^{(i)} = \mathbf{U}\mathbf{x}^{(i)} - \mathbf{b} \]
-So the order of calculations is as follows:
-\[ x_1^{(i+1)} = -\frac{w_1^{(i)}}{d_{11}} \]
-\[ x_2^{(i+1)} = -\frac{-l_{21}x_1^{(i+1)} - w_2^{(i)}}{d_{22}} \]
-\[ x_3^{(i+1)} = -\frac{-l_{31}x_1^{(i+1)} -l_{32}x_2^{(i+1)} - w_3^{(i)}}{d_{33}} \]
-
-And so on
-
-As opposed to Jacobi's method, Gauss-Seidel method computations must be performed sequentially. Every subsequent scalar equations uses results from the computation of the previous equations.
-\paragraph{Converging}
-Gauss-Seidel method is convergent if the matrix \textbf{A} is strongly row or column diagonnaly dominant. If the matrix is symmetric, the method is also convergent if the matrix \textbf{A} is positive definite. This method is also usually faster convergent compared to Jacobi's method.
-
-\newpage
-\subsubsection{Stop tests}
-There are two ways to check when to terminate iterations of the methods we just discussed:
-\begin{enumerate}
-\item Check differences between two subsequent iteration points
-\[
-\| \mathbf{x}^{(i+1)} - \mathbf{x}^{(i)} \| \leq \delta
-\]
-Where $\delta$ is an assumed tolerance, (in our case $10^{-10}$). What we are really interested in though is whether the solution of the system of equation has required accuracy. If we want to check that we can additionaly check (higher level, more computationally demanding test):
-\item Check differences between two subsequent iteration points
-\[
-\| \mathbf{A}\mathbf{x}^{(i+1)} - \mathbf{b}\| \leq \delta_2
-\]
-Where $\delta_2$ is an assumed tolerance. If this test is not passed then we can diminish the value of $\delta_2$ and continue with the iterations. Value of $\delta_2$ can not be too small since we are limited by the numerical errors.
-\end{enumerate}
-
-\newpage
-\subsubsection{\textbf{A} and \textbf{b}}
-We have been given the following system:
-\[
-\systeme{10x_1-4x_2+x_3+2x_4=-8, 2x_1-6x_2+3x_3-x_4=-12, x_1+4x_2-12x_3+x_4=4, 2x_1+3x_2-3x_3-10x_4=1}
-\]
-Therefore our matrices will look like this:
-\[
-\textbf{A} = \begin{bmatrix}
-10 & -4 & 1 & 2 \\
-2 & -6 & 3 & -1 \\
-1 & 4 & -12 & 1 \\
-2 & 3 & -3 & -10
-\end{bmatrix}
-\textbf{b} = \begin{bmatrix}
--8 \\
--12 \\
-4 \\
-11 \\
-\end{bmatrix}
-\]
-
-So:
-\[
-\textbf{L} = \begin{bmatrix}
-0 & 0 & 0 & 0 \\
-2 & 0 & 0 & 0 \\
-1 & 4 & 0 & 0 \\
-2 & 3 & -3 & 0
-\end{bmatrix}
-\textbf{D} = \begin{bmatrix}
-10 & 0 & 0 & 0 \\
-0 & -6 & 0 & 0 \\
-0 & 0 & -12 & 0 \\
-0 & 0 & 0 & -10
-\end{bmatrix}
-\textbf{U} = \begin{bmatrix}
-0 & -4 & 1 & 2 \\
-0 & 0 & 3 & -1 \\
-0 & 0 & 0 & 1 \\
-0 & 0 & 0 & 0
-\end{bmatrix}
-\]
-\[
-\textbf{D}^{-1} = \begin{bmatrix}
-\frac{1}{10} & 0 & 0 & 0 \\
-0 & - \frac{1}{6} & 0 & 0 \\
-0 & 0 & - \frac{1}{12} & 0 \\
-0 & 0 & 0 & - \frac{1}{10}
-\end{bmatrix}
-\]
-
-\newpage
-\section{Results}
-\subsection{Jacobi method result}
-For system of equations we got in this task we got following results:
-\\
-Without the change in demanded tolerance:
-\[ x = \left( \begin{array}{cc}
- -0.076776098668341 \\
- 2.105784262642568 \\
- 0.395344797635474 \\
- 0.397776619764909
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 1.154375287358407e-10 \]
-We managed to do this in \textbf{38} iterations of our loop, and the demanded tolerance did not change. (This required small change in code where I ommited the part of code responsible for changing demandedTolerance if $ \| \mathbf{A}x-b \| > \delta_2) $ )
-
-With the change in demanded tolerance:
-\[ x = \left( \begin{array}{cc}
- -0.076776098668341 \\
- 2.105784262642568 \\
- 0.395344797635474 \\
- 0.397776619764909
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 5.770361548895147e-11 \]
-We got this result in \textbf{37} iterations and demanded tolerance was equal to $2*10^{-10}$
-
-Compared to matlab function
-\[ x_{matlab} = \left( \begin{array}{cc}
- -0.076776098662498 \\
- 2.105784262636790 \\
- 0.395344797637659 \\
- 0.397776619767240 \\
-\end{array} \right)
-\]
-Matlab error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 4.070144838902081e-15 \]
-
-\newpage
-For data from task 2a we got: \\
-Without change in demanded tolerance:
-\[ x_a = \left( \begin{array}{cc}
--0.930024655108186 \\
--1.223407298660663 \\
--1.273530574212508 \\
--1.230517757317628 \\
--1.151356031082747 \\
--1.056883669273682 \\
--0.952628310081466 \\
--0.834334594312996 \\
--0.683708806198363 \\
--0.450125157620744 \\
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 6.955194519943778e-11 \]
-We managed to do this in \textbf{59} iterations of our loop, and the demanded tolerance did not change.
-
-With change in demanded tolerance:
-\[ x_a = \left( \begin{array}{cc}
--0.930024655104470 \\
--1.223407298653515 \\
--1.273530574202540 \\
--1.230517757305602 \\
--1.151356031069692 \\
--1.056883669260597 \\
--0.952628310069469 \\
--0.834334594303006 \\
--0.683708806191233 \\
--0.450125157617020 \\
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 1.699812218689508e-10 \]
-We managed to do this in \textbf{57} iterations of our loop, and the demanded tolerance changed to $4*10^{-10}$
-
-Compared to matlab function
-\[ x_{matlab} = \left( \begin{array}{cc}
- -0.930024655110760 \\
- -1.223407298665612 \\
- -1.273530574219411 \\
- -1.230517757325956 \\
- -1.151356031091789 \\
- -1.056883669282743 \\
- -0.952628310089775 \\
- -0.834334594319914 \\
- -0.683708806203301 \\
- -0.450125157623323 \\
-\end{array} \right)
-\]
-Matlab error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 3.662053438817790e-15 \]
-
-For Matrix and Vector from task 2b) error of
-\[ \| x^{(i+1)} - x^{(i)} \| \]
-grew to infinity, therefore we could never achieve demanded tolerance, therefore the program executed infinite loop.
-
-\subsubsection{Minimizing the demanded error}
-I tried to minimize the demanded error using this steps:
-\begin{enumerate}
-\item I copied error from matlab function and pasted it into demanded tolerance.
-\item If I did not get infinite loop I copied the newly acquired error and pasted it into demanded tolerance.
-\item If I got inifinite loop I used the previous error as "minimal" demanded error.
-\end{enumerate}
-\newpage
-\paragraph{For original system of equations:}
-We managed to get results with error as low as $1.776356839400250e-15$ with demanded tolerance = $3.202372833989376e-15$ for lower values program went into infinite loop.
-Results for demanded tolerance = $3.202372833989376e-15$
-For given matrix:
-\[ x = \left( \begin{array}{cc}
- -0.076776098662498 \\
- 2.105784262636790 \\
- 0.395344797637659 \\
- 0.397776619767240
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 3.108624468950438e-15 \]
-We got this result in \textbf{53} iterations and demanded tolerance did not change.
-
-\newpage
-\paragraph{For task 2a) system of equations:}
-We managed to get results with error as low as
-\[ 3.108624468950438e-15 \] with demanded tolerance:
-\[ 3.202372833989376e-15 \]
-for lower values program went into infinite loop.
-
-For demanded tolerance = $3.202372833989376e-15$:
-Results for 2a) system of equation
-
-\[ x_a = \left( \begin{array}{cc}
--0.930024655110760 \\
--1.223407298665613 \\
--1.273530574219411 \\
--1.230517757325955 \\
--1.151356031091788 \\
--1.056883669282743 \\
--0.952628310089775 \\
--0.834334594319914 \\
--0.683708806203301 \\
--0.450125157623323
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 3.108624468950438e-15 \]
-We managed to do this in \textbf{84} iterations of our loop, and the demanded tolerance did not change.
-We managed to achieve slightly better (as in, the error was smaller) results than Matlab custom function.
-
-\newpage
-\subsection{Gauss-Seidel method result}
-For system of equations we got in this task we got following results:
-\\
-\[ x = \left( \begin{array}{cc}
- -0.076776098752996 \\
- 2.105784262542701 \\
- 0.395344797589652 \\
- 0.397776619735316
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 6.999102842719934e-10 \]
-We managed to do this in \textbf{19} iterations of our loop, and the demanded tolerance did not change.
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 6.999102842719934e-10 \]
-We got this result in \textbf{19} iterations and demanded tolerance was equal to $2*10^{-10}$
-
-For data from task 2a we got: \\
-\[ x_a = \left( \begin{array}{cc}
--0.930024655049330 \\
--1.223407298590161 \\
--1.273530574151901 \\
--1.230517757273947 \\
--1.151356031055568 \\
--1.056883669259564 \\
--0.952628310076145 \\
--0.834334594312669 \\
--0.683708806199986 \\
--0.450125157622217 \\
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 5.311669113699570e-10 \]
-We managed to do this in \textbf{28} iterations of our loop, and the demanded tolerance did not change.
-
-For Matrix and Vector from task 2b) error of
-\[ \| x^{(i+1)} - x^{(i)} \| \]
-grew to infinity, therefore we could never achieve demanded tolerance, therefore the program executed infinite loop.
-
-\subsubsection{Minimizing the demanded error}
-I tried to minimize the demanded error using procedure from before
-\paragraph{For original system of equations:}
-We managed to get results with error as low as $1.776356839400250e-15$ with demanded tolerance = $ 1.986027322597818e-15 $ for lower values program went into infinite loop.
-Results for demanded tolerance = $1.986027322597818e-15$
-For given matrix:
-\[ x = \left( \begin{array}{cc}
- -0.076776098662498 \\
- 2.105784262636790 \\
- 0.395344797637659 \\
- 0.397776619767240
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 1.776356839400250e-15 \]
-We got this result in \textbf{30} iterations and demanded tolerance did not change.
-
-\newpage
-\paragraph{For task 2a) system of equations:}
-We managed to get results with error as low as
-\[ 1.538370149106851e-15 \] with demanded tolerance:
-\[ 1.538370149106851e-15 \]
-for lower values program went into infinite loop.
-
-For demanded tolerance = $1.538370149106851e-15$:
-Results for 2a) system of equation
-
-\[ x_a = \left( \begin{array}{cc}
--0.930024655110760 \\
--1.223407298665613 \\
--1.273530574219411 \\
--1.230517757325955 \\
--1.151356031091788 \\
--1.056883669282743 \\
--0.952628310089775 \\
--0.834334594319914 \\
--0.683708806203301 \\
--0.450125157623323 \\
-\end{array} \right)
-\]
-Error:
-\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 1.538370149106851e-15 \]
-We managed to do this in \textbf{42} iterations of our loop, and the demanded tolerance did not change.
-We managed to achieve slightly better (as in, the error was smaller) results than Matlab custom function.
-
-
-\newpage
-\section{Discussion of results}
-\paragraph{Table}
-
-\begin{center}
-\resizebox{\textwidth}{!}{
-\begin{tabular}{||c c c c c c||}
- \hline
- system of equations & method & demanded tolerance & error & iterations \\
- \hline
- task 3 system & Jacobi method & 10e-10 & 1.154375287358407e-10 & 38 \\
- \hline
- task 3 system & Jacobi method & 10e-10 & 5.770361548895147e-11 & 37 \\
- \hline
- task 3 system & Jacobi method & 3.202372833989376e-15 & 3.108624468950438e-15 & 53 \\
- \hline
- task 3 system & Gaussian-Seidel method & 10e-10 & 6.999102842719934e-10 & 19 \\
- \hline
- task 3 system & Gaussian-Seidel method & 1.776356839400250e-15 & 1.776356839400250e-15 & 30 \\
- \hline
- task 3 system & Matlab function & ? & 4.070144838902081e-15 & ? \\
- \hline
- task 2a) system & Jacobi method & 10e-10 & 6.955194519943778e-11 & 59 \\
- \hline
- task 2a) system & Jacobi method & 10e-10 & 1.699812218689508e-10 & 57 \\
- \hline
- task 2a) system & Jacob method & 3.202372833989376e-15 & 3.108624468950438e-15 & 84 \\
- \hline
- task 2a) system & Gaussian-Seidel method & 10e-10 & 5.311669113699570e-10 & 28 \\
- \hline
- task 2a) system & Gaussian-Seidel method & 1.538370149106851e-15 & 1.538370149106851e-15 & 42 \\
- \hline
- task 2a) system & Matlab function & ? & 3.662053438817790e-15 & ? \\
- \hline
-
-\end{tabular}}
-\end{center}
-\subsection{Comparison based on table}
-Gaussian-Seidel method takes less iterations, can achieve smaller error and works under smaller demanded tolerance, that being said Jacobi method has one crucial advantage - it can be run in parallel. That means that even when Jacobi method takes twice or thrice amount of iteration us Gaussian-Seidel one if we just run it in paraller we can diminish this difference. In the examples we worked in, just two jacobi method running in paraller provide us with similar amount of iterations per one process as in Gaussian-Seidel one, and three or more processes give the edge to Jacobi method. With modern CPU's with at least 5 cores and correct implementation of algorithm, jacobi method reigns supreme.
-
-\newpage
-\subsection{Convergence}
-The biggest problem is of course the fact that those iterative methods do not work on every system of equation. Like the one from task 2b).
-For Jacobi's method the matrix is convergent if it has strong diagonal dominance. \textbf{A}, i.e:
-\begin{enumerate}
- \item \[ \| a_{ii} \| > \sum^n_{j=1, j \neq i} \|a_{ij} \| \]
- \item \[ \| a_{jj} \| > \sum^n_{i=1, i \neq j} \|a_{ij} \| \]
-\end{enumerate}
-For Gaussian-Seidel method the matrix is convergent if it has strong diagonal dominance \textbf{or} if the matrix \textbf{A} is symmetric and positivie definite.
-\subsubsection{2b) task convergence }
-Let's check strong diagonal dominance from matrix \textbf{A} from task 2b) in matlab:
-\begin{simplechar}
-
-\hyperlink{function_3_dominant}{Code for checking if matrix is diagonally dominant}
-\\
-
-checkIfDiagonallyDominant(matrixB(10)) returns '0', therefore matrix from task 2b) will \textbf{not} converge. And as expected it does not work when put in my jacobiLoop function.
-\subsubsection{Iterations as function of size of Matrix}
-\hyperlink{function_3_plot}{Code for creating plot}
-I have used matrix from task 2a), demanded tolerance equal to 10e-10, and max size of matrix equal to 500. for both methods
-\begin{center}
- \includegraphics[scale=0.75]{iterations.eps}
-\end{center}
-Gauss Seidel method again requires fewer iterations, around half the amount for Jacobi method. For both methods function of number of iterations acts like logarithmic function. Therefore we can assume that for big matrices required number of iterations will \textbf{not} change rapidly.
-
-\chapter{Problem 4 - QR method of finding eigenvalues}
-
-\section{Problem}
-We must find eigenvalues of 5x5 matrices. Both without shifts and with shifts.
-\section{Theoretical introduction}
-\subsection{Eigenvalues}
-Eigenvalues of matrix \textbf{A} are defined as a pair of number $\lambda$ and vector \textbf{v} such that:
-\[ \mathbf{A}\mathbf{v} = \lambda\mathbf{v} \]
-This can be rewritten as:
-\[ (\mathbf{A} - \lambda\mathbf{I})\mathbf{v} = 0 \]
-And further we get characteristic equation:
-\[ det(\mathbf{A} - \lambda\mathbf{I}) = 0 \]
-
-\newpage
-\subsection{QR method for finding eigenvalues}
-First we start by transforming matrix \textbf{A} into tridiagonal form. It increases the effectiveness of calculations.
-
-Single step of QR method consists of:
-\[ \textbf{A}^{(k)} = \textbf{Q}^{(k)}\textbf{R}^{(k)} \]
-\[ \textbf{A}^{(k+1)} = \textbf{R}^{(k)}\textbf{Q}^{(k)} \]
-$\textbf{Q}^{(k)}$ being orthogonal, therefore:
-\[ \textbf{R}^{(k)} = (\textbf{Q}^{(k)}))^{-1}\textbf{A}^{(k)} = \textbf{Q}^{(k)T}\textbf{A}^{(k)}\textbf{Q}^{(k)} \]
-therefore:
-\[ \textbf{A}^{(k+1)} = \textbf{Q}^{(k)T}\textbf{A}^{(k)}\textbf{Q}^{(k)} \]
-If we have symmetric matrix \textbf{A} it converges to the diagonal matrix $diag(\lambda_i)$
-
-Since this method can be slowly convergent we use shifts. Single iteration of QR method with shifts looks like this:
-\begin{equation}
-\begin{split}
-\textbf{A}^{(k)} - p_k\textbf{I} &= \textbf{Q}^{(k)}\textbf{R}^{(k)} \\
-\textbf{A}^{(k+1)} &= \textbf{R}^{(k)}\textbf{Q}^{(k)} + p_k\textbf{I} \\
-&= \textbf{Q}^{(k)T}(\textbf{A}^{(k)} - p_k\textbf{I})\textbf{Q}^{(k)} + p_k\textbf{I} \\
-&=\textbf{Q}^{(k)T}\textbf{A}^{(k)}\textbf{Q}^{(k)} \\
-\end{split}
-\end{equation}
-
-Wher $p_k$ should be chosen as a best estimate of $\lambda_{i+1}$
-
-\newpage
-\section{Results}
-\subsection{Starting matrix}
-I decided to generate random symmetric matrix using following code:
-\hyperlink{function4_matrix_generation}{code for matrix generation.}
-I got the following matrix:
-\[
-\begin{bmatrix}
-171 & 48 & 133 & 81 & 93 \\
- 48 & 108 & 63 & 35 & 30 \\
-133 & 63 & 131 & 64 & 91 \\
- 81 & 35 & 64 & 41 & 37 \\
- 93 & 30 & 91 & 37 & 106
-\end{bmatrix}
-\]
-
-Putting it through Matlab eig function I got eigen values equal to:
-\[
-10^{2} *
-\begin{bmatrix}
- 0.000050598692964 \\
- 0.105696602175690 \\
- 0.454589544003707 \\
- 0.870708987227002 \\
- 4.138954267900641
-\end{bmatrix}
-\]
-
-\newpage
-\subsection{QR method with no shifts}
-Putting this matrix to my functions QRNoShifts and QRShifts I got:
-for qr method with no shifts:
-Final matrix:
-\[
-\begin{bmatrix}
-413.8954 & 0.0000 & -0.0000 & 0.0000 & 0.0000 \\
- 0.0000 & 87.0709 & -0.0000 & -0.0000 & 0.0000 \\
-0.0000 & -0.0000 & 45.4590 & -0.0000 & -0.0000 \\
- -0.0000 & 0.0000 & -0.0000 & 10.5697 & -0.0000 \\
- 0.0000 & -0.0000 & 0.0000 & 0 & 0.0051
-\end{bmatrix}
-\]
-
-Eigen values:
-\[
-10^{2} *
-\begin{bmatrix}
- 4.138954267900639 \\
- 0.870708987227001 \\
- 0.454589544003706 \\
- 0.105696602175689 \\
- 0.000050598692964 \\
-\end{bmatrix}
-\]
-
-It took \textbf{26} iterations to get those values.
-
-\subsection{QR method with shifts}
-For qr method with shiftts:
-Final matrix:
-\[
-\begin{bmatrix}
-413.8954
-\end{bmatrix}
-\]
-
-Eigen values:
-\[
-10^{2} *
-\begin{bmatrix}
- 0.454589544003706 \\
- 0.870708987227001 \\
- 0.105696602175689 \\
- 0.000050598692964 \\
- 4.138954267900639
-\end{bmatrix}
-\]
-
-It took \textbf{12} iterations to get those values.
-
-\newpage
-\section{Discussion of the result}
-Following plot was generated using \hyperlink{function4}{task4Plot} function, using maxMatrixSize = 25 and generating random symmetrical matrix of size i x i in each loop. Both QR methods were given exactly the same matrices.
-\subsection{Plot}
-
-\begin{center}
- \includegraphics[scale=0.5]{task4plot.eps}
-\end{center}
-\newpage
-\subsection{Shift method superiority}
-As we can see:
-QR method with shifts is much more efficient and reliable.
-\begin{enumerate}
-\item For big enough matrices it requires ten times less iterations compared to QR method without shifts.
-\item It is more efficient in our chosen matrix.
-\item It can work with non-symetric matrices
-\item Has no problem with generating complex eigen values.
-\end{enumerate}
- One thing that does not change much is the precision, with both algorithms outputting similar results.
-
-
-
-
-
-
-\addtocontents{toc}{\protect\newpage}
-\chapter{Code appendix}
-
-\section{Task 1 Code}
-\hypertarget{function1_macheps}{\subsection{Find macheps}}
-\begin{lstlisting}
-macheps = 1;
-while 1.0 + macheps / 2 > 1.0
- macheps = macheps/2;
-end
-\end{lstlisting}
-\newpage
-\hypertarget{function1_display}{\subsection{Display results}}
-\begin{simplechar}
-\begin{lstlisting}
-format long
-disp("Display calculated macheps:")
-disp(macheps);
-disp("Display actual eps:")
-disp(eps);
-disp("Display 2^-52")
-disp(2^-52)
-disp("Display difference between calculated macheps and actual eps:")
-disp(macheps - eps)
-disp("Display difference between 2^-52 and actual eps:")
-disp(2^-52 - eps) \
-disp("Display difference between calculated macheps and 2^-52:")
-disp(macheps - 2^-52)
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\section{Task 2 Code}
-\subsection{Main function}
-\begin{simplechar}
-\begin{lstlisting}
-function x = indicatedMethod(Matrix, Vector) % Name of the method as in the textbook
-% x stands for obtained result
- [~,Columns] = size(Matrix); % We need to know how big the matrix is in next steps
- % notice the '~', since We assume We use square matrix, We do not need
- % to have another variable for number of rows since it is the same as
- % number of columns
- checkIfMatrixIsSquareMatrix(Matrix);
- [Matrix, Vector] = gaussianEliminationWithPartialPivoting(Columns, Matrix, Vector);
- % Change matrix to upper triangular matrix
- [Matrix, Vector, x] = backSubstitutionPhase(Columns, Matrix, Vector);
- % Get the solution
- x = iterativeResidualCorrection(Matrix, x, Vector); % Improve on the solution
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{checkIfMatrixIsSquareMatrix}
-\begin{simplechar}
-\begin{lstlisting}
-function checkIfMatrixIsSquareMatrix(Matrix)
- [Rows,Columns] = size(Matrix);
- if Rows ~= Columns
- error ('Matrix is not square matrix!');
- end % end if
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{gaussianEliminationWithPartialPivoting}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, Vector] = gaussianEliminationWithPartialPivoting(Columns, Matrix, Vector)
- for j = 1 : Columns
- centralElement = max(Matrix(j:Columns,j));
- % We stay in the same row (j) but We change columns, as in the
- % textbook
- [Matrix, Vector] = partialPivoting(Matrix, Vector, j, centralElement, Columns);
- % ensures that a_kk != 0 and reduces errors
- [Matrix, Vector] = gaussianElimination(j, Columns, Matrix, Vector);
- % change matrix into upper triangular matrix
- end % end for
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{partialPivoting}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, Vector] = partialPivoting(Matrix, Vector, j, centralElement, Columns)
- for k = j : Columns
- partialPivotingSwapOneRow(Matrix, Vector, j, k, centralElement);
- end % end for
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{partialPivotingSwapOneRow}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, Vector] = partialPivotingSwapOneRow(Matrix, Vector, j, k, centralElement)
- if Matrix(k,j) == centralElement
- swapRowMatrix(Matrix, j, k); % swap jth row with kth row
- swapValueVector(Vector, j, k); % swap jth value with kth value
- end % end if
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-
-\subsection{swapRowMatrix}
-\begin{simplechar}
-\begin{lstlisting}
-function Matrix = swapRowMatrix(Matrix, j, k)
- temp = Matrix(j , :); % ' : ' denote "all elements in jth row"
- Matrix(j , :) = Matrix(k, :);
- Matrix(k, :) = temp; % temp equal to previous value of jth row
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{swapValueVector}
-\begin{simplechar}
-\begin{lstlisting}
-function Vector = swapValueVector(Vector, j, k)
- temp = Vector(j);
- Vector(j) = Vector(k);
- Vector(k) = temp; % temp equal to previous value of k element of vector
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{gaussianElimination}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, Vector] = gaussianElimination(j, Columns, Matrix, Vector)
- for i = j + 1 : Columns
- rowMultiplier = Matrix(i,j) / Matrix(j,j);
- [Matrix, Vector] = substractRows(Matrix, Vector, i, rowMultiplier, j, Columns);
- end % end for
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{substractRows}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, Vector] = substractRows(Matrix, Vector, i, rowMultiplier, j, Columns)
- Vector(i) = Vector(i) - rowMultiplier * Vector(j);
- for curentColumn = 1 : Columns
- Matrix(i,curentColumn) = Matrix(i,curentColumn) - rowMultiplier * Matrix(j, curentColumn);
- end % end for
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{backSubstitutionPhase}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, Vector, x] = backSubstitutionPhase(Columns, Matrix, Vector)
- for k = Columns : -1 : 1
- % Start at final column and move by -1 each iteration until we reach 1
- equation = 0;
- for j = k+1 : Columns
- equation = equation + Matrix(k,j) * x(j, 1);
- % even though x is a vector we still need to put '1' to ensure
- % that number of columns in the first matrix matches number of
- % rows in second matrix
- end % end for
-
- x(k, 1) = (Vector(k,1) - equation) / Matrix(k,k);
- % even though x is a vector we still need to put '1' to ensure
- % that we do not exceed array bounds
- end % end for
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{iterativeResidualCorrection}
-\begin{simplechar}
-\begin{lstlisting}
-function x = iterativeResidualCorrection(Matrix, x, Vector)
- residuum = Matrix*x - Vector; % as in the book
- newResiduum = residuum;
- x = improveSolution(x, newResiduum, residuum, Matrix, Vector);
-end % end function
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{improveSolution}
-\begin{simplechar}
-\begin{lstlisting}
-function x = iterativeResidualCorrection(A, x, b)
- r = A*x - b;
- for i = 1 : 100
- [~, ~, deltaX] = solveSystem(A, r);
- newX = x - deltaX;
- r = A*newX - b;
- x = newX;
- end
-
-end % end function
-
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\hypertarget{function2_plot}{\subsection{plotErrorsGaussian}}
-\begin{simplechar}
-\begin{lstlisting}
-function plotErrorsGaussian(maxMatrixSize)
-
- errorsA = zeros(maxMatrixSize);
- errorsB = zeros(maxMatrixSize);
- errorsAR = zeros(maxMatrixSize);
- errorsBR = zeros(maxMatrixSize);
- for i = 1 : maxMatrixSize
- [~, errorBeforeResidualCorrection, errorAfterResidualCorrection] = indicatedMethod(matrixA(i), vectorA(i));
- errorsA(i) = errorBeforeResidualCorrection;
- errorsAR(i) = errorAfterResidualCorrection;
- [~, errorBeforeResidualCorrection, errorAfterResidualCorrection] = indicatedMethod(matrixB(i), vectorB(i));
- errorsB(i) = errorBeforeResidualCorrection;
- errorsBR(i) = errorAfterResidualCorrection;
- end
- nexttile
- plot(errorsA, '.');
- title('Errors before residual correction for task 2a:');
- xlabel('Size of matrix A');
- ylabel('Errors');
- nexttile
- plot(errorsAR, '.');
- title('Errors after residual correction for task 2a:');
- xlabel('Size of matrix A');
- ylabel('Errors');
- nexttile
- plot(errorsB, '.');
- title('Errors before residual correction for task 2b:');
- xlabel('Size of matrix A');
- ylabel('Errors');
- nexttile
- plot(errorsBR, '.');
- title('Errors after residual correction for task 2b:');
- xlabel('Size of matrix A');
- ylabel('Errors');
-end
-\end{lstlisting}
-\end{simplechar}
-
-
-\section{Task 3 Code}
-\begin{simplechar}
-\begin{lstlisting}
-function [x_j, x_g] = iterative(Matrix, Vector)
- [L, D, U, initial_x, whichIterationAreWeOnJ, whichIterationAreWeOnG, demandedToleranceJ, demandedToleranceG, flag, Rows] = initializeValues(Matrix);
- [x_j, whichIterationAreWeOnJ, demandedToleranceJ] = jacobiLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOnJ, demandedToleranceJ, Vector, flag);
- [x_g, whichIterationAreWeOnG, demandedToleranceG] = gaussSeidelLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOnG, demandedToleranceG, Vector, flag, Rows);
- dispFinalResults(x_j, x_g, demandedToleranceJ, demandedToleranceG, whichIterationAreWeOnJ, whichIterationAreWeOnG, Matrix, Vector);
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{initializeValues}
-\begin{simplechar}
-\begin{lstlisting}
-function [L, D, U, initial_x, whichIterationAreWeOnJ, whichIterationAreWeOnG, demandedToleranceJ, demandedToleranceG, flag, Rows] = initializeValues(Matrix)
- [Rows, ~] = size(Matrix);
- [L, D, U] = decomposeMatrix(Matrix);
- initial_x = zeros(Rows, 1);
- whichIterationAreWeOnJ = 0;
- whichIterationAreWeOnG = 0;
- demandedToleranceJ = 10e-10; % as per task description
- demandedToleranceG = 10e-10; % as per task description
- flag = 0;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{decomposeMatrix}
-\begin{simplechar}
-\begin{lstlisting}
-function [L, D, U] = decomposeMatrix(Matrix)
- D = diag(diag(Matrix));
- U = triu(Matrix, 1); % Generates upper triangular part of matrix
- % where the second variable denotes on which diagonal of matrix should be
- % start
- L = tril(Matrix, -1); % Generates lower triangular part of matrix
- % where the second variable denotes on which diagonal of matrix should be
- % start
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{jacobiLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [x_j, whichIterationAreWeOn, demandedTolerance] = jacobiLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector, flag)
- while flag ~= 1 % flag denotes whether norm(Matrix*x_g-Vector) <= demandedTolerance
- [x_j, whichIterationAreWeOn, demandedTolerance, flag, initial_x] = jacobiInsideLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{jacobiInsideLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [x_j, whichIterationAreWeOn, demandedTolerance, flag, initial_x] = jacobiInsideLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector)
- x_j = jacobiEquation(D, L, U, initial_x, Vector);
- [flag, demandedTolerance] = checkError(x_j, initial_x, demandedTolerance, Matrix, Vector);
- [initial_x, whichIterationAreWeOn] = endOfLoop(x_j, whichIterationAreWeOn);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{jacobiEquation}
-\begin{simplechar}
-\begin{lstlisting}
-function x = jacobiEquation(D, L, U, initial_x, Vector)
- x = - D \ ( L + U ) * initial_x + D \ Vector; % As per formula
- % We will be using D \ Vector and D \ ( ) instead of inverseD since
- % this is faster according to matlab
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{gaussSeidelLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [x_g, whichIterationAreWeOn, demandedTolerance] = gaussSeidelLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector, flag, Rows)
- while flag ~= 1 % flag denotes whether norm(Matrix*x_g-Vector) <= demandedTolerance
- [x_g, whichIterationAreWeOn, demandedTolerance, flag, initial_x] = gaussiInsideLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector, Rows);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{gaussiInsideLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [x_j, whichIterationAreWeOn, demandedTolerance, flag, initial_x] = gaussiInsideLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector, Rows)
- x_j = gaussSeidelEquation(D, L, U, initial_x, Vector, Rows);
- [flag, demandedTolerance] = checkError(x_j, initial_x, demandedTolerance, Matrix, Vector);
- [initial_x, whichIterationAreWeOn] = endOfLoop(x_j, whichIterationAreWeOn);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{gaussSeidelEquation}
-\begin{simplechar}
-\begin{lstlisting}
-function x_g = gaussSeidelEquation(D, L, U, initial_x, Vector, Rows)
- W = U*initial_x - Vector;
- x_g(1, 1) = -W(1, 1) / D(1,1);
- for i = 2 : Rows
- x_g(i, 1) = calculateNominator(i, L, x_g, W) / D(i, i);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{checkError}
-\begin{simplechar}
-\begin{lstlisting}
-function [flag, demandedTolerance] = checkError(x, initial_x, demandedTolerance, Matrix, Vector)
- flag = 0;
- currentError = norm(x - initial_x);
- if currentError <= demandedTolerance
- currentError = norm(Matrix*x-Vector);
- if currentError <= demandedTolerance % if sequence as per textbook
- flag = 1;
- else
- demandedTolerance = demandedTolerance * 2; % arbitrary value
- end
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{endOfLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [initial_x, whichIterationAreWeOn, flag] = endOfLoop(x, whichIterationAreWeOn)
- initial_x = x;
- whichIterationAreWeOn = whichIterationAreWeOn + 1;
- flag = 0;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{dispFinalResults}
-\begin{simplechar}
-\begin{lstlisting}
-function dispFinalResults(x_j, x_g, demandedToleranceJ, demandedToleranceG, whichIterationAreWeOnJ, whichIterationAreWeOnG, Matrix, Vector)
- disp("Final demandedTolerance for Jacobi method");
- disp(demandedToleranceJ);
- disp("Final demandedTolerance for Gaussian-Seidel method:");
- disp(demandedToleranceG);
- disp("Final Iteration for Jacobi method: ");
- disp(whichIterationAreWeOnJ);
- disp("Final Iteration for Gaussian-Seidel method: ");
- disp(whichIterationAreWeOnG);
- disp("Error for Jacobi method:");
- disp(norm(Matrix*x_j - Vector));
- disp("Error for Gaussian-Seidel method:");
- disp(norm(Matrix*x_g - Vector));
- disp("A\b error:");
- disp(norm(Matrix * (Matrix\Vector) - Vector));
- disp("Answer for Jacobi method: ");
- disp(x_j);
- disp("Answer for Gaussian-Seidel method: ");
- disp(x_g);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\hypertarget{function_3_plot}{\subsection{plotIterations}}
-\begin{simplechar}
-\begin{lstlisting}
-function plotIterations()
- maxMatrixSize = 500;
- iterationsJ = zeros(maxMatrixSize);
- iterationsG = zeros(maxMatrixSize);
- for i = 1 : maxMatrixSize
- [~, ~, whichIterationAreWeOnJ, whichIterationAreWeOnG] = iterative(matrixA(i), vectorA(i));
- iterationsJ(i) = whichIterationAreWeOnJ;
- iterationsG(i) = whichIterationAreWeOnG;
- end
- nexttile
- plot(iterationsJ, '.');
- title('Number of iterations for different sizes of matrices for Jacobi method');
- xlabel('Size of matrix A');
- ylabel('Number of iterations');
- nexttile
- plot(iterationsG, '.');
- title('Number of iterations for different sizes of matrices for Gauss-Seidel method');
- xlabel('Size of matrix A');
- ylabel('Number of iterations');
-
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\hypertarget{function_3_dominant}{Code for checking if matrix is diagonally dominant}
-\begin{lstlisting}
-function d = checkIfDiagonallyDominant(Matrix)
- d = 1;
- [Rows, ~] = size(Matrix);
- for i = 1 : Rows
- rowsSum = 0;
- for j = 1 : Rows
- rowsSum = rowsSum + abs(Matrix(i, j));
- end
- rowsSum = rowsSum - Matrix(i, i);
- if Matrix(i, i) <= rowsSum
- d = 0;
- break
- end
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-
-\newpage
-\section{Task 4 Code}
-\subsection{Gram-Schmid algorithm}
-
-\begin{simplechar}
-\begin{lstlisting}
-% performs QR or QRdash decomposition of a matrix
-function [Q, R] = gramSchmidtAlgorithm(Matrix)
- [columns, Q, R, d] = initializeGramSchmid(Matrix);
- [Q, R] = factorizeColumnsOfQ(columns, Q, Matrix, R, d);
- [Q, R] = normalizeColumns(columns, Q, R);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{initializeGramSchmid}
-\begin{simplechar}
-\begin{lstlisting}
-function [columns, Q, R, d] = initializeGramSchmid(Matrix)
- % We start with empty matrices
- [rows, columns] = size(Matrix);
- Q = zeros(rows, columns);
- R = zeros(columns, columns);
- d = zeros(1, columns);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{factorizeColumnsOfQ}
-\begin{simplechar}
-\begin{lstlisting}
-function [Q, R] = factorizeColumnsOfQ(columns, Q, Matrix, R, d)
- for i = 1 : columns
- Q(:, i) = Matrix(:, i);
- R(i, i) = 1;
- d(i) = Q(:, i)' * Q(:, i);
- for i2 = i + 1 : columns
- R(i, i2) = (Q(:, i)' * Matrix(:, i2)) / d(i);
- Matrix(:, i2) = Matrix(:, i2) - R(i, i2) * Q(:, i);
- end
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{normalizeColumns}
-\begin{simplechar}
-\begin{lstlisting}
-function [Q, R] = normalizeColumns(columns, Q, R)
- for i = 1 : columns
- dd = norm(Q(:, i));
- Q(:, i) = Q(:, i) / dd;
- R(i, i:columns) = R(i, i : columns) * dd;
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{task4}
-\begin{simplechar}
-\begin{lstlisting}
-function [eigenValuesNoShifts, iterationsNoShifts, finalMatrixNoShifts, eigenValuesShifts, iterationsShifts, finalMatrixShifts] = task4(Matrix)
- [eigenValuesNoShifts, iterationsNoShifts, finalMatrixNoShifts] = QRNoShifts(Matrix);
- [eigenValuesShifts, iterationsShifts, finalMatrixShifts] = QRShifts(Matrix);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{QRNoShifts}
-\begin{simplechar}
-\begin{lstlisting}
-function [eigenValues, whichIterationAreWeOn, Matrix] = QRNoShifts(Matrix)
-
- [whichIterationAreWeOn, threshold, startingMatrix, matlabEigen] = initializeValues(Matrix);
- [Matrix, whichIterationAreWeOn] = QRNoShiftsLoop(threshold, Matrix, whichIterationAreWeOn);
- eigenValues = diag(Matrix)';
- displayResults(eigenValues, whichIterationAreWeOn, Matrix, startingMatrix, matlabEigen);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{QRNoShiftsLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, whichIterationAreWeOn] = QRNoShiftsLoop(threshold, Matrix, whichIterationAreWeOn)
- while threshold > 1e-6
- [Matrix, whichIterationAreWeOn, threshold] = QRNoShiftsInsideLoop(Matrix, whichIterationAreWeOn);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{QRNoShiftsInsideLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, whichIterationAreWeOn, threshold] = QRNoShiftsInsideLoop(Matrix, whichIterationAreWeOn)
- [Q, R] = gramSchmidtAlgorithm(Matrix);
- Matrix = R * Q;
- whichIterationAreWeOn = whichIterationAreWeOn + 1;
-
- % iterate until all non-diagonal elements are below the threshold
- matrixWithoutDiagonal = Matrix - diag(diag(Matrix)); % first diag converts Matrix
- % into vector consisting of values on the diagonal of matrix,
- % second diag converts this vector into matrix with zeros on
- % everything except diagonal
- % If we substract it from Matrix we get original Matrix with zeros
- % on a diagonal
- threshold = max(max(abs(matrixWithoutDiagonal)));
- % first max returns vector of elements
- % second max returns max element from this vector
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{displayResults}
-\begin{simplechar}
-\begin{lstlisting}
-function displayResults(eigenValues, whichIterationsAreWeOn, Matrix, startingMatrix, matlabEigen)
- disp("How many iterations it took:")
- disp(whichIterationsAreWeOn)
- disp("Starting Matrix:")
- disp(startingMatrix)
- disp("Final Matrix:")
- disp(Matrix)
- disp("eig(Matrix) eigen values:")
- disp(matlabEigen)
- disp("Our eigen values:")
- disp(eigenValues);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{initializeValues}
-\begin{simplechar}
-\begin{lstlisting}
-function [whichIterationAreWeOn, threshold, startingMatrix, matlabEigen] = initializeValues(Matrix)
- whichIterationAreWeOn = 0;
- threshold = inf;
- startingMatrix = Matrix;
- matlabEigen = eig(Matrix);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{QRShifts}
-\begin{simplechar}
-\begin{lstlisting}
-function [eigenValues, whatIterationAreWeOn, Matrix] = QRShifts(Matrix)
- eigenFromMatlab = eig(Matrix);
- initialMatrix = Matrix;
- [eigenValues, whatIterationAreWeOn, matrixSize, minThreshold] = initiateValues(Matrix);
- [Matrix, whatIterationAreWeOn, eigenValues] = QRShiftLoop(matrixSize, Matrix, eigenValues, minThreshold, whatIterationAreWeOn);
- dispResults(eigenValues, Matrix, whatIterationAreWeOn, eigenFromMatlab, initialMatrix);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{initiateValues}
-\begin{simplechar}
-\begin{lstlisting}
-function [eigenValues, whatIterationAreWeOn, matrixSize, minThreshold] = initiateValues(Matrix)
- eigenValues = double.empty(1, 0);
- whatIterationAreWeOn = 0;
- matrixSize = size(Matrix, 1);
- minThreshold = 1e-6;
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{QRShiftLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, whatIterationAreWeOn, eigenValues] = QRShiftLoop(matrixSize, Matrix, eigenValues, minThreshold, whatIterationAreWeOn)
- while matrixSize >= 2
- flag = 0;
- [Matrix, matrixSize, whatIterationAreWeOn, eigenValues] = findEigenValue(Matrix, matrixSize, whatIterationAreWeOn, eigenValues, minThreshold, flag);
- [matrixSize, Matrix] = deflateMatrix(Matrix, matrixSize);
- end
- eigenValues(size(eigenValues, 2) + 1) = Matrix(1, 1);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{findEigenValue}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, matrixSize, whatIterationAreWeOn, eigenValues] = findEigenValue(Matrix, matrixSize, whatIterationAreWeOn, eigenValues, minThreshold, flag)
- while flag == 0
- eigenValueCorner = getEigenValueFromCorner(Matrix, matrixSize);
- [Matrix, whatIterationAreWeOn] = shiftAndIterate(matrixSize, Matrix, eigenValueCorner, whatIterationAreWeOn);
- [flag, eigenValues] = thresholdBreached(Matrix, matrixSize, minThreshold, eigenValues);
- end
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{getEigenValueFromCorner}
-\begin{simplechar}
-\begin{lstlisting}
-function eigenValueCorner = getEigenValueFromCorner(Matrix, matrixSize)
- corner = Matrix((matrixSize - 1) : matrixSize, (matrixSize - 1) : matrixSize);
- % get 2 x 2 corner of the matrix
- eigenValueCorner = solveCharactersticEquation(corner);
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{shiftAndIterate}
-\begin{simplechar}
-\begin{lstlisting}
-function [Matrix, whatIterationAreWeOn] = shiftAndIterate(matrixSize, Matrix, eigenValueCorner, whatIterationAreWeOn)
- % shift and iterate algorithm
- identityMatrix = eye(matrixSize);
- Matrix = Matrix - identityMatrix * eigenValueCorner;
- [Q, R] = gramSchmidtAlgorithm(Matrix);
- Matrix = R * Q + identityMatrix * eigenValueCorner;
- whatIterationAreWeOn = whatIterationAreWeOn + 1;
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{deflateMatrix}
-\begin{simplechar}
-\begin{lstlisting}
-function [matrixSize, Matrix] = deflateMatrix(Matrix, matrixSize)
- matrixSize = matrixSize - 1;
- Matrix = Matrix(1:matrixSize, 1:matrixSize);
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{thresholdBreached}
-\begin{simplechar}
-\begin{lstlisting}
-function [flag, eigenValues] = thresholdBreached(Matrix, matrixSize, minThreshold, eigenValues)
- flag = 0;
- threshold = max(abs(Matrix(matrixSize, 1:(matrixSize - 1))));
-
- % once we zero the row (or rather get close enough to zero) exit loop
- if (threshold <= minThreshold)
- eigenValues(size(eigenValues, 2) + 1) = Matrix(matrixSize, matrixSize);
- flag = 1;
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{solveCharactersticEquation}
-\begin{simplechar}
-\begin{lstlisting}
-% finds the eigenvalue of a 2x2 matrix that is closer to the lower right corner
-function eigen = solveCharactersticEquation(Matrix)
- [eigenOne, eigenTwo] = calculateZeros(Matrix);
- eigen = valueCloserToLowerRightCorner(eigenOne, eigenTwo, Matrix);
-end
-
-function eigen = valueCloserToLowerRightCorner(eigenOne, eigenTwo, Matrix)
- if abs(Matrix(4) - eigenOne) < abs(Matrix(4) - eigenTwo)
- eigen = eigenOne;
- else
- eigen = eigenTwo;
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{calculateZeros}
-\begin{simplechar}
-\begin{lstlisting}
-function [zeroOne, zeroTwo] = calculateZeros(Matrix)
- b = Matrix(1) + Matrix(4);
- ac = Matrix(1) * Matrix(4) - Matrix(2) * Matrix(3);
- delta = (b) ^ 2 - 4 * ac;
- % get delta of quadratic equation
- squareRootDelta = sqrt(delta);
- % square delta
- zeroOne = (b - squareRootDelta) / 2;
- zeroTwo = (b + squareRootDelta) / 2;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{dispResults}
-\begin{simplechar}
-\begin{lstlisting}
-function dispResults(eigenValues, Matrix, whatIterationAreWeOn, eigenFromMatlab, initialMatrix)
- disp("Initial matrix: ");
- disp(initialMatrix);
- disp("Final matrix: ");
- disp(Matrix);
- disp("Number of iterations: ");
- disp(whatIterationAreWeOn);
- disp("Eigen values from eig(Matrix):");
- disp(eigenFromMatlab);
- disp("Our eigen values: ");
- disp(eigenValues);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\hypertarget{function4}{\subsection{task4Plot}}
-\begin{simplechar}
-\begin{lstlisting}
-function task4Plot(maxMatrixSize)
- iterationsNoShiftsVector = zeros(maxMatrixSize);
- iterationsShiftsVector = zeros(maxMatrixSize);
- for i = 1 : maxMatrixSize
- [~, iterationsNoShifts, ~, ~, iterationsShifts, ~] = task4(matrix4(i));
- iterationsNoShiftsVector(i) = iterationsNoShifts;
- iterationsShiftsVector(i) = iterationsShifts;
- end
- nexttile
- plot(iterationsNoShiftsVector, '.');
- title('Number of iterations for different sizes of matrices for no shift method');
- xlabel('Size of matrix A');
- ylabel('Number of iterations');
- nexttile
- plot(iterationsShiftsVector, '.');
- title('Number of iterations for different sizes of matrices for shift method');
- xlabel('Size of matrix A');
- ylabel('Number of iterations');
-end
-\end{lstlisting}
-\end{simplechar}
-
-\hypertarget{function4_matrix_generation}{\subsection{Matrix generation}}
-\begin{simplechar}
-\begin{lstlisting}
-function A = matrix4()
- A = 10 * rand(5); % rand generates 5x5 matrix filled with random numbers
- % we multiply by 10 to get at lest one digit in front of the dot
- A = floor(A); % we floor the matrix we got to get nice natural numbers matrix
- A = A * A'; % we get symmetric matrix
- disp(issymmetric(A)); % we check if matrix is symmetric
-end
-\end{lstlisting}
-\end{simplechar}
-
-
-\begin{thebibliography}{9}
-\bibitem{texbook}
-Piotr Tatjewski (2014) \emph{Numerical Methods}, Oficyna Wydawnicza Politechniki Warszawskiej
-\end{thebibliography}
-
+ \input{sections/01-problem}
+ \input{sections/02-theoretical-introduction}
+ \input{sections/03-solution}
+ \input{sections/04-results}
+ \input{sections/05-problem}
+ \input{sections/06-theoretical-introduction}
+ \input{sections/07-results}
+ \input{sections/08-discussion-of-results}
+ \input{sections/09-problem}
+ \input{sections/10-theoretical-introduction}
+ \input{sections/11-results}
+ \input{sections/12-discussion-of-results}
+ \input{sections/13-problem}
+ \input{sections/14-theoretical-introduction}
+ \input{sections/15-results}
+ \input{sections/16-discussion-of-the-result}
+ \input{sections/17-task-1-code}
+ \input{sections/18-task-2-code}
+ \input{sections/19-task-3-code}
+ \input{sections/20-task-4-code}
\end{document}
diff --git a/NotProgramming/ENUME/projectA/sections/01-problem.tex b/NotProgramming/ENUME/projectA/sections/01-problem.tex
new file mode 100644
index 00000000..4cfbe33c
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/01-problem.tex
@@ -0,0 +1,2 @@
+\section{Problem}
+Write a program finding macheps in the MATLAB environment
diff --git a/NotProgramming/ENUME/projectA/sections/02-theoretical-introduction.tex b/NotProgramming/ENUME/projectA/sections/02-theoretical-introduction.tex
new file mode 100644
index 00000000..e1d55da0
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/02-theoretical-introduction.tex
@@ -0,0 +1,13 @@
+\section{Theoretical Introduction}
+\subsection{Definition of machine epsilion}
+Machine epsilion is the maximal possible relative error of the floating-point representation. (Tatjewski, p.14)
+Machine epsilion is equal to $2^{-t}$ where t is number of bits in the mantissa.
+In our case where we use IEEE Standard 754, mantissa is 53 bits long with first bit omitted as it is always equal to '1', so we technicaly work with 52 bits mantissa which makes the machine epsilion equal to: $2^{-52} = 2.220446\mathrm{e}{-16}$
+
+\newpage
+\subsection{Practical applications of machine epsilion}
+Since macheps is connected to IEEE754 standard it is always equal to the same number, which means that we can safely compare results from different machines without worrying about their individual errors. Before standards, everyone could use any way of representing floats.
+
+Macheps is also essential when we calculate cumulation of errors of given mathematical operation.
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/03-solution.tex b/NotProgramming/ENUME/projectA/sections/03-solution.tex
new file mode 100644
index 00000000..5607ac0b
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/03-solution.tex
@@ -0,0 +1,5 @@
+\section{Solution}
+
+
+\hyperlink{function1_macheps}{Code for finding macheps} shifts macheps one bit to the right each iteration (by dividing by 2), it ends when we run out of mantissa bits which renders us unable to save smaller number. Due to underflow the value of macheps becomes 0 and therefore 1.0 > (macheps / 2) > 1.0 will become false.
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/04-results.tex b/NotProgramming/ENUME/projectA/sections/04-results.tex
new file mode 100644
index 00000000..d4fca6f2
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/04-results.tex
@@ -0,0 +1,24 @@
+\section{Results}
+\hyperlink{function1_display}{Code for displaying results}\\
+Display calculated macheps:
+ \[2.220446049250313\mathrm{e}{-16}\]
+
+Display actual eps:
+ \[2.220446049250313\mathrm{e}{-16}\]
+
+Display $2^{-52}$:
+ \[2.220446049250313\mathrm{e}{-16}\]
+
+Display difference between calculated macheps and actual eps:
+ \[0\]
+
+Display difference between $2^{-52}$ and actual eps:
+ \[0\]
+
+Display difference between calculated macheps and $2^{-52}$:
+ \[0\]
+
+As expected they are all equal to each other. It means that our method of calculating macheps was correct.
+
+\chapter{Problem 2 - Solving a system of n linear equations - indicated method}
+
diff --git a/NotProgramming/ENUME/projectA/sections/05-problem.tex b/NotProgramming/ENUME/projectA/sections/05-problem.tex
new file mode 100644
index 00000000..942aa380
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/05-problem.tex
@@ -0,0 +1,3 @@
+\section{Problem}
+Write a program solving a system of \textit{n} linear equations Ax = b using the indicated method (Gaussian elimination with partial pivoting).
+
diff --git a/NotProgramming/ENUME/projectA/sections/06-theoretical-introduction.tex b/NotProgramming/ENUME/projectA/sections/06-theoretical-introduction.tex
new file mode 100644
index 00000000..c27d9970
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/06-theoretical-introduction.tex
@@ -0,0 +1,118 @@
+\section{Theoretical Introduction}
+Gaussian elimination with partial pivoting consists of 3 main steps:
+\subsection{Transform matrix into upper-triangular matrix}
+
+\subsubsection{Starting conditions}
+We start with the system of linear equations looking like this:
+
+\[
+\begin{matrix}
+
+&a_{11}x_1 &{}+&a_{12}x_2&+&\dots&+&a_{1n}x_n &=&b_1,\\
+
+&a_{21}x_1 &{}+&a_{22}x_2&+&\dots&+&a_{2n}x_n &=&b_2,\\
+
+&\vdots &&\vdots & & & & \vdots & &\vdots\\
+
+&a_{n1}x_1&{}+&a_{n2}x_2&+&\dots &+&a_{nn}x_n&=&b_n.
+
+\end{matrix}
+\]
+
+In order for this method to work all the elements of "diagonal" line:
+\[ a_{11}, a_{22}, \dots, a_{nn} \]
+Must be different from zero since We will be dividing by them.
+
+We will denote rows as '$w_i$' where 'i' is number of the row.
+
+\subsubsection{Zeroing first column}
+We start transforming the system by "zeroing" elements in first column excluding first row element. We do it by multiplying first row by $l_{i1}$, where:
+\[ l_{i1} = \frac{ a_{i1}^{(1)} }
+{ a_{11}^{(1)} } \]
+And then substracting what we got ($ l_{i1}w_1 $), from \textit{i} row.
+
+Doing so we obtain a system of linear equations:
+
+\[
+\begin{matrix}
+
+&a_{11}x_1 &{}+&a_{12}x_2&+&\dots&+&a_{1n}x_n &=&b_1,\\
+
+&0 &{}+&(a_{22} - a_{12}l_{21})x_2&{}+&\dots&{}+&(a_{2n} - a_{1n}l_{21})x_n &=&b_2 - b_{1}l_{21},\\
+
+&\vdots &&\vdots & & & & \vdots & &\vdots\\
+
+&0&{}+&(a_{n2} - a_{12}l_{n1})x_2&+&\dots &+&(a_{nn} - a_{1n}l_{n1})x_n&=&b_n - b_{1}l_{n1}.
+
+\end{matrix}
+\]
+
+\subsubsection{Zeroing second column}
+We continue onto the second column, this time we will zero all elements except first and second rows.
+Row multiplier becomes:
+\[ l_{i2} = \frac{ a_{i2}^{(2)} }{ a_{22}^{(2)} } \]
+Where:
+\[ a_{22}^{(2)} = (a_{22} - a_{12}l_{21}) \]
+And:
+\[ a_{i2}^{(2)} = (a_{i2} - a_{12}l_{i1}) \]
+\newpage
+They are modified values obtained from previous step.
+We continue as in the first step and we end up with:
+
+\[
+\begin{matrix}
+
+&a_{11}x_1 &{}+&a_{12}x_2&+&\dots&+&a_{1n}x_n &=&b_1,\\
+
+&0 &{}+& a_{22}^{(2)}x_2&{}+&\dots&{}+& a_{2n}^{(2)}x_n &=&b_2^{(2)},\\
+
+&\vdots &&\vdots & & & & \vdots & &\vdots\\
+
+&0 &{}+& 0 &{}+&\dots&{}+& a_{nn}^{(3)}x_n &=&b_2^{(3)},
+
+\end{matrix}
+\]
+
+\subsubsection{Zeroing next columns}
+We repeat this process $n-1$ times and we end up with upper triangular matrix:
+
+\[
+\begin{matrix}
+
+&a_{11}x_1 &{}+&a_{12}x_2&+&\dots&+&a_{1n}x_n &=&b_1,\\
+
+&0 &{}+& a_{22}^{(2)}x_2&{}+&\dots&{}+& a_{i2}^{(2)}x_n &=&b_2^{(2)},\\
+
+&\vdots &&\vdots & & & & \vdots & &\vdots\\
+
+&0 &{}+& 0 &{}+&\dots&{}+& a_{nn}^{(n)}x_n &=&b_2^{(n)},
+
+\end{matrix}
+\]
+
+\subsection{Backward substitution}
+After transforming the system we solve the system from last to first. \\
+First we calculate value of last element:
+\[ x_n = \frac{b_n}{a_{nn}} \]
+Then one "above":
+\[ x_{n-1} = \frac{ b_{n-1} - a_{n-1, n}x_n}{a_{n-1, n-1}} \]
+And so on, for $x_k$:
+\[ x_{k} = \frac{b_k - \sum_{j = k + 1}^n a_{kj}x_j}{a_{kk}} \]
+
+\newpage
+\subsection{Partial Pivoting}
+Gaussian elimination method has one flaw, where it can come into halt if:
+\[ a_{kk}^{(k)} = 0 \]
+To avoid it we use method of pivoting, in our case we will use partial pivoting method.
+We do it before each Gaussian elimination step since this will lead to smaller error.
+\\We first find a row $i$ such that:
+\[ |{a_{ik}^{k}}| = \underset{j}{max} \{ |{a_{kk}^{k}}|, |{a_{k+1, k}^{k}}|, \cdots, |{a_{nk}^{k}}|\} \]
+
+Then we swap this row with k-th row. Since the matrix we use is assumed to be nonsingular then $|{a_{ik}^{k}}| \neq 0$ will be always true. After that we continue with the Gaussian elimination method.
+
+Let's compare full pivoting to partial pivoting.
+Full pivoting carries more computational load. It comes from the fact that:
+In full pivoting we need to compare absolute values of the matrix elements. (Which gives us $ k^2-1$ comparisons every step as opposed to $k-1$ for partial pivoting). We also have column interchanges and corresponsing interchanges in the order of elements of \textbf{x}.
+Therefore when it comes to speed, partial pivoting is faster than full pivoting.
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/07-results.tex b/NotProgramming/ENUME/projectA/sections/07-results.tex
new file mode 100644
index 00000000..f5e854ca
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/07-results.tex
@@ -0,0 +1,100 @@
+\section{Results}
+\subsection{2a)}
+Solutions vectors for matrix A and vector A and n = 10 \\
+Without residual correction:
+\[ x_{algorithm} = \left(\begin{array}{cc}
+-0.930024655110760 \\
+-1.223407298665613 \\
+-1.273530574219411 \\
+-1.230517757325955 \\
+-1.151356031091789 \\
+-1.056883669282743 \\
+-0.952628310089775 \\
+-0.834334594319914 \\
+-0.683708806203301 \\
+-0.450125157623323
+\end{array} \right)
+\]
+With residual correction:
+\[ x_{algorithm} = \left(\begin{array}{cc}
+-0.930024655110760 \\
+-1.223407298665613 \\
+-1.273530574219411 \\
+-1.230517757325955 \\
+-1.151356031091788 \\
+-1.056883669282743 \\
+-0.952628310089775 \\
+-0.834334594319914 \\
+-0.683708806203301 \\
+-0.450125157623323
+\end{array} \right)
+\]
+Matlab method:
+\[
+x_{Matlab Method} = \left( = \begin{array}{cc}
+-0.930024655110760 \\
+-1.223407298665612 \\
+-1.273530574219411 \\
+-1.230517757325956 \\
+-1.151356031091789 \\
+-1.056883669282743 \\
+-0.952628310089775 \\
+-0.834334594319914 \\
+-0.683708806203301 \\
+-0.450125157623323
+\end{array} \right)
+\]
+Error for 'A' system of equations for algorithm before residual correction: \[ 1.986027322597818e-15 \]
+Error for 'A' system of equations for algorithm after residual correction: \[ 1.986027322597818e-15 \]
+Error for 'A' system of equations for matlab method: \[ 3.383918772654241 \]
+\newpage
+\subsection{2b)}
+Solutions vectors for matrix B and vector B and n = 10
+Without residual correction:
+\[ x_{algorithm} = 10^{14} * \left(\begin{array}{cc}
+-0.000050600471710 \\
+ 0.001764889142984 \\
+-0.022358533990003 \\
+ 0.142964542843099 \\
+-0.526425616773059 \\
+ 1.184552423606169 \\
+-1.655429692441864 \\
+ 1.402099618098568 \\
+-0.659000958954395 \\
+ 0.131884594651908 \\
+\end{array} \right)
+\]
+With residual correction:
+\[ x_{algorithm} = 10^{14} * \left(\begin{array}{cc}
+-0.000050600463347 \\
+ 0.001764888849422 \\
+-0.022358530253741 \\
+ 0.142964518868662 \\
+-0.526425528251739 \\
+ 1.184552223980917 \\
+-1.655429412965713 \\
+ 1.402099381042299 \\
+-0.659000847398248 \\
+ 0.131884572303072 \\
+\end{array} \right)
+\]
+Matlab method:
+\[
+x_{Matlab Method} = 10^{14} * \left( = \begin{array}{cc}
+-0.000050613652388 \\
+0.001765340333555 \\
+-0.022364164880105 \\
+0.143000107689097 \\
+-0.526555232536911 \\
+1.184841538613606 \\
+-1.655830695338199 \\
+1.402437027506887 \\
+-0.659158629093553 \\
+0.131915987214953 \\
+\end{array} \right)
+\]
+Error for 'B' system of equations for algorithm before residual correction: \[ 3.775702543583306e-04 \]
+Error for 'B' system of equations for algorithm after residual correction: \[ 7.395459186003887e-04 \]
+Error for 'B' system of equations for matlab method: \[ 2.611906929269057e-04 \]
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/08-discussion-of-results.tex b/NotProgramming/ENUME/projectA/sections/08-discussion-of-results.tex
new file mode 100644
index 00000000..566be2c9
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/08-discussion-of-results.tex
@@ -0,0 +1,52 @@
+\section{Discussion of results}
+\hyperlink{function2_plot}{Code for generating plots}\\
+As we can see error for 'B' system of equations increased after our residual correction. But that's just one matrix and vector pair, after testing more pairs we get following graphs (Tested on systems of equations from a) and b) respectively, with maximum size of matrices and vectors equal to 100):
+\begin{center}
+ \includegraphics[scale=0.5]{errorsA.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.5]{errorsB.eps}
+\end{center}
+As we can see our residual correction method \textbf{does} work for Matrix B and Vector B and decreases the error drastically.
+
+\subsection{Errors in b)}
+Matrix B suffers from relatively huge errors. Where do they come from?
+Matrix B is a variant of Hilbert matrix.
+Equation for generating elements of this matrix is as follows:
+\[ b_{ij} = \frac{5}{8(i + j + 1)} \]
+Equation for generating elements of the Hilbert matrix is as follows:
+\[ b_{ij} = \frac{1}{(i + j - 1)} \]
+The only thing that changes are the constants, we have 5 instead of 1 in the numerator and 8 in front of the summation in the denominator and +1 instead of -1. For sufficiently huge 'i' and 'j' those differences hardly matter.
+Hilbert matrix is badly conditioned. It's condtion number for \textit{n} size hilbert matrix is equal to:
+\[ \mathcal{O}(\frac{e^{3.5255n}}{sqrt(n)}) \]
+Let's calculate condition number of matrix B in matlab:
+\begin{simplechar}
+\begin{lstlisting}
+cond(matrixB(10))
+ans = 2.428027097978043e+14
+\end{lstlisting}
+\end{simplechar}
+
+And compare it with condition number of matrix A:
+\begin{simplechar}
+\begin{lstlisting}
+cond(matrixA(10))
+ans = 4.550344127923193
+\end{lstlisting}
+\end{simplechar}
+As we can see the difference is huge, conditon number of matrix B for 10 elements is $10^{14}$ times bigger than for matrix A. This explains big errors for matrix B.
+
+
+
+
+
+
+
+
+
+
+
+\addtocontents{toc}{\protect\newpage}
+\chapter{Problem 3 - Solving a system of n linear equations - iterative algorithm}
+
diff --git a/NotProgramming/ENUME/projectA/sections/09-problem.tex b/NotProgramming/ENUME/projectA/sections/09-problem.tex
new file mode 100644
index 00000000..f1a5fada
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/09-problem.tex
@@ -0,0 +1,13 @@
+\section{Problem}
+Write a general program for solving the system of n linear equations Ax = b using the Gauss-Seidel \textbf{and} Jacobi iterative algorithms.
+
+We are given following system:
+\[
+\systeme{10x_1-4x_2+x_3+2x_4=-8, 2x_1-6x_2+3x_3-x_4=-12, x_1+4x_2-12x_3+x_4=4, 2x_1+3x_2-3x_3-10x_4=1}
+\]
+
+Then we need to compare the results of iterations plotting norm of the solution error versus the iteration number \textbf{k}, untill we get accuracy better than $10^{-10}$.
+
+We should also try to solve the equations from problem 2a) and 2b) for n = 10 using iterative method of our choice.
+
+
diff --git a/NotProgramming/ENUME/projectA/sections/10-theoretical-introduction.tex b/NotProgramming/ENUME/projectA/sections/10-theoretical-introduction.tex
new file mode 100644
index 00000000..762d1e61
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/10-theoretical-introduction.tex
@@ -0,0 +1,229 @@
+\section{Theoretical introduction}
+
+Itertaive methods differ from the Gauss elimination method since they will improve with each iteration and we don't have the guarantee of how many iterations will be neeeded before we reach the solution. Increasing iterations, decreases error of solution.
+
+In general:
+We start with:
+ \textbf{$x^{(0)}$ } - being the best known approximation of the solution point
+
+And we generate next vectors \textbf{$x^{i+1}$} in such way:
+\[ \mathbf{x^{i+1}} = \mathbf{M}\mathbf{x^{(i)}} + \mathbf{w} \]
+
+Where $\mathbf{M}$ is some matrix.
+
+\subsection{Procedure}
+
+\subsubsection{Decomposing matrix}
+For both Jacobi and Gauss-Seidel method we first decompose starting matrix $ \mathbf{A} $ to:
+\[ \mathbf{A} = \mathbf{L} + \mathbf{D} + \mathbf{U} \]
+where:
+$ \mathbf{L} $ - Subdiagonal matrix
+$ \mathbf{D} $ - Diagonal matrix
+$ \mathbf{U} $ - Matrix with entries over the diagonal.
+
+For example:
+For:
+\[ \mathbf{A} = \begin{bmatrix}
+2 & 3 & 3\\
+1 & 2 & 3\\
+1 & 1 & 2
+\end{bmatrix}
+\]
+
+We can get:
+\[ \mathbf{L} = \begin{bmatrix}
+0 & 0 & 0\\
+1 & 0 & 0\\
+1 & 1 & 0
+\end{bmatrix}
+\]
+\[ \mathbf{D} = \begin{bmatrix}
+2 & 0 & 0\\
+0 & 2 & 0\\
+0 & 0 & 2
+\end{bmatrix}
+\]
+\[ \mathbf{U} = \begin{bmatrix}
+0 & 3 & 3\\
+0 & 0 & 3\\
+0 & 0 & 0
+\end{bmatrix}
+\]
+
+so:
+
+\[ \mathbf{A} = \mathbf{L} + \mathbf{D} + \mathbf{U} \]
+
+\[
+\begin{bmatrix}
+2 & 3 & 3\\
+1 & 2 & 3\\
+1 & 1 & 2
+\end{bmatrix}
+=
+\begin{bmatrix}
+0 & 0 & 0\\
+1 & 0 & 0\\
+1 & 1 & 0
+\end{bmatrix}
++
+\begin{bmatrix}
+2 & 0 & 0\\
+0 & 2 & 0\\
+0 & 0 & 2
+\end{bmatrix}
++
+\begin{bmatrix}
+0 & 3 & 3\\
+0 & 0 & 3\\
+0 & 0 & 0
+\end{bmatrix}
+\]
+
+\subsubsection{Jacobi's method}
+After decomposing matrix we can write the system of equations
+\[ \mathbf{A}\mathbf{x} = \mathbf{b} \]
+in the form:
+\[ \mathbf{D}\mathbf{x} = -(\mathbf{L}+\mathbf{U})\mathbf{x}+\mathbf{b}
+\]
+
+If we assume that diagonal entries of matrix \textbf{A} are nonzero, then matrix \textbf{D} is nonsingular therefore we can propose such an iterative method:
+\[ \mathbf{x}^{i+1} = -\mathbf{D}^{-1}(\mathbf{L}+\mathbf{U})\mathbf{x}^{(i)}+\mathbf{D}^{-1}\mathbf{x}
+\]
+This is the Jacobi's method.
+We can rewritte this equation in the form of \textit{n} independent scalar equations:
+
+\[
+{x}_j^{i+1} = -\frac{1}{d_{jj}}(
+\sum^n_{k=1} (l_{jk} + u_{jk})x_k^{(i)}+b_j)
+) \]
+Where $d_{jj}$; $l_{jk}$; $u_{jk}$ are the elements of the respective matrixes \textbf{D}, \textbf{L}, \textbf{U}
+
+Thanks to this we can do those computations in paraller, totally or partially if we are using a computer that enables a parallelization of the computations.
+
+\paragraph{Converging}
+Jacobi's method is convergent if we have strong diagonal dominance of the matrix \textbf{A}. (More on that in discussion of results)
+
+
+\subsubsection{Gauss-Seidel method}
+After decomposing matrix we can write the system of equations
+\[ \mathbf{A}\mathbf{x} = \mathbf{b} \]
+in the form:
+\[ (\mathbf{L}+\mathbf{D})\mathbf{x} = -\mathbf{U}\mathbf{x}+\mathbf{b}
+\]
+Again, we assume that \textbf{D} is nonsingular, in doing so we propose following iterative method:
+\[ \mathbf{D}\mathbf{x}^{(i+1)} = -\mathbf{L}\mathbf{x}^{(i+1)}-\mathbf{U}\mathbf{x}^{(i)}+\mathbf{b}
+\]
+Since matrix \textbf{L} is subdiagonal, provided that we organise the calculation of elements of the vector $x^{(i_1)}$ in a proper way, it does not hurt that $x^{(i_1)}$ is on the right side of the equation.
+\newpage
+In order to organise the calculation in the correct way we:
+First take into account the structure of matrixes \textbf{D} and \textbf{L}:
+\[
+\begin{bmatrix}
+d_{11}x_1^{(i_1)}\\
+d_{22}x_2^{(i_1)}\\
+d_{33}x_3^{(i_1)}\\
+\vdots\\
+d_{nn}x_n^{(i_1)}
+\end{bmatrix}
+=
+-
+\begin{bmatrix}
+0 & 0 & 0 & \cdots & 0\\
+l_{21} & 0 & 0 & \cdots & 0\\
+l_{32} & l_{32} & 0 & \cdots & 0\\
+\vdots & \vdots & \vdots & \vdots & \vdots\\
+l_{n1} & l_{n2} & l_{n3} & \cdots & 0
+\end{bmatrix}
+\begin{bmatrix}
+x_1^{(i_1)}\\
+x_2^{(i_1)}\\
+x_3^{(i_1)}\\
+\vdots\\
+x_n^{(i_1)}
+\end{bmatrix}
+-
+\mathbf{w}^{(i)}
+\]
+Where
+\[ \mathbf{w}^{(i)} = \mathbf{U}\mathbf{x}^{(i)} - \mathbf{b} \]
+So the order of calculations is as follows:
+\[ x_1^{(i+1)} = -\frac{w_1^{(i)}}{d_{11}} \]
+\[ x_2^{(i+1)} = -\frac{-l_{21}x_1^{(i+1)} - w_2^{(i)}}{d_{22}} \]
+\[ x_3^{(i+1)} = -\frac{-l_{31}x_1^{(i+1)} -l_{32}x_2^{(i+1)} - w_3^{(i)}}{d_{33}} \]
+
+And so on
+
+As opposed to Jacobi's method, Gauss-Seidel method computations must be performed sequentially. Every subsequent scalar equations uses results from the computation of the previous equations.
+\paragraph{Converging}
+Gauss-Seidel method is convergent if the matrix \textbf{A} is strongly row or column diagonnaly dominant. If the matrix is symmetric, the method is also convergent if the matrix \textbf{A} is positive definite. This method is also usually faster convergent compared to Jacobi's method.
+
+\newpage
+\subsubsection{Stop tests}
+There are two ways to check when to terminate iterations of the methods we just discussed:
+\begin{enumerate}
+\item Check differences between two subsequent iteration points
+\[
+\| \mathbf{x}^{(i+1)} - \mathbf{x}^{(i)} \| \leq \delta
+\]
+Where $\delta$ is an assumed tolerance, (in our case $10^{-10}$). What we are really interested in though is whether the solution of the system of equation has required accuracy. If we want to check that we can additionaly check (higher level, more computationally demanding test):
+\item Check differences between two subsequent iteration points
+\[
+\| \mathbf{A}\mathbf{x}^{(i+1)} - \mathbf{b}\| \leq \delta_2
+\]
+Where $\delta_2$ is an assumed tolerance. If this test is not passed then we can diminish the value of $\delta_2$ and continue with the iterations. Value of $\delta_2$ can not be too small since we are limited by the numerical errors.
+\end{enumerate}
+
+\newpage
+\subsubsection{\textbf{A} and \textbf{b}}
+We have been given the following system:
+\[
+\systeme{10x_1-4x_2+x_3+2x_4=-8, 2x_1-6x_2+3x_3-x_4=-12, x_1+4x_2-12x_3+x_4=4, 2x_1+3x_2-3x_3-10x_4=1}
+\]
+Therefore our matrices will look like this:
+\[
+\textbf{A} = \begin{bmatrix}
+10 & -4 & 1 & 2 \\
+2 & -6 & 3 & -1 \\
+1 & 4 & -12 & 1 \\
+2 & 3 & -3 & -10
+\end{bmatrix}
+\textbf{b} = \begin{bmatrix}
+-8 \\
+-12 \\
+4 \\
+11 \\
+\end{bmatrix}
+\]
+
+So:
+\[
+\textbf{L} = \begin{bmatrix}
+0 & 0 & 0 & 0 \\
+2 & 0 & 0 & 0 \\
+1 & 4 & 0 & 0 \\
+2 & 3 & -3 & 0
+\end{bmatrix}
+\textbf{D} = \begin{bmatrix}
+10 & 0 & 0 & 0 \\
+0 & -6 & 0 & 0 \\
+0 & 0 & -12 & 0 \\
+0 & 0 & 0 & -10
+\end{bmatrix}
+\textbf{U} = \begin{bmatrix}
+0 & -4 & 1 & 2 \\
+0 & 0 & 3 & -1 \\
+0 & 0 & 0 & 1 \\
+0 & 0 & 0 & 0
+\end{bmatrix}
+\]
+\[
+\textbf{D}^{-1} = \begin{bmatrix}
+\frac{1}{10} & 0 & 0 & 0 \\
+0 & - \frac{1}{6} & 0 & 0 \\
+0 & 0 & - \frac{1}{12} & 0 \\
+0 & 0 & 0 & - \frac{1}{10}
+\end{bmatrix}
+\]
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/11-results.tex b/NotProgramming/ENUME/projectA/sections/11-results.tex
new file mode 100644
index 00000000..d328d8a3
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/11-results.tex
@@ -0,0 +1,236 @@
+\section{Results}
+\subsection{Jacobi method result}
+For system of equations we got in this task we got following results:
+\\
+Without the change in demanded tolerance:
+\[ x = \left( \begin{array}{cc}
+ -0.076776098668341 \\
+ 2.105784262642568 \\
+ 0.395344797635474 \\
+ 0.397776619764909
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 1.154375287358407e-10 \]
+We managed to do this in \textbf{38} iterations of our loop, and the demanded tolerance did not change. (This required small change in code where I ommited the part of code responsible for changing demandedTolerance if $ \| \mathbf{A}x-b \| > \delta_2) $ )
+
+With the change in demanded tolerance:
+\[ x = \left( \begin{array}{cc}
+ -0.076776098668341 \\
+ 2.105784262642568 \\
+ 0.395344797635474 \\
+ 0.397776619764909
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 5.770361548895147e-11 \]
+We got this result in \textbf{37} iterations and demanded tolerance was equal to $2*10^{-10}$
+
+Compared to matlab function
+\[ x_{matlab} = \left( \begin{array}{cc}
+ -0.076776098662498 \\
+ 2.105784262636790 \\
+ 0.395344797637659 \\
+ 0.397776619767240 \\
+\end{array} \right)
+\]
+Matlab error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 4.070144838902081e-15 \]
+
+\newpage
+For data from task 2a we got: \\
+Without change in demanded tolerance:
+\[ x_a = \left( \begin{array}{cc}
+-0.930024655108186 \\
+-1.223407298660663 \\
+-1.273530574212508 \\
+-1.230517757317628 \\
+-1.151356031082747 \\
+-1.056883669273682 \\
+-0.952628310081466 \\
+-0.834334594312996 \\
+-0.683708806198363 \\
+-0.450125157620744 \\
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 6.955194519943778e-11 \]
+We managed to do this in \textbf{59} iterations of our loop, and the demanded tolerance did not change.
+
+With change in demanded tolerance:
+\[ x_a = \left( \begin{array}{cc}
+-0.930024655104470 \\
+-1.223407298653515 \\
+-1.273530574202540 \\
+-1.230517757305602 \\
+-1.151356031069692 \\
+-1.056883669260597 \\
+-0.952628310069469 \\
+-0.834334594303006 \\
+-0.683708806191233 \\
+-0.450125157617020 \\
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 1.699812218689508e-10 \]
+We managed to do this in \textbf{57} iterations of our loop, and the demanded tolerance changed to $4*10^{-10}$
+
+Compared to matlab function
+\[ x_{matlab} = \left( \begin{array}{cc}
+ -0.930024655110760 \\
+ -1.223407298665612 \\
+ -1.273530574219411 \\
+ -1.230517757325956 \\
+ -1.151356031091789 \\
+ -1.056883669282743 \\
+ -0.952628310089775 \\
+ -0.834334594319914 \\
+ -0.683708806203301 \\
+ -0.450125157623323 \\
+\end{array} \right)
+\]
+Matlab error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 3.662053438817790e-15 \]
+
+For Matrix and Vector from task 2b) error of
+\[ \| x^{(i+1)} - x^{(i)} \| \]
+grew to infinity, therefore we could never achieve demanded tolerance, therefore the program executed infinite loop.
+
+\subsubsection{Minimizing the demanded error}
+I tried to minimize the demanded error using this steps:
+\begin{enumerate}
+\item I copied error from matlab function and pasted it into demanded tolerance.
+\item If I did not get infinite loop I copied the newly acquired error and pasted it into demanded tolerance.
+\item If I got inifinite loop I used the previous error as "minimal" demanded error.
+\end{enumerate}
+\newpage
+\paragraph{For original system of equations:}
+We managed to get results with error as low as $1.776356839400250e-15$ with demanded tolerance = $3.202372833989376e-15$ for lower values program went into infinite loop.
+Results for demanded tolerance = $3.202372833989376e-15$
+For given matrix:
+\[ x = \left( \begin{array}{cc}
+ -0.076776098662498 \\
+ 2.105784262636790 \\
+ 0.395344797637659 \\
+ 0.397776619767240
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 3.108624468950438e-15 \]
+We got this result in \textbf{53} iterations and demanded tolerance did not change.
+
+\newpage
+\paragraph{For task 2a) system of equations:}
+We managed to get results with error as low as
+\[ 3.108624468950438e-15 \] with demanded tolerance:
+\[ 3.202372833989376e-15 \]
+for lower values program went into infinite loop.
+
+For demanded tolerance = $3.202372833989376e-15$:
+Results for 2a) system of equation
+
+\[ x_a = \left( \begin{array}{cc}
+-0.930024655110760 \\
+-1.223407298665613 \\
+-1.273530574219411 \\
+-1.230517757325955 \\
+-1.151356031091788 \\
+-1.056883669282743 \\
+-0.952628310089775 \\
+-0.834334594319914 \\
+-0.683708806203301 \\
+-0.450125157623323
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 3.108624468950438e-15 \]
+We managed to do this in \textbf{84} iterations of our loop, and the demanded tolerance did not change.
+We managed to achieve slightly better (as in, the error was smaller) results than Matlab custom function.
+
+\newpage
+\subsection{Gauss-Seidel method result}
+For system of equations we got in this task we got following results:
+\\
+\[ x = \left( \begin{array}{cc}
+ -0.076776098752996 \\
+ 2.105784262542701 \\
+ 0.395344797589652 \\
+ 0.397776619735316
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 6.999102842719934e-10 \]
+We managed to do this in \textbf{19} iterations of our loop, and the demanded tolerance did not change.
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 6.999102842719934e-10 \]
+We got this result in \textbf{19} iterations and demanded tolerance was equal to $2*10^{-10}$
+
+For data from task 2a we got: \\
+\[ x_a = \left( \begin{array}{cc}
+-0.930024655049330 \\
+-1.223407298590161 \\
+-1.273530574151901 \\
+-1.230517757273947 \\
+-1.151356031055568 \\
+-1.056883669259564 \\
+-0.952628310076145 \\
+-0.834334594312669 \\
+-0.683708806199986 \\
+-0.450125157622217 \\
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 5.311669113699570e-10 \]
+We managed to do this in \textbf{28} iterations of our loop, and the demanded tolerance did not change.
+
+For Matrix and Vector from task 2b) error of
+\[ \| x^{(i+1)} - x^{(i)} \| \]
+grew to infinity, therefore we could never achieve demanded tolerance, therefore the program executed infinite loop.
+
+\subsubsection{Minimizing the demanded error}
+I tried to minimize the demanded error using procedure from before
+\paragraph{For original system of equations:}
+We managed to get results with error as low as $1.776356839400250e-15$ with demanded tolerance = $ 1.986027322597818e-15 $ for lower values program went into infinite loop.
+Results for demanded tolerance = $1.986027322597818e-15$
+For given matrix:
+\[ x = \left( \begin{array}{cc}
+ -0.076776098662498 \\
+ 2.105784262636790 \\
+ 0.395344797637659 \\
+ 0.397776619767240
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 1.776356839400250e-15 \]
+We got this result in \textbf{30} iterations and demanded tolerance did not change.
+
+\newpage
+\paragraph{For task 2a) system of equations:}
+We managed to get results with error as low as
+\[ 1.538370149106851e-15 \] with demanded tolerance:
+\[ 1.538370149106851e-15 \]
+for lower values program went into infinite loop.
+
+For demanded tolerance = $1.538370149106851e-15$:
+Results for 2a) system of equation
+
+\[ x_a = \left( \begin{array}{cc}
+-0.930024655110760 \\
+-1.223407298665613 \\
+-1.273530574219411 \\
+-1.230517757325955 \\
+-1.151356031091788 \\
+-1.056883669282743 \\
+-0.952628310089775 \\
+-0.834334594319914 \\
+-0.683708806203301 \\
+-0.450125157623323 \\
+\end{array} \right)
+\]
+Error:
+\[ r = \| \mathbf{A}\mathbf{x} - \mathbf{b}\| = 1.538370149106851e-15 \]
+We managed to do this in \textbf{42} iterations of our loop, and the demanded tolerance did not change.
+We managed to achieve slightly better (as in, the error was smaller) results than Matlab custom function.
+
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/12-discussion-of-results.tex b/NotProgramming/ENUME/projectA/sections/12-discussion-of-results.tex
new file mode 100644
index 00000000..7b71cd40
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/12-discussion-of-results.tex
@@ -0,0 +1,66 @@
+\section{Discussion of results}
+\paragraph{Table}
+
+\begin{center}
+\resizebox{\textwidth}{!}{
+\begin{tabular}{||c c c c c c||}
+ \hline
+ system of equations & method & demanded tolerance & error & iterations \\
+ \hline
+ task 3 system & Jacobi method & 10e-10 & 1.154375287358407e-10 & 38 \\
+ \hline
+ task 3 system & Jacobi method & 10e-10 & 5.770361548895147e-11 & 37 \\
+ \hline
+ task 3 system & Jacobi method & 3.202372833989376e-15 & 3.108624468950438e-15 & 53 \\
+ \hline
+ task 3 system & Gaussian-Seidel method & 10e-10 & 6.999102842719934e-10 & 19 \\
+ \hline
+ task 3 system & Gaussian-Seidel method & 1.776356839400250e-15 & 1.776356839400250e-15 & 30 \\
+ \hline
+ task 3 system & Matlab function & ? & 4.070144838902081e-15 & ? \\
+ \hline
+ task 2a) system & Jacobi method & 10e-10 & 6.955194519943778e-11 & 59 \\
+ \hline
+ task 2a) system & Jacobi method & 10e-10 & 1.699812218689508e-10 & 57 \\
+ \hline
+ task 2a) system & Jacob method & 3.202372833989376e-15 & 3.108624468950438e-15 & 84 \\
+ \hline
+ task 2a) system & Gaussian-Seidel method & 10e-10 & 5.311669113699570e-10 & 28 \\
+ \hline
+ task 2a) system & Gaussian-Seidel method & 1.538370149106851e-15 & 1.538370149106851e-15 & 42 \\
+ \hline
+ task 2a) system & Matlab function & ? & 3.662053438817790e-15 & ? \\
+ \hline
+
+\end{tabular}}
+\end{center}
+\subsection{Comparison based on table}
+Gaussian-Seidel method takes less iterations, can achieve smaller error and works under smaller demanded tolerance, that being said Jacobi method has one crucial advantage - it can be run in parallel. That means that even when Jacobi method takes twice or thrice amount of iteration us Gaussian-Seidel one if we just run it in paraller we can diminish this difference. In the examples we worked in, just two jacobi method running in paraller provide us with similar amount of iterations per one process as in Gaussian-Seidel one, and three or more processes give the edge to Jacobi method. With modern CPU's with at least 5 cores and correct implementation of algorithm, jacobi method reigns supreme.
+
+\newpage
+\subsection{Convergence}
+The biggest problem is of course the fact that those iterative methods do not work on every system of equation. Like the one from task 2b).
+For Jacobi's method the matrix is convergent if it has strong diagonal dominance. \textbf{A}, i.e:
+\begin{enumerate}
+ \item \[ \| a_{ii} \| > \sum^n_{j=1, j \neq i} \|a_{ij} \| \]
+ \item \[ \| a_{jj} \| > \sum^n_{i=1, i \neq j} \|a_{ij} \| \]
+\end{enumerate}
+For Gaussian-Seidel method the matrix is convergent if it has strong diagonal dominance \textbf{or} if the matrix \textbf{A} is symmetric and positivie definite.
+\subsubsection{2b) task convergence }
+Let's check strong diagonal dominance from matrix \textbf{A} from task 2b) in matlab:
+\begin{simplechar}
+
+\hyperlink{function_3_dominant}{Code for checking if matrix is diagonally dominant}
+\\
+
+checkIfDiagonallyDominant(matrixB(10)) returns '0', therefore matrix from task 2b) will \textbf{not} converge. And as expected it does not work when put in my jacobiLoop function.
+\subsubsection{Iterations as function of size of Matrix}
+\hyperlink{function_3_plot}{Code for creating plot}
+I have used matrix from task 2a), demanded tolerance equal to 10e-10, and max size of matrix equal to 500. for both methods
+\begin{center}
+ \includegraphics[scale=0.75]{iterations.eps}
+\end{center}
+Gauss Seidel method again requires fewer iterations, around half the amount for Jacobi method. For both methods function of number of iterations acts like logarithmic function. Therefore we can assume that for big matrices required number of iterations will \textbf{not} change rapidly.
+
+\chapter{Problem 4 - QR method of finding eigenvalues}
+
diff --git a/NotProgramming/ENUME/projectA/sections/13-problem.tex b/NotProgramming/ENUME/projectA/sections/13-problem.tex
new file mode 100644
index 00000000..51410778
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/13-problem.tex
@@ -0,0 +1,2 @@
+\section{Problem}
+We must find eigenvalues of 5x5 matrices. Both without shifts and with shifts.
diff --git a/NotProgramming/ENUME/projectA/sections/14-theoretical-introduction.tex b/NotProgramming/ENUME/projectA/sections/14-theoretical-introduction.tex
new file mode 100644
index 00000000..9f7275e0
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/14-theoretical-introduction.tex
@@ -0,0 +1,35 @@
+\section{Theoretical introduction}
+\subsection{Eigenvalues}
+Eigenvalues of matrix \textbf{A} are defined as a pair of number $\lambda$ and vector \textbf{v} such that:
+\[ \mathbf{A}\mathbf{v} = \lambda\mathbf{v} \]
+This can be rewritten as:
+\[ (\mathbf{A} - \lambda\mathbf{I})\mathbf{v} = 0 \]
+And further we get characteristic equation:
+\[ det(\mathbf{A} - \lambda\mathbf{I}) = 0 \]
+
+\newpage
+\subsection{QR method for finding eigenvalues}
+First we start by transforming matrix \textbf{A} into tridiagonal form. It increases the effectiveness of calculations.
+
+Single step of QR method consists of:
+\[ \textbf{A}^{(k)} = \textbf{Q}^{(k)}\textbf{R}^{(k)} \]
+\[ \textbf{A}^{(k+1)} = \textbf{R}^{(k)}\textbf{Q}^{(k)} \]
+$\textbf{Q}^{(k)}$ being orthogonal, therefore:
+\[ \textbf{R}^{(k)} = (\textbf{Q}^{(k)}))^{-1}\textbf{A}^{(k)} = \textbf{Q}^{(k)T}\textbf{A}^{(k)}\textbf{Q}^{(k)} \]
+therefore:
+\[ \textbf{A}^{(k+1)} = \textbf{Q}^{(k)T}\textbf{A}^{(k)}\textbf{Q}^{(k)} \]
+If we have symmetric matrix \textbf{A} it converges to the diagonal matrix $diag(\lambda_i)$
+
+Since this method can be slowly convergent we use shifts. Single iteration of QR method with shifts looks like this:
+\begin{equation}
+\begin{split}
+\textbf{A}^{(k)} - p_k\textbf{I} &= \textbf{Q}^{(k)}\textbf{R}^{(k)} \\
+\textbf{A}^{(k+1)} &= \textbf{R}^{(k)}\textbf{Q}^{(k)} + p_k\textbf{I} \\
+&= \textbf{Q}^{(k)T}(\textbf{A}^{(k)} - p_k\textbf{I})\textbf{Q}^{(k)} + p_k\textbf{I} \\
+&=\textbf{Q}^{(k)T}\textbf{A}^{(k)}\textbf{Q}^{(k)} \\
+\end{split}
+\end{equation}
+
+Wher $p_k$ should be chosen as a best estimate of $\lambda_{i+1}$
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/15-results.tex b/NotProgramming/ENUME/projectA/sections/15-results.tex
new file mode 100644
index 00000000..af4126a9
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/15-results.tex
@@ -0,0 +1,80 @@
+\section{Results}
+\subsection{Starting matrix}
+I decided to generate random symmetric matrix using following code:
+\hyperlink{function4_matrix_generation}{code for matrix generation.}
+I got the following matrix:
+\[
+\begin{bmatrix}
+171 & 48 & 133 & 81 & 93 \\
+ 48 & 108 & 63 & 35 & 30 \\
+133 & 63 & 131 & 64 & 91 \\
+ 81 & 35 & 64 & 41 & 37 \\
+ 93 & 30 & 91 & 37 & 106
+\end{bmatrix}
+\]
+
+Putting it through Matlab eig function I got eigen values equal to:
+\[
+10^{2} *
+\begin{bmatrix}
+ 0.000050598692964 \\
+ 0.105696602175690 \\
+ 0.454589544003707 \\
+ 0.870708987227002 \\
+ 4.138954267900641
+\end{bmatrix}
+\]
+
+\newpage
+\subsection{QR method with no shifts}
+Putting this matrix to my functions QRNoShifts and QRShifts I got:
+for qr method with no shifts:
+Final matrix:
+\[
+\begin{bmatrix}
+413.8954 & 0.0000 & -0.0000 & 0.0000 & 0.0000 \\
+ 0.0000 & 87.0709 & -0.0000 & -0.0000 & 0.0000 \\
+0.0000 & -0.0000 & 45.4590 & -0.0000 & -0.0000 \\
+ -0.0000 & 0.0000 & -0.0000 & 10.5697 & -0.0000 \\
+ 0.0000 & -0.0000 & 0.0000 & 0 & 0.0051
+\end{bmatrix}
+\]
+
+Eigen values:
+\[
+10^{2} *
+\begin{bmatrix}
+ 4.138954267900639 \\
+ 0.870708987227001 \\
+ 0.454589544003706 \\
+ 0.105696602175689 \\
+ 0.000050598692964 \\
+\end{bmatrix}
+\]
+
+It took \textbf{26} iterations to get those values.
+
+\subsection{QR method with shifts}
+For qr method with shiftts:
+Final matrix:
+\[
+\begin{bmatrix}
+413.8954
+\end{bmatrix}
+\]
+
+Eigen values:
+\[
+10^{2} *
+\begin{bmatrix}
+ 0.454589544003706 \\
+ 0.870708987227001 \\
+ 0.105696602175689 \\
+ 0.000050598692964 \\
+ 4.138954267900639
+\end{bmatrix}
+\]
+
+It took \textbf{12} iterations to get those values.
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/16-discussion-of-the-result.tex b/NotProgramming/ENUME/projectA/sections/16-discussion-of-the-result.tex
new file mode 100644
index 00000000..54dd7d07
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/16-discussion-of-the-result.tex
@@ -0,0 +1,27 @@
+\section{Discussion of the result}
+Following plot was generated using \hyperlink{function4}{task4Plot} function, using maxMatrixSize = 25 and generating random symmetrical matrix of size i x i in each loop. Both QR methods were given exactly the same matrices.
+\subsection{Plot}
+
+\begin{center}
+ \includegraphics[scale=0.5]{task4plot.eps}
+\end{center}
+\newpage
+\subsection{Shift method superiority}
+As we can see:
+QR method with shifts is much more efficient and reliable.
+\begin{enumerate}
+\item For big enough matrices it requires ten times less iterations compared to QR method without shifts.
+\item It is more efficient in our chosen matrix.
+\item It can work with non-symetric matrices
+\item Has no problem with generating complex eigen values.
+\end{enumerate}
+ One thing that does not change much is the precision, with both algorithms outputting similar results.
+
+
+
+
+
+
+\addtocontents{toc}{\protect\newpage}
+\chapter{Code appendix}
+
diff --git a/NotProgramming/ENUME/projectA/sections/17-task-1-code.tex b/NotProgramming/ENUME/projectA/sections/17-task-1-code.tex
new file mode 100644
index 00000000..6000c01e
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/17-task-1-code.tex
@@ -0,0 +1,29 @@
+\section{Task 1 Code}
+\hypertarget{function1_macheps}{\subsection{Find macheps}}
+\begin{lstlisting}
+macheps = 1;
+while 1.0 + macheps / 2 > 1.0
+ macheps = macheps/2;
+end
+\end{lstlisting}
+\newpage
+\hypertarget{function1_display}{\subsection{Display results}}
+\begin{simplechar}
+\begin{lstlisting}
+format long
+disp("Display calculated macheps:")
+disp(macheps);
+disp("Display actual eps:")
+disp(eps);
+disp("Display 2^-52")
+disp(2^-52)
+disp("Display difference between calculated macheps and actual eps:")
+disp(macheps - eps)
+disp("Display difference between 2^-52 and actual eps:")
+disp(2^-52 - eps) \
+disp("Display difference between calculated macheps and 2^-52:")
+disp(macheps - 2^-52)
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/18-task-2-code.tex b/NotProgramming/ENUME/projectA/sections/18-task-2-code.tex
new file mode 100644
index 00000000..0ff6cdda
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/18-task-2-code.tex
@@ -0,0 +1,217 @@
+\section{Task 2 Code}
+\subsection{Main function}
+\begin{simplechar}
+\begin{lstlisting}
+function x = indicatedMethod(Matrix, Vector) % Name of the method as in the textbook
+% x stands for obtained result
+ [~,Columns] = size(Matrix); % We need to know how big the matrix is in next steps
+ % notice the '~', since We assume We use square matrix, We do not need
+ % to have another variable for number of rows since it is the same as
+ % number of columns
+ checkIfMatrixIsSquareMatrix(Matrix);
+ [Matrix, Vector] = gaussianEliminationWithPartialPivoting(Columns, Matrix, Vector);
+ % Change matrix to upper triangular matrix
+ [Matrix, Vector, x] = backSubstitutionPhase(Columns, Matrix, Vector);
+ % Get the solution
+ x = iterativeResidualCorrection(Matrix, x, Vector); % Improve on the solution
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{checkIfMatrixIsSquareMatrix}
+\begin{simplechar}
+\begin{lstlisting}
+function checkIfMatrixIsSquareMatrix(Matrix)
+ [Rows,Columns] = size(Matrix);
+ if Rows ~= Columns
+ error ('Matrix is not square matrix!');
+ end % end if
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{gaussianEliminationWithPartialPivoting}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, Vector] = gaussianEliminationWithPartialPivoting(Columns, Matrix, Vector)
+ for j = 1 : Columns
+ centralElement = max(Matrix(j:Columns,j));
+ % We stay in the same row (j) but We change columns, as in the
+ % textbook
+ [Matrix, Vector] = partialPivoting(Matrix, Vector, j, centralElement, Columns);
+ % ensures that a_kk != 0 and reduces errors
+ [Matrix, Vector] = gaussianElimination(j, Columns, Matrix, Vector);
+ % change matrix into upper triangular matrix
+ end % end for
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{partialPivoting}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, Vector] = partialPivoting(Matrix, Vector, j, centralElement, Columns)
+ for k = j : Columns
+ partialPivotingSwapOneRow(Matrix, Vector, j, k, centralElement);
+ end % end for
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{partialPivotingSwapOneRow}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, Vector] = partialPivotingSwapOneRow(Matrix, Vector, j, k, centralElement)
+ if Matrix(k,j) == centralElement
+ swapRowMatrix(Matrix, j, k); % swap jth row with kth row
+ swapValueVector(Vector, j, k); % swap jth value with kth value
+ end % end if
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+
+\subsection{swapRowMatrix}
+\begin{simplechar}
+\begin{lstlisting}
+function Matrix = swapRowMatrix(Matrix, j, k)
+ temp = Matrix(j , :); % ' : ' denote "all elements in jth row"
+ Matrix(j , :) = Matrix(k, :);
+ Matrix(k, :) = temp; % temp equal to previous value of jth row
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{swapValueVector}
+\begin{simplechar}
+\begin{lstlisting}
+function Vector = swapValueVector(Vector, j, k)
+ temp = Vector(j);
+ Vector(j) = Vector(k);
+ Vector(k) = temp; % temp equal to previous value of k element of vector
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{gaussianElimination}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, Vector] = gaussianElimination(j, Columns, Matrix, Vector)
+ for i = j + 1 : Columns
+ rowMultiplier = Matrix(i,j) / Matrix(j,j);
+ [Matrix, Vector] = substractRows(Matrix, Vector, i, rowMultiplier, j, Columns);
+ end % end for
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{substractRows}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, Vector] = substractRows(Matrix, Vector, i, rowMultiplier, j, Columns)
+ Vector(i) = Vector(i) - rowMultiplier * Vector(j);
+ for curentColumn = 1 : Columns
+ Matrix(i,curentColumn) = Matrix(i,curentColumn) - rowMultiplier * Matrix(j, curentColumn);
+ end % end for
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{backSubstitutionPhase}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, Vector, x] = backSubstitutionPhase(Columns, Matrix, Vector)
+ for k = Columns : -1 : 1
+ % Start at final column and move by -1 each iteration until we reach 1
+ equation = 0;
+ for j = k+1 : Columns
+ equation = equation + Matrix(k,j) * x(j, 1);
+ % even though x is a vector we still need to put '1' to ensure
+ % that number of columns in the first matrix matches number of
+ % rows in second matrix
+ end % end for
+
+ x(k, 1) = (Vector(k,1) - equation) / Matrix(k,k);
+ % even though x is a vector we still need to put '1' to ensure
+ % that we do not exceed array bounds
+ end % end for
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{iterativeResidualCorrection}
+\begin{simplechar}
+\begin{lstlisting}
+function x = iterativeResidualCorrection(Matrix, x, Vector)
+ residuum = Matrix*x - Vector; % as in the book
+ newResiduum = residuum;
+ x = improveSolution(x, newResiduum, residuum, Matrix, Vector);
+end % end function
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{improveSolution}
+\begin{simplechar}
+\begin{lstlisting}
+function x = iterativeResidualCorrection(A, x, b)
+ r = A*x - b;
+ for i = 1 : 100
+ [~, ~, deltaX] = solveSystem(A, r);
+ newX = x - deltaX;
+ r = A*newX - b;
+ x = newX;
+ end
+
+end % end function
+
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\hypertarget{function2_plot}{\subsection{plotErrorsGaussian}}
+\begin{simplechar}
+\begin{lstlisting}
+function plotErrorsGaussian(maxMatrixSize)
+
+ errorsA = zeros(maxMatrixSize);
+ errorsB = zeros(maxMatrixSize);
+ errorsAR = zeros(maxMatrixSize);
+ errorsBR = zeros(maxMatrixSize);
+ for i = 1 : maxMatrixSize
+ [~, errorBeforeResidualCorrection, errorAfterResidualCorrection] = indicatedMethod(matrixA(i), vectorA(i));
+ errorsA(i) = errorBeforeResidualCorrection;
+ errorsAR(i) = errorAfterResidualCorrection;
+ [~, errorBeforeResidualCorrection, errorAfterResidualCorrection] = indicatedMethod(matrixB(i), vectorB(i));
+ errorsB(i) = errorBeforeResidualCorrection;
+ errorsBR(i) = errorAfterResidualCorrection;
+ end
+ nexttile
+ plot(errorsA, '.');
+ title('Errors before residual correction for task 2a:');
+ xlabel('Size of matrix A');
+ ylabel('Errors');
+ nexttile
+ plot(errorsAR, '.');
+ title('Errors after residual correction for task 2a:');
+ xlabel('Size of matrix A');
+ ylabel('Errors');
+ nexttile
+ plot(errorsB, '.');
+ title('Errors before residual correction for task 2b:');
+ xlabel('Size of matrix A');
+ ylabel('Errors');
+ nexttile
+ plot(errorsBR, '.');
+ title('Errors after residual correction for task 2b:');
+ xlabel('Size of matrix A');
+ ylabel('Errors');
+end
+\end{lstlisting}
+\end{simplechar}
+
+
diff --git a/NotProgramming/ENUME/projectA/sections/19-task-3-code.tex b/NotProgramming/ENUME/projectA/sections/19-task-3-code.tex
new file mode 100644
index 00000000..72a060c5
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/19-task-3-code.tex
@@ -0,0 +1,222 @@
+\section{Task 3 Code}
+\begin{simplechar}
+\begin{lstlisting}
+function [x_j, x_g] = iterative(Matrix, Vector)
+ [L, D, U, initial_x, whichIterationAreWeOnJ, whichIterationAreWeOnG, demandedToleranceJ, demandedToleranceG, flag, Rows] = initializeValues(Matrix);
+ [x_j, whichIterationAreWeOnJ, demandedToleranceJ] = jacobiLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOnJ, demandedToleranceJ, Vector, flag);
+ [x_g, whichIterationAreWeOnG, demandedToleranceG] = gaussSeidelLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOnG, demandedToleranceG, Vector, flag, Rows);
+ dispFinalResults(x_j, x_g, demandedToleranceJ, demandedToleranceG, whichIterationAreWeOnJ, whichIterationAreWeOnG, Matrix, Vector);
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{initializeValues}
+\begin{simplechar}
+\begin{lstlisting}
+function [L, D, U, initial_x, whichIterationAreWeOnJ, whichIterationAreWeOnG, demandedToleranceJ, demandedToleranceG, flag, Rows] = initializeValues(Matrix)
+ [Rows, ~] = size(Matrix);
+ [L, D, U] = decomposeMatrix(Matrix);
+ initial_x = zeros(Rows, 1);
+ whichIterationAreWeOnJ = 0;
+ whichIterationAreWeOnG = 0;
+ demandedToleranceJ = 10e-10; % as per task description
+ demandedToleranceG = 10e-10; % as per task description
+ flag = 0;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{decomposeMatrix}
+\begin{simplechar}
+\begin{lstlisting}
+function [L, D, U] = decomposeMatrix(Matrix)
+ D = diag(diag(Matrix));
+ U = triu(Matrix, 1); % Generates upper triangular part of matrix
+ % where the second variable denotes on which diagonal of matrix should be
+ % start
+ L = tril(Matrix, -1); % Generates lower triangular part of matrix
+ % where the second variable denotes on which diagonal of matrix should be
+ % start
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{jacobiLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [x_j, whichIterationAreWeOn, demandedTolerance] = jacobiLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector, flag)
+ while flag ~= 1 % flag denotes whether norm(Matrix*x_g-Vector) <= demandedTolerance
+ [x_j, whichIterationAreWeOn, demandedTolerance, flag, initial_x] = jacobiInsideLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{jacobiInsideLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [x_j, whichIterationAreWeOn, demandedTolerance, flag, initial_x] = jacobiInsideLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector)
+ x_j = jacobiEquation(D, L, U, initial_x, Vector);
+ [flag, demandedTolerance] = checkError(x_j, initial_x, demandedTolerance, Matrix, Vector);
+ [initial_x, whichIterationAreWeOn] = endOfLoop(x_j, whichIterationAreWeOn);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{jacobiEquation}
+\begin{simplechar}
+\begin{lstlisting}
+function x = jacobiEquation(D, L, U, initial_x, Vector)
+ x = - D \ ( L + U ) * initial_x + D \ Vector; % As per formula
+ % We will be using D \ Vector and D \ ( ) instead of inverseD since
+ % this is faster according to matlab
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{gaussSeidelLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [x_g, whichIterationAreWeOn, demandedTolerance] = gaussSeidelLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector, flag, Rows)
+ while flag ~= 1 % flag denotes whether norm(Matrix*x_g-Vector) <= demandedTolerance
+ [x_g, whichIterationAreWeOn, demandedTolerance, flag, initial_x] = gaussiInsideLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector, Rows);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{gaussiInsideLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [x_j, whichIterationAreWeOn, demandedTolerance, flag, initial_x] = gaussiInsideLoop(Matrix, L, D, U, initial_x, whichIterationAreWeOn, demandedTolerance, Vector, Rows)
+ x_j = gaussSeidelEquation(D, L, U, initial_x, Vector, Rows);
+ [flag, demandedTolerance] = checkError(x_j, initial_x, demandedTolerance, Matrix, Vector);
+ [initial_x, whichIterationAreWeOn] = endOfLoop(x_j, whichIterationAreWeOn);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{gaussSeidelEquation}
+\begin{simplechar}
+\begin{lstlisting}
+function x_g = gaussSeidelEquation(D, L, U, initial_x, Vector, Rows)
+ W = U*initial_x - Vector;
+ x_g(1, 1) = -W(1, 1) / D(1,1);
+ for i = 2 : Rows
+ x_g(i, 1) = calculateNominator(i, L, x_g, W) / D(i, i);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{checkError}
+\begin{simplechar}
+\begin{lstlisting}
+function [flag, demandedTolerance] = checkError(x, initial_x, demandedTolerance, Matrix, Vector)
+ flag = 0;
+ currentError = norm(x - initial_x);
+ if currentError <= demandedTolerance
+ currentError = norm(Matrix*x-Vector);
+ if currentError <= demandedTolerance % if sequence as per textbook
+ flag = 1;
+ else
+ demandedTolerance = demandedTolerance * 2; % arbitrary value
+ end
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsection{endOfLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [initial_x, whichIterationAreWeOn, flag] = endOfLoop(x, whichIterationAreWeOn)
+ initial_x = x;
+ whichIterationAreWeOn = whichIterationAreWeOn + 1;
+ flag = 0;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{dispFinalResults}
+\begin{simplechar}
+\begin{lstlisting}
+function dispFinalResults(x_j, x_g, demandedToleranceJ, demandedToleranceG, whichIterationAreWeOnJ, whichIterationAreWeOnG, Matrix, Vector)
+ disp("Final demandedTolerance for Jacobi method");
+ disp(demandedToleranceJ);
+ disp("Final demandedTolerance for Gaussian-Seidel method:");
+ disp(demandedToleranceG);
+ disp("Final Iteration for Jacobi method: ");
+ disp(whichIterationAreWeOnJ);
+ disp("Final Iteration for Gaussian-Seidel method: ");
+ disp(whichIterationAreWeOnG);
+ disp("Error for Jacobi method:");
+ disp(norm(Matrix*x_j - Vector));
+ disp("Error for Gaussian-Seidel method:");
+ disp(norm(Matrix*x_g - Vector));
+ disp("A\b error:");
+ disp(norm(Matrix * (Matrix\Vector) - Vector));
+ disp("Answer for Jacobi method: ");
+ disp(x_j);
+ disp("Answer for Gaussian-Seidel method: ");
+ disp(x_g);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\hypertarget{function_3_plot}{\subsection{plotIterations}}
+\begin{simplechar}
+\begin{lstlisting}
+function plotIterations()
+ maxMatrixSize = 500;
+ iterationsJ = zeros(maxMatrixSize);
+ iterationsG = zeros(maxMatrixSize);
+ for i = 1 : maxMatrixSize
+ [~, ~, whichIterationAreWeOnJ, whichIterationAreWeOnG] = iterative(matrixA(i), vectorA(i));
+ iterationsJ(i) = whichIterationAreWeOnJ;
+ iterationsG(i) = whichIterationAreWeOnG;
+ end
+ nexttile
+ plot(iterationsJ, '.');
+ title('Number of iterations for different sizes of matrices for Jacobi method');
+ xlabel('Size of matrix A');
+ ylabel('Number of iterations');
+ nexttile
+ plot(iterationsG, '.');
+ title('Number of iterations for different sizes of matrices for Gauss-Seidel method');
+ xlabel('Size of matrix A');
+ ylabel('Number of iterations');
+
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\hypertarget{function_3_dominant}{Code for checking if matrix is diagonally dominant}
+\begin{lstlisting}
+function d = checkIfDiagonallyDominant(Matrix)
+ d = 1;
+ [Rows, ~] = size(Matrix);
+ for i = 1 : Rows
+ rowsSum = 0;
+ for j = 1 : Rows
+ rowsSum = rowsSum + abs(Matrix(i, j));
+ end
+ rowsSum = rowsSum - Matrix(i, i);
+ if Matrix(i, i) <= rowsSum
+ d = 0;
+ break
+ end
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/20-task-4-code.tex b/NotProgramming/ENUME/projectA/sections/20-task-4-code.tex
new file mode 100644
index 00000000..762d2429
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/20-task-4-code.tex
@@ -0,0 +1,5 @@
+\section{Task 4 Code}
+ \input{sections/20-task-4-code/01-gram-schmid-algorithm}
+ \input{sections/20-task-4-code/02-task4}
+ \input{sections/20-task-4-code/03-qrnoshifts}
+ \input{sections/20-task-4-code/04-qrshifts}
diff --git a/NotProgramming/ENUME/projectA/sections/20-task-4-code/01-gram-schmid-algorithm.tex b/NotProgramming/ENUME/projectA/sections/20-task-4-code/01-gram-schmid-algorithm.tex
new file mode 100644
index 00000000..7f5de202
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/20-task-4-code/01-gram-schmid-algorithm.tex
@@ -0,0 +1,56 @@
+\subsection{Gram-Schmid algorithm}
+
+\begin{simplechar}
+\begin{lstlisting}
+% performs QR or QRdash decomposition of a matrix
+function [Q, R] = gramSchmidtAlgorithm(Matrix)
+ [columns, Q, R, d] = initializeGramSchmid(Matrix);
+ [Q, R] = factorizeColumnsOfQ(columns, Q, Matrix, R, d);
+ [Q, R] = normalizeColumns(columns, Q, R);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{initializeGramSchmid}
+\begin{simplechar}
+\begin{lstlisting}
+function [columns, Q, R, d] = initializeGramSchmid(Matrix)
+ % We start with empty matrices
+ [rows, columns] = size(Matrix);
+ Q = zeros(rows, columns);
+ R = zeros(columns, columns);
+ d = zeros(1, columns);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{factorizeColumnsOfQ}
+\begin{simplechar}
+\begin{lstlisting}
+function [Q, R] = factorizeColumnsOfQ(columns, Q, Matrix, R, d)
+ for i = 1 : columns
+ Q(:, i) = Matrix(:, i);
+ R(i, i) = 1;
+ d(i) = Q(:, i)' * Q(:, i);
+ for i2 = i + 1 : columns
+ R(i, i2) = (Q(:, i)' * Matrix(:, i2)) / d(i);
+ Matrix(:, i2) = Matrix(:, i2) - R(i, i2) * Q(:, i);
+ end
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{normalizeColumns}
+\begin{simplechar}
+\begin{lstlisting}
+function [Q, R] = normalizeColumns(columns, Q, R)
+ for i = 1 : columns
+ dd = norm(Q(:, i));
+ Q(:, i) = Q(:, i) / dd;
+ R(i, i:columns) = R(i, i : columns) * dd;
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectA/sections/20-task-4-code/02-task4.tex b/NotProgramming/ENUME/projectA/sections/20-task-4-code/02-task4.tex
new file mode 100644
index 00000000..3f839f44
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/20-task-4-code/02-task4.tex
@@ -0,0 +1,10 @@
+\subsection{task4}
+\begin{simplechar}
+\begin{lstlisting}
+function [eigenValuesNoShifts, iterationsNoShifts, finalMatrixNoShifts, eigenValuesShifts, iterationsShifts, finalMatrixShifts] = task4(Matrix)
+ [eigenValuesNoShifts, iterationsNoShifts, finalMatrixNoShifts] = QRNoShifts(Matrix);
+ [eigenValuesShifts, iterationsShifts, finalMatrixShifts] = QRShifts(Matrix);
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectA/sections/20-task-4-code/03-qrnoshifts.tex b/NotProgramming/ENUME/projectA/sections/20-task-4-code/03-qrnoshifts.tex
new file mode 100644
index 00000000..49085b28
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/20-task-4-code/03-qrnoshifts.tex
@@ -0,0 +1,79 @@
+\subsection{QRNoShifts}
+\begin{simplechar}
+\begin{lstlisting}
+function [eigenValues, whichIterationAreWeOn, Matrix] = QRNoShifts(Matrix)
+
+ [whichIterationAreWeOn, threshold, startingMatrix, matlabEigen] = initializeValues(Matrix);
+ [Matrix, whichIterationAreWeOn] = QRNoShiftsLoop(threshold, Matrix, whichIterationAreWeOn);
+ eigenValues = diag(Matrix)';
+ displayResults(eigenValues, whichIterationAreWeOn, Matrix, startingMatrix, matlabEigen);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{QRNoShiftsLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, whichIterationAreWeOn] = QRNoShiftsLoop(threshold, Matrix, whichIterationAreWeOn)
+ while threshold > 1e-6
+ [Matrix, whichIterationAreWeOn, threshold] = QRNoShiftsInsideLoop(Matrix, whichIterationAreWeOn);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{QRNoShiftsInsideLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, whichIterationAreWeOn, threshold] = QRNoShiftsInsideLoop(Matrix, whichIterationAreWeOn)
+ [Q, R] = gramSchmidtAlgorithm(Matrix);
+ Matrix = R * Q;
+ whichIterationAreWeOn = whichIterationAreWeOn + 1;
+
+ % iterate until all non-diagonal elements are below the threshold
+ matrixWithoutDiagonal = Matrix - diag(diag(Matrix)); % first diag converts Matrix
+ % into vector consisting of values on the diagonal of matrix,
+ % second diag converts this vector into matrix with zeros on
+ % everything except diagonal
+ % If we substract it from Matrix we get original Matrix with zeros
+ % on a diagonal
+ threshold = max(max(abs(matrixWithoutDiagonal)));
+ % first max returns vector of elements
+ % second max returns max element from this vector
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{displayResults}
+\begin{simplechar}
+\begin{lstlisting}
+function displayResults(eigenValues, whichIterationsAreWeOn, Matrix, startingMatrix, matlabEigen)
+ disp("How many iterations it took:")
+ disp(whichIterationsAreWeOn)
+ disp("Starting Matrix:")
+ disp(startingMatrix)
+ disp("Final Matrix:")
+ disp(Matrix)
+ disp("eig(Matrix) eigen values:")
+ disp(matlabEigen)
+ disp("Our eigen values:")
+ disp(eigenValues);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{initializeValues}
+\begin{simplechar}
+\begin{lstlisting}
+function [whichIterationAreWeOn, threshold, startingMatrix, matlabEigen] = initializeValues(Matrix)
+ whichIterationAreWeOn = 0;
+ threshold = inf;
+ startingMatrix = Matrix;
+ matlabEigen = eig(Matrix);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
diff --git a/NotProgramming/ENUME/projectA/sections/20-task-4-code/04-qrshifts.tex b/NotProgramming/ENUME/projectA/sections/20-task-4-code/04-qrshifts.tex
new file mode 100644
index 00000000..f10e52aa
--- /dev/null
+++ b/NotProgramming/ENUME/projectA/sections/20-task-4-code/04-qrshifts.tex
@@ -0,0 +1,209 @@
+\subsection{QRShifts}
+\begin{simplechar}
+\begin{lstlisting}
+function [eigenValues, whatIterationAreWeOn, Matrix] = QRShifts(Matrix)
+ eigenFromMatlab = eig(Matrix);
+ initialMatrix = Matrix;
+ [eigenValues, whatIterationAreWeOn, matrixSize, minThreshold] = initiateValues(Matrix);
+ [Matrix, whatIterationAreWeOn, eigenValues] = QRShiftLoop(matrixSize, Matrix, eigenValues, minThreshold, whatIterationAreWeOn);
+ dispResults(eigenValues, Matrix, whatIterationAreWeOn, eigenFromMatlab, initialMatrix);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{initiateValues}
+\begin{simplechar}
+\begin{lstlisting}
+function [eigenValues, whatIterationAreWeOn, matrixSize, minThreshold] = initiateValues(Matrix)
+ eigenValues = double.empty(1, 0);
+ whatIterationAreWeOn = 0;
+ matrixSize = size(Matrix, 1);
+ minThreshold = 1e-6;
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{QRShiftLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, whatIterationAreWeOn, eigenValues] = QRShiftLoop(matrixSize, Matrix, eigenValues, minThreshold, whatIterationAreWeOn)
+ while matrixSize >= 2
+ flag = 0;
+ [Matrix, matrixSize, whatIterationAreWeOn, eigenValues] = findEigenValue(Matrix, matrixSize, whatIterationAreWeOn, eigenValues, minThreshold, flag);
+ [matrixSize, Matrix] = deflateMatrix(Matrix, matrixSize);
+ end
+ eigenValues(size(eigenValues, 2) + 1) = Matrix(1, 1);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{findEigenValue}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, matrixSize, whatIterationAreWeOn, eigenValues] = findEigenValue(Matrix, matrixSize, whatIterationAreWeOn, eigenValues, minThreshold, flag)
+ while flag == 0
+ eigenValueCorner = getEigenValueFromCorner(Matrix, matrixSize);
+ [Matrix, whatIterationAreWeOn] = shiftAndIterate(matrixSize, Matrix, eigenValueCorner, whatIterationAreWeOn);
+ [flag, eigenValues] = thresholdBreached(Matrix, matrixSize, minThreshold, eigenValues);
+ end
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{getEigenValueFromCorner}
+\begin{simplechar}
+\begin{lstlisting}
+function eigenValueCorner = getEigenValueFromCorner(Matrix, matrixSize)
+ corner = Matrix((matrixSize - 1) : matrixSize, (matrixSize - 1) : matrixSize);
+ % get 2 x 2 corner of the matrix
+ eigenValueCorner = solveCharactersticEquation(corner);
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{shiftAndIterate}
+\begin{simplechar}
+\begin{lstlisting}
+function [Matrix, whatIterationAreWeOn] = shiftAndIterate(matrixSize, Matrix, eigenValueCorner, whatIterationAreWeOn)
+ % shift and iterate algorithm
+ identityMatrix = eye(matrixSize);
+ Matrix = Matrix - identityMatrix * eigenValueCorner;
+ [Q, R] = gramSchmidtAlgorithm(Matrix);
+ Matrix = R * Q + identityMatrix * eigenValueCorner;
+ whatIterationAreWeOn = whatIterationAreWeOn + 1;
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{deflateMatrix}
+\begin{simplechar}
+\begin{lstlisting}
+function [matrixSize, Matrix] = deflateMatrix(Matrix, matrixSize)
+ matrixSize = matrixSize - 1;
+ Matrix = Matrix(1:matrixSize, 1:matrixSize);
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{thresholdBreached}
+\begin{simplechar}
+\begin{lstlisting}
+function [flag, eigenValues] = thresholdBreached(Matrix, matrixSize, minThreshold, eigenValues)
+ flag = 0;
+ threshold = max(abs(Matrix(matrixSize, 1:(matrixSize - 1))));
+
+ % once we zero the row (or rather get close enough to zero) exit loop
+ if (threshold <= minThreshold)
+ eigenValues(size(eigenValues, 2) + 1) = Matrix(matrixSize, matrixSize);
+ flag = 1;
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{solveCharactersticEquation}
+\begin{simplechar}
+\begin{lstlisting}
+% finds the eigenvalue of a 2x2 matrix that is closer to the lower right corner
+function eigen = solveCharactersticEquation(Matrix)
+ [eigenOne, eigenTwo] = calculateZeros(Matrix);
+ eigen = valueCloserToLowerRightCorner(eigenOne, eigenTwo, Matrix);
+end
+
+function eigen = valueCloserToLowerRightCorner(eigenOne, eigenTwo, Matrix)
+ if abs(Matrix(4) - eigenOne) < abs(Matrix(4) - eigenTwo)
+ eigen = eigenOne;
+ else
+ eigen = eigenTwo;
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{calculateZeros}
+\begin{simplechar}
+\begin{lstlisting}
+function [zeroOne, zeroTwo] = calculateZeros(Matrix)
+ b = Matrix(1) + Matrix(4);
+ ac = Matrix(1) * Matrix(4) - Matrix(2) * Matrix(3);
+ delta = (b) ^ 2 - 4 * ac;
+ % get delta of quadratic equation
+ squareRootDelta = sqrt(delta);
+ % square delta
+ zeroOne = (b - squareRootDelta) / 2;
+ zeroTwo = (b + squareRootDelta) / 2;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{dispResults}
+\begin{simplechar}
+\begin{lstlisting}
+function dispResults(eigenValues, Matrix, whatIterationAreWeOn, eigenFromMatlab, initialMatrix)
+ disp("Initial matrix: ");
+ disp(initialMatrix);
+ disp("Final matrix: ");
+ disp(Matrix);
+ disp("Number of iterations: ");
+ disp(whatIterationAreWeOn);
+ disp("Eigen values from eig(Matrix):");
+ disp(eigenFromMatlab);
+ disp("Our eigen values: ");
+ disp(eigenValues);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\hypertarget{function4}{\subsection{task4Plot}}
+\begin{simplechar}
+\begin{lstlisting}
+function task4Plot(maxMatrixSize)
+ iterationsNoShiftsVector = zeros(maxMatrixSize);
+ iterationsShiftsVector = zeros(maxMatrixSize);
+ for i = 1 : maxMatrixSize
+ [~, iterationsNoShifts, ~, ~, iterationsShifts, ~] = task4(matrix4(i));
+ iterationsNoShiftsVector(i) = iterationsNoShifts;
+ iterationsShiftsVector(i) = iterationsShifts;
+ end
+ nexttile
+ plot(iterationsNoShiftsVector, '.');
+ title('Number of iterations for different sizes of matrices for no shift method');
+ xlabel('Size of matrix A');
+ ylabel('Number of iterations');
+ nexttile
+ plot(iterationsShiftsVector, '.');
+ title('Number of iterations for different sizes of matrices for shift method');
+ xlabel('Size of matrix A');
+ ylabel('Number of iterations');
+end
+\end{lstlisting}
+\end{simplechar}
+
+\hypertarget{function4_matrix_generation}{\subsection{Matrix generation}}
+\begin{simplechar}
+\begin{lstlisting}
+function A = matrix4()
+ A = 10 * rand(5); % rand generates 5x5 matrix filled with random numbers
+ % we multiply by 10 to get at lest one digit in front of the dot
+ A = floor(A); % we floor the matrix we got to get nice natural numbers matrix
+ A = A * A'; % we get symmetric matrix
+ disp(issymmetric(A)); % we check if matrix is symmetric
+end
+\end{lstlisting}
+\end{simplechar}
+
+
+\begin{thebibliography}{9}
+\bibitem{texbook}
+Piotr Tatjewski (2014) \emph{Numerical Methods}, Oficyna Wydawnicza Politechniki Warszawskiej
+\end{thebibliography}
+
diff --git a/NotProgramming/ENUME/projectB/Report/report.tex b/NotProgramming/ENUME/projectB/Report/report.tex
index 70b0929c..d1c435ab 100644
--- a/NotProgramming/ENUME/projectB/Report/report.tex
+++ b/NotProgramming/ENUME/projectB/Report/report.tex
@@ -46,1592 +46,15 @@ linkto=all,
\chapter{Find all zeros of function}
-\section{a) False position method}
-
-\subsection{Problem}
-
-We have to find zeros of the function
-\[ f(x) = -2.1 + 0.3x - xe^{-x} \]
-In the interval $[-5; 10]$ using false position method.
-
-\subsection{Theoretical Introduction}
-\emph{False position} method also called \emph{regula falsi} in fancier circles is similar to the bisection method, the difference is that the interval we use $[a_n, b_n]$ is divided into two subintervals. We have:
-\begin{itemize}
-\item $\alpha$ - The root
-\item $a_n$ - 'left' interval
-\item $b_n$ - 'right' interval
-\item $f(a_n)$ - Value at left interval
-\item $f(b_n)$ - Value at right interval
-\end{itemize}
-
-We get:
-\[ \frac{f(b_n) - f(a_n)}{b_n - a_n} = \frac{f(b_n) - 0}{b_n - c_n} \]
-From which we get:
-\[ c_n = b_n - \frac{f(b_n)(b_n - a_n)}{f(b_n) - f(a_n)} = \frac{a_nf(b_n) - b_n f(a_n)}{f(b_n)-f(a_n)} \]
-
-Then we choose next interval as in the bisection method so: we calculate products of function values at $a_n$ and $b_n$ and that subinterval is selected for the next iteration of \emph{false position} method. This subinterval corresponds to the negative product value.
-
-\subsubsection{Properties of \emph{false position method}}
-This method is always convergent, simillary to bisection method, since it will always choose and shorten the interval which contains the root. If the function is continous and differentiable the method is linearly convergent. That being said the convergence may become sluggish. It can happen if for example one of the endpoints of the intervals will remain the same and the iterating will not shorten the interval to 0. One of the examples of functions that lead to that are barrier functions used in constrained optimization methods.
-
-\paragraph{Improvement to the method}
-In order to improve the formula and avoid aforementioned situation we can take smaller value of the function for the value that does not change.
-For right end:
-\[ c_n = \frac{a_n\frac{f(b_n)}{2} - b_nf(a_n)}{\frac{f(b_n)}{2} - f(a_n)} \]
-And for left end:
-\[ c_n = \frac{a_nf(b_n) - b_n\frac{f(a_n)}{2}}{f(b_n)- \frac{f(a_n)}{2}} \]
-
-This is called \emph{modified regula falsi} or \emph{Illinois algorithm}.
-It is superlinearly convergent, globally convergent and length of intervals we get in each iterations converges to zero.
-\subsection{Results}
-
-\begin{center}
- \includegraphics[scale=0.25]{task1falsepositionoverall.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task1falsepositionzommedleft.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task1falsepositionzommedright.eps}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & -0.17673 &-1.9421 \\
-\hline
-2 & -0.32943 &-1.7409 \\
-\hline
-3 & -0.39578 &-1.6308 \\
-\hline
-4 &-0.61812 &-1.1386 \\
-\hline
-5 &-0.76152 &-0.69765 \\
-\hline
-6 &-0.84516 &-0.38573 \\
-\hline
-7 &-0.89015 &-0.19911 \\
-\hline
-8 &-0.91304 &-0.098733 \\
-\hline
-9 & -0.92431 &-0.047922 \\
-\hline
-10 & -0.92976 & -0.02301 \\
-\hline
-11 &-0.93237 & -0.01099 \\
-\hline
-12 &-0.93362 &-0.005236 \\
-\hline
-13 &-0.93421 &-0.0024915 \\
-\hline
-14 &-0.9345 &-0.0011848 \\
-\hline
-15 &-0.93463 &-0.0005633 \\
-\hline
-16 &-0.93469 &-0.00026777 \\
-\hline
-17 &-0.93473 &-0.00012728 \\
-\hline
-18 &-0.93474 &-6.0499e-05 \\
-\hline
-19 &-0.93475 &-2.8756e-05 \\
-\hline
-20 &-0.93475 & -1.3668e-05 \\
-\hline
-21 &-0.93475 & -6.4964e-06 \\
-\hline
-22 &-0.93475 & -3.0878e-06 \\
-\hline
-23 &-0.93475 & -1.4676e-06 \\
-\hline
-24 &-0.93475 & -6.9758e-07 \\
-\hline
-25 &-0.93475 & -3.3157e-07 \\
-\hline
-26 &-0.93475 & -1.5759e-07 \\
-\hline
-27 &-0.93475 & -7.4906e-08 \\
-\hline
-28 &-0.93475 & -3.5603e-08 \\
-\hline
-29 &-0.93475 & -1.6922e-08 \\
-\hline
-30 &-0.93475 & -8.0433e-09 \\
-\hline
-31 &-0.93475 & -3.823e-09 \\
-\hline
-32 &-0.93475 & -1.8171e-09 \\
-\hline
-33 &-0.93475 & -8.6368e-10 \\
-\hline
-34 &-0.93475 & -4.1051e-10 \\
-\hline
-35 &-0.93475 & -1.9512e-10 \\
-\hline
-36 &-0.93475 & -9.2741e-11 \\
-\hline
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 7.0323 & 0.0034663 \\
-\hline
-2 & 7.0212 & 9.0344e-05 \\
-\hline
-3 & 7.0211 & 4.6349e-05 \\
-\hline
-4 & 7.0208 & -4.3921e-05 \\
-\hline
-5 & 7.0209 & 4.8939e-11 \\
-\hline
-
-\hline
-\end{tabular}
-\end{center}
-
-\section{b) the Newton's method}
-
-
-\subsection{Problem}
-
-We have to find zeros of the function
-\[ f(x) = -2.1 + 0.3x - xe^{-x} \]
-In the interval $[-5; 10]$
-
-using the Newton's method
-\subsection{Theoretical Introduction}
-\emph{The Newton's method} also called \emph{the tangent method} relies on first order part of its expansion into Taylor series for a given current approximation of root.
-\[ f(x) \approx f(x_n) + f^{'}(x_n)(x-x_n) \]
-Then we obtain the next point $x_{x+1}$ by finding root of linear function:
-\[ f(x_n) + f^{'}(x_n)(x_{n+1}-x_n) = 0 \]
-From this we get formula for $x_{n+1}$:
-\[ x_{n+1} = x_n - \frac{f(x_n)}{f^{'}(x_n)} \]
-
-This method as opposed to \emph{regula falsi} method is locally convergent, should we choose initial point too far from the root (area which is close enough to root is called set of attraction) then we can get a divergence. On the other side if the Newton's method will converge then it is quite rapid with convergence of order p = 2 - quadratic convergence.
-
-Newton's method is also effective if the function derrivative is far from zero, so the slope of the function is steep, conversely if the derrivative is close to zero the method is not recommended.
-\subsection{Results}
-
-\begin{center}
- \includegraphics[scale=0.25]{task1Newtonoverall.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task1Newtonzommedleft.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task1Newtonzommedright.eps}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & -1.25 & 1.8879 \\
-\hline
-2 & -1.0001 & 0.31855 \\
-\hline
-3 & -0.93804 & 0.015256 \\
-\hline
-4 & -0.93476 & 4.0314e-05 \\
-\hline
-5 & -0.93475 & 2.8356e-10 \\
-\hline
-6 & -0.93475 & 0 \\
-\hline
-\hline
-
-\hline
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 6.25 & -0.23707 \\
-\hline
-2 & 7.0144 & -0.0019866 \\
-\hline
-3 & 7.0209 & -9.517e-08 \\
-\hline
-4 &7.0209 & 7.468e-16 \\
-\hline
-\hline
-
-\hline
-\end{tabular}
-\end{center}
-
-\subsection{Discussion of results}
-As we can see and as we could expect from theory Newton method reigns supreme.
-It is:
-\begin{enumerate}
-\item Faster.
-Especially for finding first root. It took 36 iterations for false position method to find first root with accuary up to $10^{-10}$ and it took only 6 iterations for the Newton method.
-\item More accurate
-Not only that we also got more accurate results with Newton method! With first root being so close to the real answer that the matlab calculated the value of this function at this point as exactly equal to 0. For second root the accuary is $10^{6}$ better than for the false position method.
-\item Smaller gaps
-Looking at graphs we got from both method we can clearly see that the gaps between the final result and each and every step are much smaller for Newton method. This again proves that it is faster and more accurate compared to false position method.
-\end{enumerate}
-
-
-
-\chapter{Find real and complex roots of the polynomial}
-
-\section{Problem}
-
-We have to find all real and complex roots of the polynomial:
-
-\[ f(x) = a_4x^4+a_3x^3+a_2x^2+a_1x+a_0 \]
-where:
-\[ [a_4 \; a_3 \; a_2 \; a_1 \; a_0] = [-2 \; 12 \; 4 \; 1 \; 3] \]
-
-So our polynomial looks like this:
-\[ f(x) = -2x^4+12x^3+4x^2+1x+3 \]
-
-Using the M{\"u}ller's method. We have to implement both MM1 and MM2 versions. We also need to find real roots using the Newton's method and compare these results with what we got from MM2 version of the M{\"u}ller's method.
-\section{Theoretical Introduction}
-M{\"u}ller's method revoles around the idea of approximating the polynomial locally close to the root by a quadratic function. Based on three different points we can use quadratic interpolation and develop our method. This means that we can treat it as a generalization of secant method. That being said we can also realize it in an efficient way if we use just one point. We can use for this case values of polynomial, and its first and second derrivative at current point.
-
-Accordingly there are two versions of M{\"u}ller's method: \textbf{MM1} and \textbf{MM2}.
-
-\subsection{MM1}
-Given three points: $x_0; x_1; x_2$ and their polynomial values: $f(x_0), f(x_1), f(x_2)$ we construct a (quadratic) function passing through these points. Then we find roots of this parabola and we choose one of these rots for the approximation of the result.
-
-For example:
-Assume that $x_2$ is the approximation of the root.
-Let's introduce variable $z$ such that:
-\[ z = x - x_2 \]
-And differences:
-\[ z_0 = x_0 - x_2 \]
-\[ z_1 = x_1 - x_2 \]
-
-We have quadratic function:
-\[ y(z) = az^2 + bz + c \]
-
-Using three points from above we get:
-\[ y(z_0) = az_0^2 + bz_0 + c = f(x_0) \]
-\[ y(z_1) = az_1^2 + bz_1 + c = f(x_1) \]
-\[ y(z_2) = c = f(x_2) \]
-
-And then we get system of equation that we can solve to find $a$ and $b$:
-\[ az_0^2 + bz_0 = f(x_0) - f(x_2) \]
-\[ az_1^2 + bz_1 = f(x_1) - f(x_2) \]
-
-Roots are equal to:
-\[ z_+ = \frac{-2c}{b+\sqrt{b^2 - 4ac}} \]
-\[ z_- = \frac{-2c}{b-\sqrt{b^2 - 4ac}} \]
-
-We choose a root with smaller absolute value for next iteration:
-\[ z_{min} = \min{|z_+, z_-|} \]
-\[ x_3 = x_2 + z_{min} \]
-
-Then we choose new point $x_3$ and two selected from $x_0, x_1, x_2$ which were closer to $x_3$.
-
-This method should also work for $\Delta < 0 $
-
-
-\subsection{MM2}
-This method being numerically more effective is usually recommended.
-We calculate values of a polynomial and its first and second derrivatives at one point.
-
-from definition of quadratic function:
-\[ y(z) = az^2 + bz + c \]
-we can get:
-\[ z = x - x_k \]
-If $z = 0$ then:
-\[ y(0) = c = f(x_k) \]
-\[ y^{'}(0) = b = f^{'}(x_k) \]
-\[ y^{''}(0) = 2a = f^{''}(x_k) \]
-
-We can derive from that formula for roots:
-
-\[ z_{\pm} = \frac{-2f(x_k)}{f^{'}(x_k) \pm \sqrt{ (f^{'}(x_k))^2 - 2f(x_k)f^{''}(x_k)}}\]
-
-Then we choose root with smaller absolute value for next iteration:
-\[ x_{k+1} = x_k + z_{min} \]
-
-Again this method should be implemented in complex number arithmetic.
-This method is locally convergent with order of convergence equal to 1.84. It is locally more effective that secant method and it is almost as fast as Newton's method while being capable of finding complex roots. It can be used to find roots of polynomials or another nonlinear functions.
-
-\section{Results}
-
-\subsection{Graphs for MM1}
-\begin{center}
- \includegraphics[scale=0.25]{task2mm1realoverall.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm1realleft.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm1realright.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm1complexoverall.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm1complexdown.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm1complexmiddle.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm1complexup.eps}
-\end{center}
-
-\subsection{Graphs for MM2}
-\begin{center}
- \includegraphics[scale=0.25]{task2mm2realoverall.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm2realleft.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm2realright.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm2complexoverall.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm2complexright.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm2complexleft.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2mm2complexup.eps}
-\end{center}
-
-\subsection{Tables for MM1}
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & -1.25 & -20.32 \\
-\hline
-2 & -1.0009 & -8.0351 \\
-\hline
-3 & -0.76855 & -1.5512 \\
-\hline
-4 & -0.63496 & 0.58064 \\
-\hline
-5 & -0.67945 & -0.023155 \\
-\hline
-6 & -0.67788 & -0.00010725 \\
-\hline
-7 & -0.67787 & -8.6306e-09 \\
-\hline
-8 & -0.67787 & 0 \\
-\hline
-\hline
-
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 6.25 & 43.43 \\
-\hline
-2 & 6.3257 & 4.4966 \\
-\hline
-3 & 6.3341 & 0.033379 \\
-\hline
-4 & 6.3341 & -1.6916e-06 \\
-\hline
-5 & 6.3341 & -7.1942e-14 \\
-\hline
-
-\hline
-
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 0+0i & 3 \\
-\hline
-2 & -0.0072549-0.12193i & 2.9384 \\
-\hline
-3 & 0.069406-0.45062i & 1.7235 \\
-\hline
-4 & 0.19733-0.61224i & 0.82578 \\
-\hline
-5 & 0.16937-0.56334i & 0.047116 \\
-\hline
-6 & 0.17186-0.56551i & 0.0003142 \\
-\hline
-7 & 0.17188-0.56551i & 4.4741e-08 \\
-\hline
-8 & 0.17188-0.56551i & 2.6645e-15 \\
-\hline
-9 & 0.17188-0.56551i & 0 \\
-\hline
-\hline
-
-\end{tabular}
-\end{center}
-
-\subsection{Tables for MM2}
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & -1.25+0i & -20.32+0i \\
-\hline
-2 & -0.72604-0.25326i & 1.0515-4.0744i \\
-\hline
-3 & -0.68613-0.01483i & -0.11667-0.22303i \\
-\hline
-4 & -0.67788+2.5407e-06i & -0.00010163+3.7123e-05i \\
-\hline
-5 & -0.67787-8.0819e-13i & 1.4105e-11-1.1809e-11i \\
-\hline
- \hline
-
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 6.25 & 43.43 \\
-\hline
-2 & 6.3376 & -1.8647 \\
-\hline
-3 & 6.3341 & 0.0029695 \\
-\hline
-4 & 6.3341 & 1.6294e-08 \\
-\hline
-5 & 6.3341 & -4.6896e-13 \\
-\hline
-\hline
-
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 0+0i & 3 \\
-\hline
-2 & -0.125+0.85696i & 8.0341 \\
-\hline
-3 & 0.16892+0.62593i & 0.94053 \\
-\hline
-4 & 0.17203+0.56536i & 0.0031354 \\
-\hline
-5 & 0.17188+0.56551i & 3.8615e-09 \\
-\hline
-6 & 0.17188+0.56551i & 0 \\
-\hline
-\hline
-
-\end{tabular}
-\end{center}
-
-\subsection{Comparison of results between MM1 and MM2}
-As we can see MM2 method is much better, it took on average around 5 iterations for it to find a root with sufficient accuracy compared to around 7 iterations that MM1 needed to find roots. MM1 is slightly more accurate with at least 10 times better accuary than MM2, there is also a big error in MM2 result which incorrectly denotes a number that should only have real part as an imaginary number. MM1 does not have this problem and shows root -0.67787 correctly. We can also observe that MM1 calculated complex root with a '-' between real and imaginary part and MM2 calculated complex root with a '+' between real and imaginary part. We can assume that in order to get all the complex roots we should use both of the methods.
-
-We can also observe that on graphs with MM2 approaching the root faster than MM1 and MM1 being slightly more accurate.
-\subsection{Comparison of results between Newton's method and MM2}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2newtonoverall.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2newtonleft.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task2newtonright.eps}
-\end{center}
-
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
- 1 & -1.25 & 1.8879 \\
- \hline
- 2 & -0.92681 & -5.52 \\
- \hline
- 3 & -0.74804 & -1.159 \\
- \hline
- 4 & -0.68543 & -0.11186 \\
- \hline
- 5 & -0.67797 & -0.0014548 \\
- \hline
- 6 & -0.67787 & -2.568e-07 \\
- \hline
- 7 & -0.67787 & -7.9936e-15 \\
- \hline
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
- 1 & 6.25 & -0.23707 \\
- \hline
- 2 & 6.3376 & -1.8647 \\
- \hline
- 3 & 6.3341 & -0.0029912 \\
- \hline
- 4 & 6.3341 & -7.7134e-09 \\
- \hline
- 5 & 6.3341 & -7.1942e-14 \\
- \hline
-\end{tabular}
-\end{center}
-
-As we can see Newton method calculated real roots in around the same number of iterations as method MM1, it was slightly slower than MM2. Newton method had pretty good accuracy, comparable to MM1 accuracy.
-
-
-\chapter{Find real and complex roots of the polynomial using Laguerre's method}
-
-\section{Problem}
-We have to find all (real and complex) roots of the polynomial from previous exercise:
-\[ f(x) = -2x^4+12x^3+4x^2+1x+3 \]
-Using the Laguerre's method. Then we should compare those results with the MM2 version of the M{\"u}ller's method.
-
-
-\section{Theoretical Introduction}
-Laguerre's method is defined by a single formula:
-
-\[ x_{k+1} = x_k - \frac{nf(x_k)}{f^{'}(x_k) \pm \sqrt{(n-1)[(n-1)( (f^{'}(x_k))^2 - nf(x_k)f^{''}(x_k) )]}} \]
-Where:
-$n$ - order of the polynomial
-
-This formula is similar to the one from MM2 but also takes order of the polynomial into consideration. In general this method is better. For polynomials with real roots it is globally convergent. It does not have formal analysis for complex roots but it usually shows good numerical properties, although divergence may happen.
-
-\section{Results}
-
-\begin{center}
- \includegraphics[scale=0.25]{task3overall.eps}
-\end{center}
-
-
-\begin{center}
- \includegraphics[scale=0.25]{task3left.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task3right.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task3complexoverall.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task3complexleft.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task3complexright.eps}
-\end{center}
-
-\begin{center}
- \includegraphics[scale=0.25]{task3complexup.eps}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & -1.25 & -20.32 \\
-\hline
-2 & -0.67905 & -0.017268 \\
-\hline
-3 & -0.67787 & -3.1489e-07 \\
-\hline
-4 & -0.67787 & 0 \\
-\hline
-\hline
-\hline
-
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 6.25 & 43.43 \\
-\hline
-2 & 6.3376 & -1.8647 \\
-\hline
-3 & 6.3341 & 0.0029631 \\
-\hline
-4 & 6.3341 & 7.9942e-09\\
-\hline
-5 & 6.3341 & -7.1942e-14\\
-\hline
-
-
-\end{tabular}
-\end{center}
-
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 0+0i & 3 \\
-\hline
-2 & -0.042857+0.71586i & 4.1826 \\
-\hline
-3 & 0.172+0.56266i & 0.040584 \\
-\hline
-4 & 0.17188+0.56551i & 2.8484e-06 \\
-\hline
-5 & 0.17188+0.56551i & 2.2952e-14 \\
-\hline
-6 & 0.17188+0.56551i & 0 \\
-\hline
-
-
-\end{tabular}
-\end{center}
-
-
-\subsection{Comparison of results between Laguerre's method and MM2 method}
-
-\subsubsection{Tables for MM2}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & -1.25+0i & -20.32+0i \\
-\hline
-2 & -0.72604-0.25326i & 1.0515-4.0744i \\
-\hline
-3 & -0.68613-0.01483i & -0.11667-0.22303i \\
-\hline
-4 & -0.67788+2.5407e-06i & -0.00010163+3.7123e-05i \\
-\hline
-5 & -0.67787-8.0819e-13i & 1.4105e-11-1.1809e-11i \\
-\hline
- \hline
-
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 6.25 & 43.43 \\
-\hline
-2 & 6.3376 & -1.8647 \\
-\hline
-3 & 6.3341 & 0.0029695 \\
-\hline
-4 & 6.3341 & 1.6294e-08 \\
-\hline
-5 & 6.3341 & -4.6896e-13 \\
-\hline
-\hline
-
-\end{tabular}
-\end{center}
-
-\begin{center}
- \begin{tabular}{| c c c |}
-\hline
-Iteration & root & f(root) \\
-\hline
-1 & 0+0i & 3 \\
-\hline
-2 & -0.125+0.85696i & 8.0341 \\
-\hline
-3 & 0.16892+0.62593i & 0.94053 \\
-\hline
-4 & 0.17203+0.56536i & 0.0031354 \\
-\hline
-5 & 0.17188+0.56551i & 3.8615e-09 \\
-\hline
-6 & 0.17188+0.56551i & 0 \\
-\hline
-\hline
-
-\end{tabular}
-\end{center}
-
-As expected Laguerre's method reigns supreme, it is:
-\begin{enumerate}
-\item Faster
-With 5 iterations on average compared to around 5.3 for MM2
-\item More accurate
-For real root -0.67787 matlab calculated the value of this function for Laguerre's method as equal to exactly 0 as opposed to around $10^{-11}$ error for MM2.
-\item With no errors
-Laguerre's method did not mistakenly added imaginary part to real root -0.67787 as MM2 did.
-\end{enumerate}
-
-Laguerre's method is faster and more accurate than MM2 which means that we can compare it to faster version of MM1, this means that it is the best method we tested in this exercise.
-
-\chapter{Code appendix}
-
-\section{Task 1}
-
-\subsection{task1Bisection.m}
-
-\subsubsection{Top of task1Bisection.m}
-\begin{simplechar}
-\begin{lstlisting}
-interval = [-5, 10];
-rootBrackets = rootBracketing(@taskFunction, interval(1), interval(2));
-
-printGraph(@taskFunction, 'False Position', @falsePosition, interval, rootBrackets, 'Approximate zeros of function for method of ');
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{taskFunction}
-\begin{simplechar}
-\begin{lstlisting}
-function y = taskFunction(x)
- y = -2.1 + 0.3*x - x*exp(1)^(-x);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{falsePosition}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = falsePosition(taskFunction, a, b, tolerance)
-
- [iterations, lastTwoA, lastTwoB, i] = initialize();
- [zero, iterations, a, b, lastTwoA, lastTwoB] = firstTwoIterations(a, b, taskFunction, iterations, lastTwoA, lastTwoB);
- [zero, iterations] = falsePositionLoop(taskFunction, zero, tolerance, lastTwoA, lastTwoB, i, a, b, iterations);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [iterations, lastTwoA, lastTwoB, i] = initialize()
- iterations = double.empty(2, 0);
- lastTwoA = double.empty(2, 0);
- lastTwoB = double.empty(2, 0);
- i = 0;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{taskFunction}
-\begin{simplechar}
-\begin{lstlisting}
-function y = taskFunction(x)
- y = -2.1 + 0.3*x - x*exp(1)^(-x);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{firstTwoIterations}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations, a, b, lastTwoA, lastTwoB] = firstTwoIterations(a, b, taskFunction, iterations, lastTwoA, lastTwoB)
- for j = 1 : 2
- zero = (a*taskFunction(b) - b * taskFunction(a)) / (taskFunction(b) - taskFunction(a));
- iterations(:, size(iterations, 2) + 1) = [zero, taskFunction(zero)];
- if sign(taskFunction(a)) ~= sign(taskFunction(zero))
- b = zero;
- else
- a = zero;
- end
- lastTwoA(j) = a;
- lastTwoB(j) = b;
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{falsePositionLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = falsePositionLoop(taskFunction, zero, tolerance, lastTwoA, lastTwoB, i, a, b, iterations)
- while abs(taskFunction(zero)) > tolerance
- [lastTwoA, i, a, lastTwoB, b, tolerance, zero, iterations] = insideLoop(lastTwoA, i, a, lastTwoB, b, tolerance, taskFunction, iterations);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{insideLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [lastTwoA, i, a, lastTwoB, b, tolerance, zero, iterations] = insideLoop(lastTwoA, i, a, lastTwoB, b, tolerance, taskFunction, iterations)
- [lastTwoA, lastTwoB] = changeLastTwoAB(lastTwoA, lastTwoB, i, a, b);
- zero = calculateZero(lastTwoB, tolerance, a, b, lastTwoA, taskFunction);
- iterations(:, size(iterations, 2) + 1) = [zero, taskFunction(zero)];
- [a, b] = newSubInterval(taskFunction, a, b, zero);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{changeLastTwoAB}
-\begin{simplechar}
-\begin{lstlisting}
-function [lastTwoA, lastTwoB] = changeLastTwoAB(lastTwoA, lastTwoB, i, a, b)
- lastTwoA(mod(i, 2) + 1) = a;
- lastTwoB(mod(i, 2) + 1) = b;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{calculateZero}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero] = calculateZero(lastTwoB, tolerance, a, b, lastTwoA, taskFunction)
- if(abs(lastTwoB(1) - lastTwoB(2)) < tolerance)
- zero = (a*(taskFunction(b) / 2) - b * taskFunction(a)) / (taskFunction(b) / 2 - taskFunction(a));
- elseif (abs(lastTwoA(1) - lastTwoA(2)) < tolerance)
- zero = (a*taskFunction(b) - b * (taskFunction(a) / 2)) / (taskFunction(b) - (taskFunction(a) / 2));
- else
- zero = (a*taskFunction(b) - b * taskFunction(a)) / (taskFunction(b) - taskFunction(a));
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{newSubInterval}
-\begin{simplechar}
-\begin{lstlisting}
-function [a, b] = newSubInterval(taskFunction, a, b, zero)
- if sign(taskFunction(a)) ~= sign(taskFunction(zero))
- b = zero;
- else
- a = zero;
- end
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-
-
-\subsection{task1Newton.m}
-
-\subsubsection{Top of task1Newton.m}
-\begin{simplechar}
-\begin{lstlisting}
-interval = [-5, 10];
-rootBrackets = rootBracketing(@taskFunction, interval(1), interval(2));
-
-printGraph(@taskFunction, 'Newton', @newtonMethod, interval, rootBrackets, 'Approximate zeros of function for method of ');
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{taskFunction}
-\begin{simplechar}
-\begin{lstlisting}
-function y = taskFunction(x)
- y = -2.1 + 0.3*x - x*exp(1)^(-x);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{newtonMethod}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = newtonMethod(taskFunction, a, b, tolerance)
- [iterations, iteration, zero] = initialize(a, b);
- [zero, iterations] = newtonLoop(iterations, iteration, zero, a, b, tolerance, taskFunction);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [iterations, step, zero] = initialize(a, b)
- iterations = double.empty(2, 0);
- step = sqrt(eps);
- zero = (a + b) / 2;
- iterations(:, size(iterations, 2) + 1) = [zero, taskFunction(zero)];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{newtonLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = newtonLoop(iterations, iteration, zero, a, b, tolerance, taskFunction)
- while abs(taskFunction(zero)) > tolerance
- [zero, iterations] = insideLoop(taskFunction, zero, iteration, iterations, a, b);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{insideLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = insideLoop(taskFunction, zero, iteration, iterations, a, b)
- [zero, iterations] = calculateZeroIterations(taskFunction, zero, iteration, iterations);
- checkForDivergence(zero, a, b);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{calculateZeroIterations}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = calculateZeroIterations(taskFunction, zero, iteration, iterations)
- derivative = (taskFunction(zero + iteration) - taskFunction(zero - iteration)) / (2 * iteration);
- zero = zero - taskFunction(zero) / derivative;
- iterations(:, size(iterations, 2) + 1) = [zero, taskFunction(zero)];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{checkForDivergence}
-\begin{simplechar}
-\begin{lstlisting}
-function checkForDivergence(zero, a, b)
- if zero < a || zero > b
- error('Divergent iteration');
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\section{Task 2}
-
-\subsection{task2MM1.m}
-
-\subsubsection{Top of task2MM1}
-\begin{simplechar}
-\begin{lstlisting}
-interval = [-5, 10];
-rootBrackets = rootBracketing(@polynomial, interval(1), interval(2));
-
-printGraph(@polynomial, 'MM1', @mm1, interval, rootBrackets, 'Approximate zeros of function for method of ');
-
-printComplexGraph(@polynomial, 'MM1', @mm1, [-1 - i, 1 + i], 'Aproximate complex roots of polynomial');
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{polynomial}
-\begin{simplechar}
-\begin{lstlisting}
-function y = polynomial(x)
- y = -2 * x^4 + 12 * x^3 + 4* x^2 + 1 * x + 3;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{mm1}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, iterations] = mm1(polynomial, a, b, tolerance)
- [approximation, approximationValue, iterations] = initialize(a, b, polynomial);
- [approximation, iterations] = mm1Loop(approximation, tolerance, approximationValue, iterations, polynomial);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, approximationValue, iterations] = initialize(a, b, polynomial)
- approximation = [a, b, (a + b) / 2];
- approximationValue = arrayfun(polynomial, approximation);
- iterations = [approximation(3); polynomial(approximation(3))];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{mm1Loop}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, iterations] = mm1Loop(approximation, tolerance, approximationValue, iterations, polynomial)
- while abs(polynomial(approximation(3))) > tolerance
- [approximation, approximationValue, iterations] = insideLoop(approximation, approximationValue, polynomial, iterations);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{insideLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, approximationValue, iterations] = insideLoop(approximation, approximationValue, polynomial, iterations)
- equationsSystem = createEquationSystem(approximation, approximationValue);
- [zPlus, zMinus] = rootsOfQuadraticFormula(equationsSystem, approximationValue);
- [approximation, approximationValue, iterations] = updateApproximations(zPlus, zMinus, approximation, iterations, polynomial);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{createEquationSystem}
-\begin{simplechar}
-\begin{lstlisting}
-function equationsSystem = createEquationSystem(approximation, approximationValue)
- [z0, z1, difference0, difference1] = initializeEquationSystem(approximation, approximationValue);
- equationsSystem = solveEquationSystem(z0, difference0, z1, difference1);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{rootsOfQuadraticFormula}
-\begin{simplechar}
-\begin{lstlisting}
-function [zPlus, zMinus] = rootsOfQuadraticFormula(equationsSystem, approximationValue)
- [a, b, c] = createApproximatedQuadraticFormula(equationsSystem, approximationValue);
- [zPlus, zMinus] = findRootsOfQuadraticFormula(a, b, c);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{updateApproximations}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, approximationValue, iterations] = updateApproximations(zPlus, zMinus, approximation, iterations, polynomial)
- newApproximation = chooseNewRoot(zPlus, zMinus, approximation);
- iterations = addZeroToIterationVector(newApproximation, iterations, polynomial);
- worstApproximationIndex = getWorstApproximationIndex(approximation, newApproximation);
- [approximation, approximationValue] = deleteWorstApproximation(worstApproximationIndex, approximation, polynomial, newApproximation);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{initializeEquationSystem}
-\begin{simplechar}
-\begin{lstlisting}
-function [z0, z1, difference0, difference1] = initializeEquationSystem(approximation, approximationValue)
- z0 = approximation(1) - approximation(3);
- z1 = approximation(2) - approximation(3);
- difference0 = approximationValue(1) - approximationValue(3);
- difference1 = approximationValue(2) - approximationValue(3);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{solveEquationSystem}
-\begin{simplechar}
-\begin{lstlisting}
-function equationsSystem = solveEquationSystem(z0, difference0, z1, difference1)
- equationsSystem = [z0 ^ 2, z0, difference0; z1 ^ 2, z1, difference1];
- reductor = equationsSystem(2, 1) / equationsSystem(1, 1);
- equationsSystem(2, :) = equationsSystem(2, :) - reductor * equationsSystem(1, :);
- equationsSystem(2, 1) = 0;
- equationsSystem(2, :) = equationsSystem(2, :) ./ equationsSystem(2, 2);
- equationsSystem(1, :) = equationsSystem(1, :) - equationsSystem(1, 2) * equationsSystem(2, :);
- equationsSystem(1, :) = equationsSystem(1, :) ./ equationsSystem(1, 1);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{createApproximatedQuadraticFormula}
-\begin{simplechar}
-\begin{lstlisting}
-function [a, b, c] = createApproximatedQuadraticFormula(equationsSystem, approximationValue)
- a = equationsSystem(1, 3);
- b = equationsSystem(2, 3);
- c = approximationValue(3);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{findRootsOfQuadraticFormula}
-\begin{simplechar}
-\begin{lstlisting}
-function [zPlus, zMinus] = findRootsOfQuadraticFormula(a, b, c)
- zPlus = -2 * c / (b + sqrt(b ^ 2 - 4 * a * c));
- zMinus = -2 * c / (b - sqrt(b ^ 2 - 4 * a * c));
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{chooseNewRoot}
-\begin{simplechar}
-\begin{lstlisting}
-function newApproximation = chooseNewRoot(zPlus, zMinus, approximation)
- if abs(zPlus) < abs(zMinus)
- newApproximation = approximation(3) + zPlus;
- else
- newApproximation = approximation(3) + zMinus;
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{addZeroToIterationVector}
-\begin{simplechar}
-\begin{lstlisting}
-function iterations = addZeroToIterationVector(newApproximation, iterations, polynomial)
- zero = newApproximation;
- iterations(:, size(iterations, 2) + 1) = [zero, polynomial(zero)];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{getWorstApproximationIndex}
-\begin{simplechar}
-\begin{lstlisting}
-function worstApproximationIndex = getWorstApproximationIndex(approximation, newApproximation)
- worstApproximationIndex = -1;
- worstApproximationDifference = 0;
- for i = 1:size(approximation, 2)
- diff = abs(approximation(i) - newApproximation);
- if diff > worstApproximationDifference
- worstApproximationIndex = i;
- worstApproximationDifference = diff;
- end
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{deleteWorstApproximation}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, approximationValue] = deleteWorstApproximation(worstApproximationIndex, approximation, polynomial, newApproximation)
- approximation(worstApproximationIndex) = [];
- approximation(3) = newApproximation;
- approximationValue = arrayfun(polynomial, approximation);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{task2MM2.m}
-
-
-\subsubsection{top of task2MM2.m}
-\begin{simplechar}
-\begin{lstlisting}
-interval = [-5, 10];
-rootBrackets = rootBracketing(@polynomial, interval(1), interval(2));
-
-printGraph(@polynomial, 'MM2', @mm2, interval, rootBrackets, 'Approximate zeros of function for method of ');
-
-printComplexGraph(@polynomial, 'MM2', @mm2, [-1 - i, 1 + i], 'Aproximate complex roots of polynomial');
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{polynomial}
-\begin{simplechar}
-\begin{lstlisting}
-function y = polynomial(x)
- y = -2 * x^4 + 12 * x^3 + 4* x^2 + 1 * x + 3;
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{mm2}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, iterations] = mm2(polynomial, a, b, tolerance)
- [approximation, iterations] = initialize(a, b, polynomial);
- [approximation, iterations] = mm2Loop(approximation, iterations, polynomial, tolerance);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, iterations] = initialize(a, b, polynomial)
- approximation = (a + b) / 2;
- iterations = [approximation; polynomial(approximation)];
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{mm2Loop}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, iterations] = mm2Loop(approximation, iterations, polynomial, tolerance)
- while abs(polynomial(approximation)) > tolerance
- [approximation, iterations] = insideLoop(approximation, polynomial, iterations);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{insideLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, iterations] = insideLoop(approximation, polynomial, iterations)
- [a, b, c] = getABC(approximation, polynomial);
- [zPlus, zMinus] = findRoots(a, b, c);
- newApproximation = chooseNewApproximation(zPlus, zMinus, approximation);
- [approximation, iterations] = updateApproximations(newApproximation, iterations, polynomial);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{getABC}
-\begin{simplechar}
-\begin{lstlisting}
-function [a, b, c] = getABC(approximation, polynomial)
- c = polynomial(approximation);
- b = derivative(polynomial, approximation, 1);
- a = derivative(polynomial, approximation, 2) / 2;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{findRoots}
-\begin{simplechar}
-\begin{lstlisting}
-function [zPlus, zMinus] = findRoots(a, b, c)
- zPlus = -2 * c / (b + sqrt(b ^ 2 - 4 * a * c));
- zMinus = -2 * c / (b - sqrt(b ^ 2 - 4 * a * c));
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{chooseNewApproximation}
-\begin{simplechar}
-\begin{lstlisting}
-function newApproximation = chooseNewApproximation(zPlus, zMinus, approximation)
- if abs(zPlus) < abs(zMinus)
- newApproximation = approximation + zPlus;
- else
- newApproximation = approximation + zMinus;
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{updateApproximations}
-\begin{simplechar}
-\begin{lstlisting}
-function [approximation, iterations] = updateApproximations(newApproximation, iterations, polynomial)
- approximation = newApproximation;
- iterations(:, size(iterations, 2) + 1) = [approximation, polynomial(approximation)];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{derivative}
-\begin{simplechar}
-\begin{lstlisting}
-function y = derivative(function_, x, degree)
- if degree == 0
- y = function_(x);
- return
- end
-
- step = sqrt(eps);
- y = (derivative(function_, x + step, degree - 1) - derivative(function_, x - step, degree - 1)) / (2 * step);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\section{Task 3}
-
-\subsubsection{Top of Task 3}
-\begin{simplechar}
-\begin{lstlisting}
-interval = [-5, 10];
-rootBrackets = rootBracketing(@polynomial, interval(1), interval(2));
-
-printGraph(@polynomial, 'Laguerre', @laguerre, interval, rootBrackets, 'Approximate zeros of function for method of ');
-
-printComplexGraph(@polynomial, 'Laguerre', @laguerre, [-1 - i, 1 + i], 'Aproximate complex roots of polynomial');
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{polynomial}
-\begin{simplechar}
-\begin{lstlisting}
-function y = polynomial(x)
- y = -2 * x^4 + 12 * x^3 + 4* x^2 + 1 * x + 3;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{laguerre}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = laguerre(polynomial, a, b, tolerance)
- [degree, zero, iterations] = initialize(a, b, polynomial);
- [zero, iterations] = laguerreLoop(polynomial, zero, tolerance, iterations, degree);
-
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [degree, zero, iterations] = initialize(a, b, polynomial)
- degree = 4;
- zero = (a + b) / 2;
- iterations = [zero; polynomial(zero)];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{laguerreLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = laguerreLoop(polynomial, zero, tolerance, iterations, degree)
- while abs(polynomial(zero)) > tolerance
- [iterations, zero] = insideLoop(polynomial, zero, degree, iterations);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{insideLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [iterations, zero] = insideLoop(polynomial, zero, degree, iterations)
- [derrivative0, derrivative1, derrivative2] = calculateDerrivatives(polynomial, zero);
- [zPlus, zMinus] = calculateZ(degree, derrivative0, derrivative1, derrivative2);
- newZero = chooseNewZero(zPlus, zMinus, zero);
- [zero, iterations] = updateZeros(newZero, iterations, polynomial);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{calculateDerrivatives}
-\begin{simplechar}
-\begin{lstlisting}
-function [derrivative0, derrivative1, derrivative2] = calculateDerrivatives(polynomial, zero)
- derrivative0 = polynomial(zero);
- derrivative1 = derivative(polynomial, zero, 1);
- derrivative2 = derivative(polynomial, zero, 2);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{calculateZ}
-\begin{simplechar}
-\begin{lstlisting}
-function [zPlus, zMinus] = calculateZ(degree, derrivative0, derrivative1, derrivative2)
- expressionUnderSquareRoot = (degree - 1) * ((degree - 1) * derrivative1 ^ 2 - degree * derrivative0 * derrivative2);
- lagsqrt = sqrt(expressionUnderSquareRoot);
-
- zPlus = degree * derrivative0 / (derrivative1 + lagsqrt);
- zMinus = degree * derrivative0 / (derrivative1 - lagsqrt);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsubsection{chooseNewZero}
-\begin{simplechar}
-\begin{lstlisting}
-function newZero = chooseNewZero(zPlus, zMinus, zero)
- if abs(zPlus) < abs(zMinus)
- newZero = zero - zPlus;
- else
- newZero = zero - zMinus;
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{updateZeros}
-\begin{simplechar}
-\begin{lstlisting}
-function [zero, iterations] = updateZeros(newZero, iterations, polynomial)
- zero = newZero;
- iterations(:, size(iterations, 2) + 1) = [zero, polynomial(zero)];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{rootBrackering.m}
-
-\subsubsection{updateZeros}
-\begin{simplechar}
-\begin{lstlisting}
-% find the root brackets of a function within the given range
-function rootBrackets = rootBracketing(givenFunction, intervalLeft, intervalRight)
- [a, b, rootBrackets, resolution] = initializeValues(intervalLeft, intervalRight);
- rootBrackets = bracketingLoop(a, b, rootBrackets, intervalRight, resolution, givenFunction);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{initializeValues}
-\begin{simplechar}
-\begin{lstlisting}
-function [a, b, rootBrackets, resolution] = initializeValues(intervalLeft, intervalRight)
- % define search resolution
- resolution = (intervalRight - intervalLeft) / 6;
- % The higher the value of denominator the less iterations will it take
- % to reach the roots, however in order to have nice graph showing those
- % brackets I will choose relatively small denominator - I have choosen
- % the smallest natural number that still generates brackets on a graph
-
- % start search at the start of the range
- a = intervalLeft;
- b = intervalLeft + resolution;
- rootBrackets = double.empty(2, 0); % initialize empty vector of size 2
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsubsection{bracketingLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function rootBrackets = bracketingLoop(a, b, rootBrackets, intervalRight, resolution, givenFunction)
- while b ~= intervalRight % if the bracket can't be expanded end loop
- % if the function changes sign inside the interval that means that we passed through a root that means that a bracket has been found
- if sign(givenFunction(a)) ~= sign(givenFunction(b))
- % save bracket
- rootBrackets(:, size(rootBrackets, 2) + 1) = [a, b]; % Add the new bracket to existing ones
- end
- % check next bracket
- a = b;
- b = min(a + resolution, intervalRight);
- % Once a + resolution > intervalRight, then we will know that we
- % reached beyond the interval and we must stop
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{printGraph.m}
-\begin{simplechar}
-\begin{lstlisting}
-% graph the real roots of a function
-function printGraph(taskFunction, algorithmName, algorithm, interval, rootBrackets, plotTitle)
- figure()
- grid on; % Get y values lines
- hold on; % Retain current plot when adding new plots
- title([plotTitle, algorithmName]);
- set(gca, 'XAxisLocation', 'origin'); % Set properties of current axis
- x = interval(1):0.01:interval(2);
- % x is a vector of values between left and right interval with every value being higher by 0.01
- y = arrayfun(taskFunction, x); % We sketch the function from task for each x
- plot(x, y);
-
- % iterate over rootBrackets and add them to the plot
- for rootBracket = rootBrackets
- % find all zeros within the bracket using the given algorithm
- % Get all steps from the algorithm we use
- [~, steps] = algorithm(taskFunction, rootBracket(1), rootBracket(2), 1e-10);
-
- firstStepColor = [1 0 0]; % Red
- otherStepsColor = [0 1 0]; % Green
- % plot first steps
- scatter(steps(1, 1), steps(2, 1), [], firstStepColor);
- text(steps(1, 1), steps(2, 1), 'firstStep', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top'); % It makes text appear neatly
- % plot other steps
- scatter(steps(1, 2:end), steps(2, 2:end), [], otherStepsColor);
-
-
-
- % print root table
- disp([plotTitle, ' (', algorithmName, ')']);
- columns = {'step', 'root', 'value at root'};
- disp(table((1:size(steps, 2))', steps(1, :)', steps(2, :)', 'VariableNames', columns));
- end
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\newpage
-\subsection{printComplexGraph.m}
-\begin{simplechar}
-\begin{lstlisting}
-% graph the complex roots of a function
-function printComplexGraph(printComplexGraph, algorithmName, algorithm, rootBrackets, plottitle)
- figure();
- grid on; % Get y values lines
- hold on; % Retain current plot when adding new plots
- title([plottitle, algorithmName]);
- xlabel("Real part");
- ylabel("Imaginary part");
- set(gca, 'XAxisLocation', 'origin'); % Set properties of current axis
-
- % find all zeros within the bracket using the given algorithm
- [~, steps] = algorithm(printComplexGraph, rootBrackets(1), rootBrackets(2), 1e-15);
-
- % plot first step
- text(real(steps(1, 1)), imag(steps(1, 1)), 'start', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top');
-
- % plot steps on graph
- plot(real(steps(1, :)), imag(steps(1, :)), '-x');
-
- % plot last step
- text(real(steps(1, end)), imag(steps(1, end)), 'end', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top');
-
-
- % print root table
- disp([plottitle, ' (', algorithmName, ')']);
- columns = {'step', 'root', 'abs value at root'};
- disp(table([1:size(steps, 2)]', steps(1, :)', abs(steps(2, :))', 'VariableNames', columns));
-end
-\end{lstlisting}
-\end{simplechar}
-
-
-\begin{thebibliography}{9}
-\bibitem{texbook}
-Piotr Tatjewski (2014) \emph{Numerical Methods}, Oficyna Wydawnicza Politechniki Warszawskiej
-\end{thebibliography}
-
-
+ \input{sections/01-a-false-position-method}
+ \input{sections/02-b-the-newton-s-method}
+ \input{sections/03-problem}
+ \input{sections/04-theoretical-introduction}
+ \input{sections/05-results}
+ \input{sections/06-problem}
+ \input{sections/07-theoretical-introduction}
+ \input{sections/08-results}
+ \input{sections/09-task-1}
+ \input{sections/10-task-2}
+ \input{sections/11-task-3}
\end{document}
diff --git a/NotProgramming/ENUME/projectB/Report/sections/01-a-false-position-method.tex b/NotProgramming/ENUME/projectB/Report/sections/01-a-false-position-method.tex
new file mode 100644
index 00000000..cc6e0faf
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/01-a-false-position-method.tex
@@ -0,0 +1,151 @@
+\section{a) False position method}
+
+\subsection{Problem}
+
+We have to find zeros of the function
+\[ f(x) = -2.1 + 0.3x - xe^{-x} \]
+In the interval $[-5; 10]$ using false position method.
+
+\subsection{Theoretical Introduction}
+\emph{False position} method also called \emph{regula falsi} in fancier circles is similar to the bisection method, the difference is that the interval we use $[a_n, b_n]$ is divided into two subintervals. We have:
+\begin{itemize}
+\item $\alpha$ - The root
+\item $a_n$ - 'left' interval
+\item $b_n$ - 'right' interval
+\item $f(a_n)$ - Value at left interval
+\item $f(b_n)$ - Value at right interval
+\end{itemize}
+
+We get:
+\[ \frac{f(b_n) - f(a_n)}{b_n - a_n} = \frac{f(b_n) - 0}{b_n - c_n} \]
+From which we get:
+\[ c_n = b_n - \frac{f(b_n)(b_n - a_n)}{f(b_n) - f(a_n)} = \frac{a_nf(b_n) - b_n f(a_n)}{f(b_n)-f(a_n)} \]
+
+Then we choose next interval as in the bisection method so: we calculate products of function values at $a_n$ and $b_n$ and that subinterval is selected for the next iteration of \emph{false position} method. This subinterval corresponds to the negative product value.
+
+\subsubsection{Properties of \emph{false position method}}
+This method is always convergent, simillary to bisection method, since it will always choose and shorten the interval which contains the root. If the function is continous and differentiable the method is linearly convergent. That being said the convergence may become sluggish. It can happen if for example one of the endpoints of the intervals will remain the same and the iterating will not shorten the interval to 0. One of the examples of functions that lead to that are barrier functions used in constrained optimization methods.
+
+\paragraph{Improvement to the method}
+In order to improve the formula and avoid aforementioned situation we can take smaller value of the function for the value that does not change.
+For right end:
+\[ c_n = \frac{a_n\frac{f(b_n)}{2} - b_nf(a_n)}{\frac{f(b_n)}{2} - f(a_n)} \]
+And for left end:
+\[ c_n = \frac{a_nf(b_n) - b_n\frac{f(a_n)}{2}}{f(b_n)- \frac{f(a_n)}{2}} \]
+
+This is called \emph{modified regula falsi} or \emph{Illinois algorithm}.
+It is superlinearly convergent, globally convergent and length of intervals we get in each iterations converges to zero.
+\subsection{Results}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task1falsepositionoverall.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task1falsepositionzommedleft.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task1falsepositionzommedright.eps}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & -0.17673 &-1.9421 \\
+\hline
+2 & -0.32943 &-1.7409 \\
+\hline
+3 & -0.39578 &-1.6308 \\
+\hline
+4 &-0.61812 &-1.1386 \\
+\hline
+5 &-0.76152 &-0.69765 \\
+\hline
+6 &-0.84516 &-0.38573 \\
+\hline
+7 &-0.89015 &-0.19911 \\
+\hline
+8 &-0.91304 &-0.098733 \\
+\hline
+9 & -0.92431 &-0.047922 \\
+\hline
+10 & -0.92976 & -0.02301 \\
+\hline
+11 &-0.93237 & -0.01099 \\
+\hline
+12 &-0.93362 &-0.005236 \\
+\hline
+13 &-0.93421 &-0.0024915 \\
+\hline
+14 &-0.9345 &-0.0011848 \\
+\hline
+15 &-0.93463 &-0.0005633 \\
+\hline
+16 &-0.93469 &-0.00026777 \\
+\hline
+17 &-0.93473 &-0.00012728 \\
+\hline
+18 &-0.93474 &-6.0499e-05 \\
+\hline
+19 &-0.93475 &-2.8756e-05 \\
+\hline
+20 &-0.93475 & -1.3668e-05 \\
+\hline
+21 &-0.93475 & -6.4964e-06 \\
+\hline
+22 &-0.93475 & -3.0878e-06 \\
+\hline
+23 &-0.93475 & -1.4676e-06 \\
+\hline
+24 &-0.93475 & -6.9758e-07 \\
+\hline
+25 &-0.93475 & -3.3157e-07 \\
+\hline
+26 &-0.93475 & -1.5759e-07 \\
+\hline
+27 &-0.93475 & -7.4906e-08 \\
+\hline
+28 &-0.93475 & -3.5603e-08 \\
+\hline
+29 &-0.93475 & -1.6922e-08 \\
+\hline
+30 &-0.93475 & -8.0433e-09 \\
+\hline
+31 &-0.93475 & -3.823e-09 \\
+\hline
+32 &-0.93475 & -1.8171e-09 \\
+\hline
+33 &-0.93475 & -8.6368e-10 \\
+\hline
+34 &-0.93475 & -4.1051e-10 \\
+\hline
+35 &-0.93475 & -1.9512e-10 \\
+\hline
+36 &-0.93475 & -9.2741e-11 \\
+\hline
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 7.0323 & 0.0034663 \\
+\hline
+2 & 7.0212 & 9.0344e-05 \\
+\hline
+3 & 7.0211 & 4.6349e-05 \\
+\hline
+4 & 7.0208 & -4.3921e-05 \\
+\hline
+5 & 7.0209 & 4.8939e-11 \\
+\hline
+
+\hline
+\end{tabular}
+\end{center}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/02-b-the-newton-s-method.tex b/NotProgramming/ENUME/projectB/Report/sections/02-b-the-newton-s-method.tex
new file mode 100644
index 00000000..801fa072
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/02-b-the-newton-s-method.tex
@@ -0,0 +1,93 @@
+\section{b) the Newton's method}
+
+
+\subsection{Problem}
+
+We have to find zeros of the function
+\[ f(x) = -2.1 + 0.3x - xe^{-x} \]
+In the interval $[-5; 10]$
+
+using the Newton's method
+\subsection{Theoretical Introduction}
+\emph{The Newton's method} also called \emph{the tangent method} relies on first order part of its expansion into Taylor series for a given current approximation of root.
+\[ f(x) \approx f(x_n) + f^{'}(x_n)(x-x_n) \]
+Then we obtain the next point $x_{x+1}$ by finding root of linear function:
+\[ f(x_n) + f^{'}(x_n)(x_{n+1}-x_n) = 0 \]
+From this we get formula for $x_{n+1}$:
+\[ x_{n+1} = x_n - \frac{f(x_n)}{f^{'}(x_n)} \]
+
+This method as opposed to \emph{regula falsi} method is locally convergent, should we choose initial point too far from the root (area which is close enough to root is called set of attraction) then we can get a divergence. On the other side if the Newton's method will converge then it is quite rapid with convergence of order p = 2 - quadratic convergence.
+
+Newton's method is also effective if the function derrivative is far from zero, so the slope of the function is steep, conversely if the derrivative is close to zero the method is not recommended.
+\subsection{Results}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task1Newtonoverall.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task1Newtonzommedleft.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task1Newtonzommedright.eps}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & -1.25 & 1.8879 \\
+\hline
+2 & -1.0001 & 0.31855 \\
+\hline
+3 & -0.93804 & 0.015256 \\
+\hline
+4 & -0.93476 & 4.0314e-05 \\
+\hline
+5 & -0.93475 & 2.8356e-10 \\
+\hline
+6 & -0.93475 & 0 \\
+\hline
+\hline
+
+\hline
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 6.25 & -0.23707 \\
+\hline
+2 & 7.0144 & -0.0019866 \\
+\hline
+3 & 7.0209 & -9.517e-08 \\
+\hline
+4 &7.0209 & 7.468e-16 \\
+\hline
+\hline
+
+\hline
+\end{tabular}
+\end{center}
+
+\subsection{Discussion of results}
+As we can see and as we could expect from theory Newton method reigns supreme.
+It is:
+\begin{enumerate}
+\item Faster.
+Especially for finding first root. It took 36 iterations for false position method to find first root with accuary up to $10^{-10}$ and it took only 6 iterations for the Newton method.
+\item More accurate
+Not only that we also got more accurate results with Newton method! With first root being so close to the real answer that the matlab calculated the value of this function at this point as exactly equal to 0. For second root the accuary is $10^{6}$ better than for the false position method.
+\item Smaller gaps
+Looking at graphs we got from both method we can clearly see that the gaps between the final result and each and every step are much smaller for Newton method. This again proves that it is faster and more accurate compared to false position method.
+\end{enumerate}
+
+
+
+\chapter{Find real and complex roots of the polynomial}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/03-problem.tex b/NotProgramming/ENUME/projectB/Report/sections/03-problem.tex
new file mode 100644
index 00000000..eaccbceb
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/03-problem.tex
@@ -0,0 +1,12 @@
+\section{Problem}
+
+We have to find all real and complex roots of the polynomial:
+
+\[ f(x) = a_4x^4+a_3x^3+a_2x^2+a_1x+a_0 \]
+where:
+\[ [a_4 \; a_3 \; a_2 \; a_1 \; a_0] = [-2 \; 12 \; 4 \; 1 \; 3] \]
+
+So our polynomial looks like this:
+\[ f(x) = -2x^4+12x^3+4x^2+1x+3 \]
+
+Using the M{\"u}ller's method. We have to implement both MM1 and MM2 versions. We also need to find real roots using the Newton's method and compare these results with what we got from MM2 version of the M{\"u}ller's method.
diff --git a/NotProgramming/ENUME/projectB/Report/sections/04-theoretical-introduction.tex b/NotProgramming/ENUME/projectB/Report/sections/04-theoretical-introduction.tex
new file mode 100644
index 00000000..338d8379
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/04-theoretical-introduction.tex
@@ -0,0 +1,64 @@
+\section{Theoretical Introduction}
+M{\"u}ller's method revoles around the idea of approximating the polynomial locally close to the root by a quadratic function. Based on three different points we can use quadratic interpolation and develop our method. This means that we can treat it as a generalization of secant method. That being said we can also realize it in an efficient way if we use just one point. We can use for this case values of polynomial, and its first and second derrivative at current point.
+
+Accordingly there are two versions of M{\"u}ller's method: \textbf{MM1} and \textbf{MM2}.
+
+\subsection{MM1}
+Given three points: $x_0; x_1; x_2$ and their polynomial values: $f(x_0), f(x_1), f(x_2)$ we construct a (quadratic) function passing through these points. Then we find roots of this parabola and we choose one of these rots for the approximation of the result.
+
+For example:
+Assume that $x_2$ is the approximation of the root.
+Let's introduce variable $z$ such that:
+\[ z = x - x_2 \]
+And differences:
+\[ z_0 = x_0 - x_2 \]
+\[ z_1 = x_1 - x_2 \]
+
+We have quadratic function:
+\[ y(z) = az^2 + bz + c \]
+
+Using three points from above we get:
+\[ y(z_0) = az_0^2 + bz_0 + c = f(x_0) \]
+\[ y(z_1) = az_1^2 + bz_1 + c = f(x_1) \]
+\[ y(z_2) = c = f(x_2) \]
+
+And then we get system of equation that we can solve to find $a$ and $b$:
+\[ az_0^2 + bz_0 = f(x_0) - f(x_2) \]
+\[ az_1^2 + bz_1 = f(x_1) - f(x_2) \]
+
+Roots are equal to:
+\[ z_+ = \frac{-2c}{b+\sqrt{b^2 - 4ac}} \]
+\[ z_- = \frac{-2c}{b-\sqrt{b^2 - 4ac}} \]
+
+We choose a root with smaller absolute value for next iteration:
+\[ z_{min} = \min{|z_+, z_-|} \]
+\[ x_3 = x_2 + z_{min} \]
+
+Then we choose new point $x_3$ and two selected from $x_0, x_1, x_2$ which were closer to $x_3$.
+
+This method should also work for $\Delta < 0 $
+
+
+\subsection{MM2}
+This method being numerically more effective is usually recommended.
+We calculate values of a polynomial and its first and second derrivatives at one point.
+
+from definition of quadratic function:
+\[ y(z) = az^2 + bz + c \]
+we can get:
+\[ z = x - x_k \]
+If $z = 0$ then:
+\[ y(0) = c = f(x_k) \]
+\[ y^{'}(0) = b = f^{'}(x_k) \]
+\[ y^{''}(0) = 2a = f^{''}(x_k) \]
+
+We can derive from that formula for roots:
+
+\[ z_{\pm} = \frac{-2f(x_k)}{f^{'}(x_k) \pm \sqrt{ (f^{'}(x_k))^2 - 2f(x_k)f^{''}(x_k)}}\]
+
+Then we choose root with smaller absolute value for next iteration:
+\[ x_{k+1} = x_k + z_{min} \]
+
+Again this method should be implemented in complex number arithmetic.
+This method is locally convergent with order of convergence equal to 1.84. It is locally more effective that secant method and it is almost as fast as Newton's method while being capable of finding complex roots. It can be used to find roots of polynomials or another nonlinear functions.
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/05-results.tex b/NotProgramming/ENUME/projectB/Report/sections/05-results.tex
new file mode 100644
index 00000000..52303782
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/05-results.tex
@@ -0,0 +1,8 @@
+\section{Results}
+
+ \input{sections/05-results/01-graphs-for-mm1}
+ \input{sections/05-results/02-graphs-for-mm2}
+ \input{sections/05-results/03-tables-for-mm1}
+ \input{sections/05-results/04-tables-for-mm2}
+ \input{sections/05-results/05-comparison-of-results-between-mm1-and}
+ \input{sections/05-results/06-comparison-of-results-between-newton-s}
diff --git a/NotProgramming/ENUME/projectB/Report/sections/05-results/01-graphs-for-mm1.tex b/NotProgramming/ENUME/projectB/Report/sections/05-results/01-graphs-for-mm1.tex
new file mode 100644
index 00000000..add42a5e
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/05-results/01-graphs-for-mm1.tex
@@ -0,0 +1,29 @@
+\subsection{Graphs for MM1}
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm1realoverall.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm1realleft.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm1realright.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm1complexoverall.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm1complexdown.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm1complexmiddle.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm1complexup.eps}
+\end{center}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/05-results/02-graphs-for-mm2.tex b/NotProgramming/ENUME/projectB/Report/sections/05-results/02-graphs-for-mm2.tex
new file mode 100644
index 00000000..b6eb7aaf
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/05-results/02-graphs-for-mm2.tex
@@ -0,0 +1,29 @@
+\subsection{Graphs for MM2}
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm2realoverall.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm2realleft.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm2realright.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm2complexoverall.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm2complexright.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm2complexleft.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2mm2complexup.eps}
+\end{center}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/05-results/03-tables-for-mm1.tex b/NotProgramming/ENUME/projectB/Report/sections/05-results/03-tables-for-mm1.tex
new file mode 100644
index 00000000..bba4c30f
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/05-results/03-tables-for-mm1.tex
@@ -0,0 +1,76 @@
+\subsection{Tables for MM1}
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & -1.25 & -20.32 \\
+\hline
+2 & -1.0009 & -8.0351 \\
+\hline
+3 & -0.76855 & -1.5512 \\
+\hline
+4 & -0.63496 & 0.58064 \\
+\hline
+5 & -0.67945 & -0.023155 \\
+\hline
+6 & -0.67788 & -0.00010725 \\
+\hline
+7 & -0.67787 & -8.6306e-09 \\
+\hline
+8 & -0.67787 & 0 \\
+\hline
+\hline
+
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 6.25 & 43.43 \\
+\hline
+2 & 6.3257 & 4.4966 \\
+\hline
+3 & 6.3341 & 0.033379 \\
+\hline
+4 & 6.3341 & -1.6916e-06 \\
+\hline
+5 & 6.3341 & -7.1942e-14 \\
+\hline
+
+\hline
+
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 0+0i & 3 \\
+\hline
+2 & -0.0072549-0.12193i & 2.9384 \\
+\hline
+3 & 0.069406-0.45062i & 1.7235 \\
+\hline
+4 & 0.19733-0.61224i & 0.82578 \\
+\hline
+5 & 0.16937-0.56334i & 0.047116 \\
+\hline
+6 & 0.17186-0.56551i & 0.0003142 \\
+\hline
+7 & 0.17188-0.56551i & 4.4741e-08 \\
+\hline
+8 & 0.17188-0.56551i & 2.6645e-15 \\
+\hline
+9 & 0.17188-0.56551i & 0 \\
+\hline
+\hline
+
+\end{tabular}
+\end{center}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/05-results/04-tables-for-mm2.tex b/NotProgramming/ENUME/projectB/Report/sections/05-results/04-tables-for-mm2.tex
new file mode 100644
index 00000000..e389ee9f
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/05-results/04-tables-for-mm2.tex
@@ -0,0 +1,63 @@
+\subsection{Tables for MM2}
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & -1.25+0i & -20.32+0i \\
+\hline
+2 & -0.72604-0.25326i & 1.0515-4.0744i \\
+\hline
+3 & -0.68613-0.01483i & -0.11667-0.22303i \\
+\hline
+4 & -0.67788+2.5407e-06i & -0.00010163+3.7123e-05i \\
+\hline
+5 & -0.67787-8.0819e-13i & 1.4105e-11-1.1809e-11i \\
+\hline
+ \hline
+
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 6.25 & 43.43 \\
+\hline
+2 & 6.3376 & -1.8647 \\
+\hline
+3 & 6.3341 & 0.0029695 \\
+\hline
+4 & 6.3341 & 1.6294e-08 \\
+\hline
+5 & 6.3341 & -4.6896e-13 \\
+\hline
+\hline
+
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 0+0i & 3 \\
+\hline
+2 & -0.125+0.85696i & 8.0341 \\
+\hline
+3 & 0.16892+0.62593i & 0.94053 \\
+\hline
+4 & 0.17203+0.56536i & 0.0031354 \\
+\hline
+5 & 0.17188+0.56551i & 3.8615e-09 \\
+\hline
+6 & 0.17188+0.56551i & 0 \\
+\hline
+\hline
+
+\end{tabular}
+\end{center}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/05-results/05-comparison-of-results-between-mm1-and.tex b/NotProgramming/ENUME/projectB/Report/sections/05-results/05-comparison-of-results-between-mm1-and.tex
new file mode 100644
index 00000000..ee209bbf
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/05-results/05-comparison-of-results-between-mm1-and.tex
@@ -0,0 +1,4 @@
+\subsection{Comparison of results between MM1 and MM2}
+As we can see MM2 method is much better, it took on average around 5 iterations for it to find a root with sufficient accuracy compared to around 7 iterations that MM1 needed to find roots. MM1 is slightly more accurate with at least 10 times better accuary than MM2, there is also a big error in MM2 result which incorrectly denotes a number that should only have real part as an imaginary number. MM1 does not have this problem and shows root -0.67787 correctly. We can also observe that MM1 calculated complex root with a '-' between real and imaginary part and MM2 calculated complex root with a '+' between real and imaginary part. We can assume that in order to get all the complex roots we should use both of the methods.
+
+We can also observe that on graphs with MM2 approaching the root faster than MM1 and MM1 being slightly more accurate.
diff --git a/NotProgramming/ENUME/projectB/Report/sections/05-results/06-comparison-of-results-between-newton-s.tex b/NotProgramming/ENUME/projectB/Report/sections/05-results/06-comparison-of-results-between-newton-s.tex
new file mode 100644
index 00000000..255b61e0
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/05-results/06-comparison-of-results-between-newton-s.tex
@@ -0,0 +1,60 @@
+\subsection{Comparison of results between Newton's method and MM2}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2newtonoverall.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2newtonleft.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task2newtonright.eps}
+\end{center}
+
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+ 1 & -1.25 & 1.8879 \\
+ \hline
+ 2 & -0.92681 & -5.52 \\
+ \hline
+ 3 & -0.74804 & -1.159 \\
+ \hline
+ 4 & -0.68543 & -0.11186 \\
+ \hline
+ 5 & -0.67797 & -0.0014548 \\
+ \hline
+ 6 & -0.67787 & -2.568e-07 \\
+ \hline
+ 7 & -0.67787 & -7.9936e-15 \\
+ \hline
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+ 1 & 6.25 & -0.23707 \\
+ \hline
+ 2 & 6.3376 & -1.8647 \\
+ \hline
+ 3 & 6.3341 & -0.0029912 \\
+ \hline
+ 4 & 6.3341 & -7.7134e-09 \\
+ \hline
+ 5 & 6.3341 & -7.1942e-14 \\
+ \hline
+\end{tabular}
+\end{center}
+
+As we can see Newton method calculated real roots in around the same number of iterations as method MM1, it was slightly slower than MM2. Newton method had pretty good accuracy, comparable to MM1 accuracy.
+
+
+\chapter{Find real and complex roots of the polynomial using Laguerre's method}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/06-problem.tex b/NotProgramming/ENUME/projectB/Report/sections/06-problem.tex
new file mode 100644
index 00000000..c733128f
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/06-problem.tex
@@ -0,0 +1,6 @@
+\section{Problem}
+We have to find all (real and complex) roots of the polynomial from previous exercise:
+\[ f(x) = -2x^4+12x^3+4x^2+1x+3 \]
+Using the Laguerre's method. Then we should compare those results with the MM2 version of the M{\"u}ller's method.
+
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/07-theoretical-introduction.tex b/NotProgramming/ENUME/projectB/Report/sections/07-theoretical-introduction.tex
new file mode 100644
index 00000000..47642450
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/07-theoretical-introduction.tex
@@ -0,0 +1,9 @@
+\section{Theoretical Introduction}
+Laguerre's method is defined by a single formula:
+
+\[ x_{k+1} = x_k - \frac{nf(x_k)}{f^{'}(x_k) \pm \sqrt{(n-1)[(n-1)( (f^{'}(x_k))^2 - nf(x_k)f^{''}(x_k) )]}} \]
+Where:
+$n$ - order of the polynomial
+
+This formula is similar to the one from MM2 but also takes order of the polynomial into consideration. In general this method is better. For polynomials with real roots it is globally convergent. It does not have formal analysis for complex roots but it usually shows good numerical properties, although divergence may happen.
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/08-results.tex b/NotProgramming/ENUME/projectB/Report/sections/08-results.tex
new file mode 100644
index 00000000..24aab4c4
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/08-results.tex
@@ -0,0 +1,174 @@
+\section{Results}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task3overall.eps}
+\end{center}
+
+
+\begin{center}
+ \includegraphics[scale=0.25]{task3left.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task3right.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task3complexoverall.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task3complexleft.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task3complexright.eps}
+\end{center}
+
+\begin{center}
+ \includegraphics[scale=0.25]{task3complexup.eps}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & -1.25 & -20.32 \\
+\hline
+2 & -0.67905 & -0.017268 \\
+\hline
+3 & -0.67787 & -3.1489e-07 \\
+\hline
+4 & -0.67787 & 0 \\
+\hline
+\hline
+\hline
+
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 6.25 & 43.43 \\
+\hline
+2 & 6.3376 & -1.8647 \\
+\hline
+3 & 6.3341 & 0.0029631 \\
+\hline
+4 & 6.3341 & 7.9942e-09\\
+\hline
+5 & 6.3341 & -7.1942e-14\\
+\hline
+
+
+\end{tabular}
+\end{center}
+
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 0+0i & 3 \\
+\hline
+2 & -0.042857+0.71586i & 4.1826 \\
+\hline
+3 & 0.172+0.56266i & 0.040584 \\
+\hline
+4 & 0.17188+0.56551i & 2.8484e-06 \\
+\hline
+5 & 0.17188+0.56551i & 2.2952e-14 \\
+\hline
+6 & 0.17188+0.56551i & 0 \\
+\hline
+
+
+\end{tabular}
+\end{center}
+
+
+\subsection{Comparison of results between Laguerre's method and MM2 method}
+
+\subsubsection{Tables for MM2}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & -1.25+0i & -20.32+0i \\
+\hline
+2 & -0.72604-0.25326i & 1.0515-4.0744i \\
+\hline
+3 & -0.68613-0.01483i & -0.11667-0.22303i \\
+\hline
+4 & -0.67788+2.5407e-06i & -0.00010163+3.7123e-05i \\
+\hline
+5 & -0.67787-8.0819e-13i & 1.4105e-11-1.1809e-11i \\
+\hline
+ \hline
+
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 6.25 & 43.43 \\
+\hline
+2 & 6.3376 & -1.8647 \\
+\hline
+3 & 6.3341 & 0.0029695 \\
+\hline
+4 & 6.3341 & 1.6294e-08 \\
+\hline
+5 & 6.3341 & -4.6896e-13 \\
+\hline
+\hline
+
+\end{tabular}
+\end{center}
+
+\begin{center}
+ \begin{tabular}{| c c c |}
+\hline
+Iteration & root & f(root) \\
+\hline
+1 & 0+0i & 3 \\
+\hline
+2 & -0.125+0.85696i & 8.0341 \\
+\hline
+3 & 0.16892+0.62593i & 0.94053 \\
+\hline
+4 & 0.17203+0.56536i & 0.0031354 \\
+\hline
+5 & 0.17188+0.56551i & 3.8615e-09 \\
+\hline
+6 & 0.17188+0.56551i & 0 \\
+\hline
+\hline
+
+\end{tabular}
+\end{center}
+
+As expected Laguerre's method reigns supreme, it is:
+\begin{enumerate}
+\item Faster
+With 5 iterations on average compared to around 5.3 for MM2
+\item More accurate
+For real root -0.67787 matlab calculated the value of this function for Laguerre's method as equal to exactly 0 as opposed to around $10^{-11}$ error for MM2.
+\item With no errors
+Laguerre's method did not mistakenly added imaginary part to real root -0.67787 as MM2 did.
+\end{enumerate}
+
+Laguerre's method is faster and more accurate than MM2 which means that we can compare it to faster version of MM1, this means that it is the best method we tested in this exercise.
+
+\chapter{Code appendix}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/09-task-1.tex b/NotProgramming/ENUME/projectB/Report/sections/09-task-1.tex
new file mode 100644
index 00000000..c8350018
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/09-task-1.tex
@@ -0,0 +1,230 @@
+\section{Task 1}
+
+\subsection{task1Bisection.m}
+
+\subsubsection{Top of task1Bisection.m}
+\begin{simplechar}
+\begin{lstlisting}
+interval = [-5, 10];
+rootBrackets = rootBracketing(@taskFunction, interval(1), interval(2));
+
+printGraph(@taskFunction, 'False Position', @falsePosition, interval, rootBrackets, 'Approximate zeros of function for method of ');
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{taskFunction}
+\begin{simplechar}
+\begin{lstlisting}
+function y = taskFunction(x)
+ y = -2.1 + 0.3*x - x*exp(1)^(-x);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{falsePosition}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = falsePosition(taskFunction, a, b, tolerance)
+
+ [iterations, lastTwoA, lastTwoB, i] = initialize();
+ [zero, iterations, a, b, lastTwoA, lastTwoB] = firstTwoIterations(a, b, taskFunction, iterations, lastTwoA, lastTwoB);
+ [zero, iterations] = falsePositionLoop(taskFunction, zero, tolerance, lastTwoA, lastTwoB, i, a, b, iterations);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [iterations, lastTwoA, lastTwoB, i] = initialize()
+ iterations = double.empty(2, 0);
+ lastTwoA = double.empty(2, 0);
+ lastTwoB = double.empty(2, 0);
+ i = 0;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{taskFunction}
+\begin{simplechar}
+\begin{lstlisting}
+function y = taskFunction(x)
+ y = -2.1 + 0.3*x - x*exp(1)^(-x);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{firstTwoIterations}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations, a, b, lastTwoA, lastTwoB] = firstTwoIterations(a, b, taskFunction, iterations, lastTwoA, lastTwoB)
+ for j = 1 : 2
+ zero = (a*taskFunction(b) - b * taskFunction(a)) / (taskFunction(b) - taskFunction(a));
+ iterations(:, size(iterations, 2) + 1) = [zero, taskFunction(zero)];
+ if sign(taskFunction(a)) ~= sign(taskFunction(zero))
+ b = zero;
+ else
+ a = zero;
+ end
+ lastTwoA(j) = a;
+ lastTwoB(j) = b;
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{falsePositionLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = falsePositionLoop(taskFunction, zero, tolerance, lastTwoA, lastTwoB, i, a, b, iterations)
+ while abs(taskFunction(zero)) > tolerance
+ [lastTwoA, i, a, lastTwoB, b, tolerance, zero, iterations] = insideLoop(lastTwoA, i, a, lastTwoB, b, tolerance, taskFunction, iterations);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{insideLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [lastTwoA, i, a, lastTwoB, b, tolerance, zero, iterations] = insideLoop(lastTwoA, i, a, lastTwoB, b, tolerance, taskFunction, iterations)
+ [lastTwoA, lastTwoB] = changeLastTwoAB(lastTwoA, lastTwoB, i, a, b);
+ zero = calculateZero(lastTwoB, tolerance, a, b, lastTwoA, taskFunction);
+ iterations(:, size(iterations, 2) + 1) = [zero, taskFunction(zero)];
+ [a, b] = newSubInterval(taskFunction, a, b, zero);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{changeLastTwoAB}
+\begin{simplechar}
+\begin{lstlisting}
+function [lastTwoA, lastTwoB] = changeLastTwoAB(lastTwoA, lastTwoB, i, a, b)
+ lastTwoA(mod(i, 2) + 1) = a;
+ lastTwoB(mod(i, 2) + 1) = b;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{calculateZero}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero] = calculateZero(lastTwoB, tolerance, a, b, lastTwoA, taskFunction)
+ if(abs(lastTwoB(1) - lastTwoB(2)) < tolerance)
+ zero = (a*(taskFunction(b) / 2) - b * taskFunction(a)) / (taskFunction(b) / 2 - taskFunction(a));
+ elseif (abs(lastTwoA(1) - lastTwoA(2)) < tolerance)
+ zero = (a*taskFunction(b) - b * (taskFunction(a) / 2)) / (taskFunction(b) - (taskFunction(a) / 2));
+ else
+ zero = (a*taskFunction(b) - b * taskFunction(a)) / (taskFunction(b) - taskFunction(a));
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{newSubInterval}
+\begin{simplechar}
+\begin{lstlisting}
+function [a, b] = newSubInterval(taskFunction, a, b, zero)
+ if sign(taskFunction(a)) ~= sign(taskFunction(zero))
+ b = zero;
+ else
+ a = zero;
+ end
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+
+
+\subsection{task1Newton.m}
+
+\subsubsection{Top of task1Newton.m}
+\begin{simplechar}
+\begin{lstlisting}
+interval = [-5, 10];
+rootBrackets = rootBracketing(@taskFunction, interval(1), interval(2));
+
+printGraph(@taskFunction, 'Newton', @newtonMethod, interval, rootBrackets, 'Approximate zeros of function for method of ');
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{taskFunction}
+\begin{simplechar}
+\begin{lstlisting}
+function y = taskFunction(x)
+ y = -2.1 + 0.3*x - x*exp(1)^(-x);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{newtonMethod}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = newtonMethod(taskFunction, a, b, tolerance)
+ [iterations, iteration, zero] = initialize(a, b);
+ [zero, iterations] = newtonLoop(iterations, iteration, zero, a, b, tolerance, taskFunction);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [iterations, step, zero] = initialize(a, b)
+ iterations = double.empty(2, 0);
+ step = sqrt(eps);
+ zero = (a + b) / 2;
+ iterations(:, size(iterations, 2) + 1) = [zero, taskFunction(zero)];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{newtonLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = newtonLoop(iterations, iteration, zero, a, b, tolerance, taskFunction)
+ while abs(taskFunction(zero)) > tolerance
+ [zero, iterations] = insideLoop(taskFunction, zero, iteration, iterations, a, b);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{insideLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = insideLoop(taskFunction, zero, iteration, iterations, a, b)
+ [zero, iterations] = calculateZeroIterations(taskFunction, zero, iteration, iterations);
+ checkForDivergence(zero, a, b);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{calculateZeroIterations}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = calculateZeroIterations(taskFunction, zero, iteration, iterations)
+ derivative = (taskFunction(zero + iteration) - taskFunction(zero - iteration)) / (2 * iteration);
+ zero = zero - taskFunction(zero) / derivative;
+ iterations(:, size(iterations, 2) + 1) = [zero, taskFunction(zero)];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{checkForDivergence}
+\begin{simplechar}
+\begin{lstlisting}
+function checkForDivergence(zero, a, b)
+ if zero < a || zero > b
+ error('Divergent iteration');
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
diff --git a/NotProgramming/ENUME/projectB/Report/sections/10-task-2.tex b/NotProgramming/ENUME/projectB/Report/sections/10-task-2.tex
new file mode 100644
index 00000000..33bae42f
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/10-task-2.tex
@@ -0,0 +1,4 @@
+\section{Task 2}
+
+ \input{sections/10-task-2/01-task2mm1-m}
+ \input{sections/10-task-2/02-task2mm2-m}
diff --git a/NotProgramming/ENUME/projectB/Report/sections/10-task-2/01-task2mm1-m.tex b/NotProgramming/ENUME/projectB/Report/sections/10-task-2/01-task2mm1-m.tex
new file mode 100644
index 00000000..2601d157
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/10-task-2/01-task2mm1-m.tex
@@ -0,0 +1,200 @@
+\subsection{task2MM1.m}
+
+\subsubsection{Top of task2MM1}
+\begin{simplechar}
+\begin{lstlisting}
+interval = [-5, 10];
+rootBrackets = rootBracketing(@polynomial, interval(1), interval(2));
+
+printGraph(@polynomial, 'MM1', @mm1, interval, rootBrackets, 'Approximate zeros of function for method of ');
+
+printComplexGraph(@polynomial, 'MM1', @mm1, [-1 - i, 1 + i], 'Aproximate complex roots of polynomial');
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{polynomial}
+\begin{simplechar}
+\begin{lstlisting}
+function y = polynomial(x)
+ y = -2 * x^4 + 12 * x^3 + 4* x^2 + 1 * x + 3;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{mm1}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, iterations] = mm1(polynomial, a, b, tolerance)
+ [approximation, approximationValue, iterations] = initialize(a, b, polynomial);
+ [approximation, iterations] = mm1Loop(approximation, tolerance, approximationValue, iterations, polynomial);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, approximationValue, iterations] = initialize(a, b, polynomial)
+ approximation = [a, b, (a + b) / 2];
+ approximationValue = arrayfun(polynomial, approximation);
+ iterations = [approximation(3); polynomial(approximation(3))];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{mm1Loop}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, iterations] = mm1Loop(approximation, tolerance, approximationValue, iterations, polynomial)
+ while abs(polynomial(approximation(3))) > tolerance
+ [approximation, approximationValue, iterations] = insideLoop(approximation, approximationValue, polynomial, iterations);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{insideLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, approximationValue, iterations] = insideLoop(approximation, approximationValue, polynomial, iterations)
+ equationsSystem = createEquationSystem(approximation, approximationValue);
+ [zPlus, zMinus] = rootsOfQuadraticFormula(equationsSystem, approximationValue);
+ [approximation, approximationValue, iterations] = updateApproximations(zPlus, zMinus, approximation, iterations, polynomial);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{createEquationSystem}
+\begin{simplechar}
+\begin{lstlisting}
+function equationsSystem = createEquationSystem(approximation, approximationValue)
+ [z0, z1, difference0, difference1] = initializeEquationSystem(approximation, approximationValue);
+ equationsSystem = solveEquationSystem(z0, difference0, z1, difference1);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{rootsOfQuadraticFormula}
+\begin{simplechar}
+\begin{lstlisting}
+function [zPlus, zMinus] = rootsOfQuadraticFormula(equationsSystem, approximationValue)
+ [a, b, c] = createApproximatedQuadraticFormula(equationsSystem, approximationValue);
+ [zPlus, zMinus] = findRootsOfQuadraticFormula(a, b, c);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{updateApproximations}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, approximationValue, iterations] = updateApproximations(zPlus, zMinus, approximation, iterations, polynomial)
+ newApproximation = chooseNewRoot(zPlus, zMinus, approximation);
+ iterations = addZeroToIterationVector(newApproximation, iterations, polynomial);
+ worstApproximationIndex = getWorstApproximationIndex(approximation, newApproximation);
+ [approximation, approximationValue] = deleteWorstApproximation(worstApproximationIndex, approximation, polynomial, newApproximation);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{initializeEquationSystem}
+\begin{simplechar}
+\begin{lstlisting}
+function [z0, z1, difference0, difference1] = initializeEquationSystem(approximation, approximationValue)
+ z0 = approximation(1) - approximation(3);
+ z1 = approximation(2) - approximation(3);
+ difference0 = approximationValue(1) - approximationValue(3);
+ difference1 = approximationValue(2) - approximationValue(3);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{solveEquationSystem}
+\begin{simplechar}
+\begin{lstlisting}
+function equationsSystem = solveEquationSystem(z0, difference0, z1, difference1)
+ equationsSystem = [z0 ^ 2, z0, difference0; z1 ^ 2, z1, difference1];
+ reductor = equationsSystem(2, 1) / equationsSystem(1, 1);
+ equationsSystem(2, :) = equationsSystem(2, :) - reductor * equationsSystem(1, :);
+ equationsSystem(2, 1) = 0;
+ equationsSystem(2, :) = equationsSystem(2, :) ./ equationsSystem(2, 2);
+ equationsSystem(1, :) = equationsSystem(1, :) - equationsSystem(1, 2) * equationsSystem(2, :);
+ equationsSystem(1, :) = equationsSystem(1, :) ./ equationsSystem(1, 1);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{createApproximatedQuadraticFormula}
+\begin{simplechar}
+\begin{lstlisting}
+function [a, b, c] = createApproximatedQuadraticFormula(equationsSystem, approximationValue)
+ a = equationsSystem(1, 3);
+ b = equationsSystem(2, 3);
+ c = approximationValue(3);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{findRootsOfQuadraticFormula}
+\begin{simplechar}
+\begin{lstlisting}
+function [zPlus, zMinus] = findRootsOfQuadraticFormula(a, b, c)
+ zPlus = -2 * c / (b + sqrt(b ^ 2 - 4 * a * c));
+ zMinus = -2 * c / (b - sqrt(b ^ 2 - 4 * a * c));
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{chooseNewRoot}
+\begin{simplechar}
+\begin{lstlisting}
+function newApproximation = chooseNewRoot(zPlus, zMinus, approximation)
+ if abs(zPlus) < abs(zMinus)
+ newApproximation = approximation(3) + zPlus;
+ else
+ newApproximation = approximation(3) + zMinus;
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{addZeroToIterationVector}
+\begin{simplechar}
+\begin{lstlisting}
+function iterations = addZeroToIterationVector(newApproximation, iterations, polynomial)
+ zero = newApproximation;
+ iterations(:, size(iterations, 2) + 1) = [zero, polynomial(zero)];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{getWorstApproximationIndex}
+\begin{simplechar}
+\begin{lstlisting}
+function worstApproximationIndex = getWorstApproximationIndex(approximation, newApproximation)
+ worstApproximationIndex = -1;
+ worstApproximationDifference = 0;
+ for i = 1:size(approximation, 2)
+ diff = abs(approximation(i) - newApproximation);
+ if diff > worstApproximationDifference
+ worstApproximationIndex = i;
+ worstApproximationDifference = diff;
+ end
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{deleteWorstApproximation}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, approximationValue] = deleteWorstApproximation(worstApproximationIndex, approximation, polynomial, newApproximation)
+ approximation(worstApproximationIndex) = [];
+ approximation(3) = newApproximation;
+ approximationValue = arrayfun(polynomial, approximation);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
diff --git a/NotProgramming/ENUME/projectB/Report/sections/10-task-2/02-task2mm2-m.tex b/NotProgramming/ENUME/projectB/Report/sections/10-task-2/02-task2mm2-m.tex
new file mode 100644
index 00000000..2063856a
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/10-task-2/02-task2mm2-m.tex
@@ -0,0 +1,128 @@
+\subsection{task2MM2.m}
+
+
+\subsubsection{top of task2MM2.m}
+\begin{simplechar}
+\begin{lstlisting}
+interval = [-5, 10];
+rootBrackets = rootBracketing(@polynomial, interval(1), interval(2));
+
+printGraph(@polynomial, 'MM2', @mm2, interval, rootBrackets, 'Approximate zeros of function for method of ');
+
+printComplexGraph(@polynomial, 'MM2', @mm2, [-1 - i, 1 + i], 'Aproximate complex roots of polynomial');
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{polynomial}
+\begin{simplechar}
+\begin{lstlisting}
+function y = polynomial(x)
+ y = -2 * x^4 + 12 * x^3 + 4* x^2 + 1 * x + 3;
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{mm2}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, iterations] = mm2(polynomial, a, b, tolerance)
+ [approximation, iterations] = initialize(a, b, polynomial);
+ [approximation, iterations] = mm2Loop(approximation, iterations, polynomial, tolerance);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, iterations] = initialize(a, b, polynomial)
+ approximation = (a + b) / 2;
+ iterations = [approximation; polynomial(approximation)];
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{mm2Loop}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, iterations] = mm2Loop(approximation, iterations, polynomial, tolerance)
+ while abs(polynomial(approximation)) > tolerance
+ [approximation, iterations] = insideLoop(approximation, polynomial, iterations);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{insideLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, iterations] = insideLoop(approximation, polynomial, iterations)
+ [a, b, c] = getABC(approximation, polynomial);
+ [zPlus, zMinus] = findRoots(a, b, c);
+ newApproximation = chooseNewApproximation(zPlus, zMinus, approximation);
+ [approximation, iterations] = updateApproximations(newApproximation, iterations, polynomial);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{getABC}
+\begin{simplechar}
+\begin{lstlisting}
+function [a, b, c] = getABC(approximation, polynomial)
+ c = polynomial(approximation);
+ b = derivative(polynomial, approximation, 1);
+ a = derivative(polynomial, approximation, 2) / 2;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{findRoots}
+\begin{simplechar}
+\begin{lstlisting}
+function [zPlus, zMinus] = findRoots(a, b, c)
+ zPlus = -2 * c / (b + sqrt(b ^ 2 - 4 * a * c));
+ zMinus = -2 * c / (b - sqrt(b ^ 2 - 4 * a * c));
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{chooseNewApproximation}
+\begin{simplechar}
+\begin{lstlisting}
+function newApproximation = chooseNewApproximation(zPlus, zMinus, approximation)
+ if abs(zPlus) < abs(zMinus)
+ newApproximation = approximation + zPlus;
+ else
+ newApproximation = approximation + zMinus;
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{updateApproximations}
+\begin{simplechar}
+\begin{lstlisting}
+function [approximation, iterations] = updateApproximations(newApproximation, iterations, polynomial)
+ approximation = newApproximation;
+ iterations(:, size(iterations, 2) + 1) = [approximation, polynomial(approximation)];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{derivative}
+\begin{simplechar}
+\begin{lstlisting}
+function y = derivative(function_, x, degree)
+ if degree == 0
+ y = function_(x);
+ return
+ end
+
+ step = sqrt(eps);
+ y = (derivative(function_, x + step, degree - 1) - derivative(function_, x - step, degree - 1)) / (2 * step);
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectB/Report/sections/11-task-3.tex b/NotProgramming/ENUME/projectB/Report/sections/11-task-3.tex
new file mode 100644
index 00000000..ed52d808
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/11-task-3.tex
@@ -0,0 +1,121 @@
+\section{Task 3}
+
+\subsubsection{Top of Task 3}
+\begin{simplechar}
+\begin{lstlisting}
+interval = [-5, 10];
+rootBrackets = rootBracketing(@polynomial, interval(1), interval(2));
+
+printGraph(@polynomial, 'Laguerre', @laguerre, interval, rootBrackets, 'Approximate zeros of function for method of ');
+
+printComplexGraph(@polynomial, 'Laguerre', @laguerre, [-1 - i, 1 + i], 'Aproximate complex roots of polynomial');
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{polynomial}
+\begin{simplechar}
+\begin{lstlisting}
+function y = polynomial(x)
+ y = -2 * x^4 + 12 * x^3 + 4* x^2 + 1 * x + 3;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{laguerre}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = laguerre(polynomial, a, b, tolerance)
+ [degree, zero, iterations] = initialize(a, b, polynomial);
+ [zero, iterations] = laguerreLoop(polynomial, zero, tolerance, iterations, degree);
+
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [degree, zero, iterations] = initialize(a, b, polynomial)
+ degree = 4;
+ zero = (a + b) / 2;
+ iterations = [zero; polynomial(zero)];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{laguerreLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = laguerreLoop(polynomial, zero, tolerance, iterations, degree)
+ while abs(polynomial(zero)) > tolerance
+ [iterations, zero] = insideLoop(polynomial, zero, degree, iterations);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{insideLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [iterations, zero] = insideLoop(polynomial, zero, degree, iterations)
+ [derrivative0, derrivative1, derrivative2] = calculateDerrivatives(polynomial, zero);
+ [zPlus, zMinus] = calculateZ(degree, derrivative0, derrivative1, derrivative2);
+ newZero = chooseNewZero(zPlus, zMinus, zero);
+ [zero, iterations] = updateZeros(newZero, iterations, polynomial);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{calculateDerrivatives}
+\begin{simplechar}
+\begin{lstlisting}
+function [derrivative0, derrivative1, derrivative2] = calculateDerrivatives(polynomial, zero)
+ derrivative0 = polynomial(zero);
+ derrivative1 = derivative(polynomial, zero, 1);
+ derrivative2 = derivative(polynomial, zero, 2);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{calculateZ}
+\begin{simplechar}
+\begin{lstlisting}
+function [zPlus, zMinus] = calculateZ(degree, derrivative0, derrivative1, derrivative2)
+ expressionUnderSquareRoot = (degree - 1) * ((degree - 1) * derrivative1 ^ 2 - degree * derrivative0 * derrivative2);
+ lagsqrt = sqrt(expressionUnderSquareRoot);
+
+ zPlus = degree * derrivative0 / (derrivative1 + lagsqrt);
+ zMinus = degree * derrivative0 / (derrivative1 - lagsqrt);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsubsection{chooseNewZero}
+\begin{simplechar}
+\begin{lstlisting}
+function newZero = chooseNewZero(zPlus, zMinus, zero)
+ if abs(zPlus) < abs(zMinus)
+ newZero = zero - zPlus;
+ else
+ newZero = zero - zMinus;
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{updateZeros}
+\begin{simplechar}
+\begin{lstlisting}
+function [zero, iterations] = updateZeros(newZero, iterations, polynomial)
+ zero = newZero;
+ iterations(:, size(iterations, 2) + 1) = [zero, polynomial(zero)];
+end
+\end{lstlisting}
+\end{simplechar}
+
+ \input{sections/11-task-3/01-rootbrackering-m}
+ \input{sections/11-task-3/02-printgraph-m}
+ \input{sections/11-task-3/03-printcomplexgraph-m}
diff --git a/NotProgramming/ENUME/projectB/Report/sections/11-task-3/01-rootbrackering-m.tex b/NotProgramming/ENUME/projectB/Report/sections/11-task-3/01-rootbrackering-m.tex
new file mode 100644
index 00000000..7ec91a87
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/11-task-3/01-rootbrackering-m.tex
@@ -0,0 +1,55 @@
+\subsection{rootBrackering.m}
+
+\subsubsection{updateZeros}
+\begin{simplechar}
+\begin{lstlisting}
+% find the root brackets of a function within the given range
+function rootBrackets = rootBracketing(givenFunction, intervalLeft, intervalRight)
+ [a, b, rootBrackets, resolution] = initializeValues(intervalLeft, intervalRight);
+ rootBrackets = bracketingLoop(a, b, rootBrackets, intervalRight, resolution, givenFunction);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{initializeValues}
+\begin{simplechar}
+\begin{lstlisting}
+function [a, b, rootBrackets, resolution] = initializeValues(intervalLeft, intervalRight)
+ % define search resolution
+ resolution = (intervalRight - intervalLeft) / 6;
+ % The higher the value of denominator the less iterations will it take
+ % to reach the roots, however in order to have nice graph showing those
+ % brackets I will choose relatively small denominator - I have choosen
+ % the smallest natural number that still generates brackets on a graph
+
+ % start search at the start of the range
+ a = intervalLeft;
+ b = intervalLeft + resolution;
+ rootBrackets = double.empty(2, 0); % initialize empty vector of size 2
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
+\subsubsection{bracketingLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function rootBrackets = bracketingLoop(a, b, rootBrackets, intervalRight, resolution, givenFunction)
+ while b ~= intervalRight % if the bracket can't be expanded end loop
+ % if the function changes sign inside the interval that means that we passed through a root that means that a bracket has been found
+ if sign(givenFunction(a)) ~= sign(givenFunction(b))
+ % save bracket
+ rootBrackets(:, size(rootBrackets, 2) + 1) = [a, b]; % Add the new bracket to existing ones
+ end
+ % check next bracket
+ a = b;
+ b = min(a + resolution, intervalRight);
+ % Once a + resolution > intervalRight, then we will know that we
+ % reached beyond the interval and we must stop
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
diff --git a/NotProgramming/ENUME/projectB/Report/sections/11-task-3/02-printgraph-m.tex b/NotProgramming/ENUME/projectB/Report/sections/11-task-3/02-printgraph-m.tex
new file mode 100644
index 00000000..bf61c726
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/11-task-3/02-printgraph-m.tex
@@ -0,0 +1,42 @@
+\subsection{printGraph.m}
+\begin{simplechar}
+\begin{lstlisting}
+% graph the real roots of a function
+function printGraph(taskFunction, algorithmName, algorithm, interval, rootBrackets, plotTitle)
+ figure()
+ grid on; % Get y values lines
+ hold on; % Retain current plot when adding new plots
+ title([plotTitle, algorithmName]);
+ set(gca, 'XAxisLocation', 'origin'); % Set properties of current axis
+ x = interval(1):0.01:interval(2);
+ % x is a vector of values between left and right interval with every value being higher by 0.01
+ y = arrayfun(taskFunction, x); % We sketch the function from task for each x
+ plot(x, y);
+
+ % iterate over rootBrackets and add them to the plot
+ for rootBracket = rootBrackets
+ % find all zeros within the bracket using the given algorithm
+ % Get all steps from the algorithm we use
+ [~, steps] = algorithm(taskFunction, rootBracket(1), rootBracket(2), 1e-10);
+
+ firstStepColor = [1 0 0]; % Red
+ otherStepsColor = [0 1 0]; % Green
+ % plot first steps
+ scatter(steps(1, 1), steps(2, 1), [], firstStepColor);
+ text(steps(1, 1), steps(2, 1), 'firstStep', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top'); % It makes text appear neatly
+ % plot other steps
+ scatter(steps(1, 2:end), steps(2, 2:end), [], otherStepsColor);
+
+
+
+ % print root table
+ disp([plotTitle, ' (', algorithmName, ')']);
+ columns = {'step', 'root', 'value at root'};
+ disp(table((1:size(steps, 2))', steps(1, :)', steps(2, :)', 'VariableNames', columns));
+ end
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\newpage
diff --git a/NotProgramming/ENUME/projectB/Report/sections/11-task-3/03-printcomplexgraph-m.tex b/NotProgramming/ENUME/projectB/Report/sections/11-task-3/03-printcomplexgraph-m.tex
new file mode 100644
index 00000000..840d4ed6
--- /dev/null
+++ b/NotProgramming/ENUME/projectB/Report/sections/11-task-3/03-printcomplexgraph-m.tex
@@ -0,0 +1,41 @@
+\subsection{printComplexGraph.m}
+\begin{simplechar}
+\begin{lstlisting}
+% graph the complex roots of a function
+function printComplexGraph(printComplexGraph, algorithmName, algorithm, rootBrackets, plottitle)
+ figure();
+ grid on; % Get y values lines
+ hold on; % Retain current plot when adding new plots
+ title([plottitle, algorithmName]);
+ xlabel("Real part");
+ ylabel("Imaginary part");
+ set(gca, 'XAxisLocation', 'origin'); % Set properties of current axis
+
+ % find all zeros within the bracket using the given algorithm
+ [~, steps] = algorithm(printComplexGraph, rootBrackets(1), rootBrackets(2), 1e-15);
+
+ % plot first step
+ text(real(steps(1, 1)), imag(steps(1, 1)), 'start', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top');
+
+ % plot steps on graph
+ plot(real(steps(1, :)), imag(steps(1, :)), '-x');
+
+ % plot last step
+ text(real(steps(1, end)), imag(steps(1, end)), 'end', 'HorizontalAlignment', 'center', 'VerticalAlignment', 'top');
+
+
+ % print root table
+ disp([plottitle, ' (', algorithmName, ')']);
+ columns = {'step', 'root', 'abs value at root'};
+ disp(table([1:size(steps, 2)]', steps(1, :)', abs(steps(2, :))', 'VariableNames', columns));
+end
+\end{lstlisting}
+\end{simplechar}
+
+
+\begin{thebibliography}{9}
+\bibitem{texbook}
+Piotr Tatjewski (2014) \emph{Numerical Methods}, Oficyna Wydawnicza Politechniki Warszawskiej
+\end{thebibliography}
+
+
diff --git a/NotProgramming/ENUME/projectC/ENUME_KRZYSZTOF_RUDNICKI_307585_ENUME.tex b/NotProgramming/ENUME/projectC/ENUME_KRZYSZTOF_RUDNICKI_307585_ENUME.tex
index 8d0100e5..133b045f 100644
--- a/NotProgramming/ENUME/projectC/ENUME_KRZYSZTOF_RUDNICKI_307585_ENUME.tex
+++ b/NotProgramming/ENUME/projectC/ENUME_KRZYSZTOF_RUDNICKI_307585_ENUME.tex
@@ -55,1159 +55,21 @@ linkto=all,
\tableofcontents
\chapter{Determine polynomial function fitting experimental data}
-\section{Problem}
-Given following samples:
-\begin{center}
- \begin{tabular}{| c | c |}
-\hline
-$x_i$ & $y_i$ \\
-\hline
--5 & -6.5743\\
-\hline
--4 & 0.9765\\
-\hline
--3 & 3.1026\\
-\hline
--2 & 1.8572 \\
-\hline
--1 & 1.3165 \\
-\hline
-0 & -0.6144 \\
-\hline
-1 & 0.1032 \\
-\hline
-2 & 0.3729 \\
-\hline
-3 & 2.5327 \\
-\hline
-4 & 7.3857 \\
-\hline
-5 & 9.4892 \\
-\hline
-
-\end{tabular}
-\end{center}
-
-We have to determine polynomial function $ y = f(x) $ that best fits this data. \\
-We will use least-square approximation using system of normal equation with QR factorization.
-
-\section{Theoretical introduction}
-\subsection{Linear Least Squares Problem}
-We have polynomial function:
-\[ y(x) = a_nx^n + a_{n-1}x^{n-1} + \dots + a_1x^1 + a_0 \]
-where n - degree of the polynomial we use to approximate function \\
-Given matrix $\mathbf{A} \in \mathbb{R}^{m \times n} \quad (m > n)$ and vector $\mathbf{y} \in \mathbb{R}^m$ \\
-We need to find vector \^{x} such that:
-\[ \forall x \in \mathbb{R}^n \quad|| \mathbf{y} - \mathbf{A} \hat{x} ||_2 \leq || \mathbf{y} - \mathbf{A}x ||_2 \]
-$\mathbf{A}\hat{x}$ is the vector of values of the approximating function at each data point and $y$ is the vector of values of data points. \\
-We have to minimize the Euclidean norm of difference between approximation and data points. \\
-To obtain $\hat{x}$ we will calculate the derrivative of error function with respect to $b_n$ and equate it to 0. This way we will get system of equations caled \textbf{normal equations} which have unique solution in form of vector $\hat{x}$
-
-\subsection{Gram matrix and QR decomposition}
-We will use Gram's matrix since it's condition number tends to be pretty high which improves the accuracy of our solution. \\
-Gram's matrix is a matrix of set of normal equations. The simplest way to present normal equations is by using formula:
-\[ \langle \phi_i, \phi_k \rangle \myeq \sum_{j=0}^N \phi_i(x_j)fi_k(x_j) \]
-Which then leads to following matrix \textbf{A}:
-
-\[
-A = \begin{bmatrix}
-\phi_0(x_0) & \phi_1(x_0) & \dots & \phi_n(x_0) \\
-\phi_0(x_1) & \phi_1(x_1) & \dots & \phi_n(x_1) \\
-\phi_0(x_2) & \phi_1(x_2) & \dots & \phi_n(x_2) \\
-\vdots & \vdots & \vdots & \vdots \\
-\phi_0(x_N) & \phi_1(x_N) & \dots & \phi_n(x_N) \\
-\end{bmatrix}
-\]
-
-In our case we define matrix \textbf{A} as:
-\[
-A = \begin{bmatrix}
-1 & x_0 & (x_0)^2 & \dots & (x_0)^n \\
-1 & x_1 & (x_1)^2 & \dots & (x_1)^n\\
-1 & x_2 & (x_2)^2 & \dots & (x_2)^n\\
-\vdots & \vdots & \vdots & \vdots \\
-1 & x_N & (x_N)^2 & \dots & (x_N)^n\\
-\end{bmatrix}
-\]
-
-Where $x_N$ is the x-axis position for the N-th data point. Then we can express system of natural equations using A in this way:
-\[ A^Ty = (A^TA)\hat{x} \]
-
-With condition number of A equal to square root of condition number of Gram's matrix which gives us small errors. It is also usefull for QR factoization since we can rewrite it as follows:
-\[ (R^TQ^T)(QR)\hat{x} = (R^TQ^T)y \]
-Since determinant of $R \neq 0$ and $Q^TQ = I$ we can simplify aforementioned equation to:
-\[ R\hat{x} = Q^Ty \]
-And to optimize even further ahead insetead of using QR decomposition we can use faster $\tilde{Q}\tilde{R}$ decomposition:
-\[ \tilde{R}\hat{x} = (\tilde{Q}^T\tilde{Q})^{-1}(\tilde{Q}^T) \]
-This is faster since $\tilde{R}$ is an upper triangular matrix, easily solved using back-substitution.
-
-\subsection{Gram-Schmidt algorithm}
-We will use Gram-Schmidt algorithm for $\tilde{Q}\tilde{R}$ decomposition.
-Gram-Schmidt algorithm takes non-orthogonal function basis denoted as:
-\[ \phi_0, \dots, \phi_n \]
-and orthogonalizes it into orthogonal function basis denoted as:
-\[ \psi_0, \dots, \psi_n \]
-Standard Gram-Schmid algorithm looks like this:
-\[ \psi_0 = \phi_0 \]
-\[ \psi_1 = \phi_1 - \frac{\langle \psi_0, \phi_1 \rangle}{\langle \psi_0, \psi_0 \rangle} \psi_0 \]
-\[ \psi_n = \phi_n - \sum_{j = 0}^{i-1} \frac{\langle \psi_j, \phi_i \rangle}{\langle \psi_j, \psi_j \rangle} \psi_j \]
-Where $ i = 2, \dots, n $
-Then we get a very well conditioned set of normal equations:
-\[ a_0\langle \psi_0, \psi_0 \rangle = \langle f, \psi_0 \rangle \]
-\[ a_1\langle \psi_1, \psi_1 \rangle = \langle f, \psi_1 \rangle \]
-\[ \vdots \]
-\[ a_n\langle \psi_n, \psi_n \rangle = \langle f, \psi_n \rangle \]
-
-\section{Results}
-
-I decided to simulate polynomials up to $\mathbf{10^{th}}$ degree.
-
-\includepdf[pages=-]{10-eps-converted-to.pdf}
-\includepdf[pages=-]{11-eps-converted-to.pdf}
-\includepdf[pages=-]{12-eps-converted-to.pdf}
-\includepdf[pages=-]{13-eps-converted-to.pdf}
-\includepdf[pages=-]{14-eps-converted-to.pdf}
-\includepdf[pages=-]{15-eps-converted-to.pdf}
-\includepdf[pages=-]{16-eps-converted-to.pdf}
-\includepdf[pages=-]{17-eps-converted-to.pdf}
-\includepdf[pages=-]{18-eps-converted-to.pdf}
-\includepdf[pages=-]{19-eps-converted-to.pdf}
-\includepdf[pages=-]{110-eps-converted-to.pdf}
-\includepdf[pages=-]{111-eps-converted-to.pdf}
-
-\begin{center}
- \begin{tabular}{| c | c | c |}
-\hline
-
-Degree & Error & Condition number of Gram's Matrix \\
-\hline
-0& 13.2040& 1\\
-\hline
-1& 9.1281& 10\\
-\hline
-2& 8.8257& 408.7796\\
-\hline
-3& 4.2365& 8.5584e+03\\
-\hline
-4& 1.5418& 3.1798e+05\\
-\hline
-5& 1.5413& 7.4675e+06\\
-\hline
-6& 1.1689& 2.8316e+08\\
-\hline
-7& 0.9345& 7.6462e+09\\
-\hline
-8& 0.8883& 3.3055e+11\\
-\hline
-9& 0.8334& 1.5167e+13\\
-\hline
-10& 6.3645e-13& 9.2930e+14\\
-\hline
-11 & 2.2390 & 8.7763e+17 \\
-\hline
- \end{tabular}
-\end{center}
-
-\section{Discussion of results}
-As expected, with the increase in polynomial degree error of the solution decreased and condion number of Gram's matrix increased. The most interesting part is how for polynomial of degree \textbf{10} the error got significantly lower, $10^{-12}$ times lower than for polynomial of lower degree, with only around 100 times bigger Gram's matrix condition number, and then for polynomial of degree 11, the error become much much higher and so did Gram's matrix. I suppose that since we get 11 data points, approaching number of data points with the degree of the polynomial lowers the erorr until we have the same polynomial degree as data points at which point the error increases again.
-
-
-
-
-
-
-\chapter{Determine trajectory of the motion}
-
-
-\section{a) Runge-Kutta method of $4^{th}$ order and Adams PC}
-\subsection{Problem}
-We are given following equations:
-\[ \frac{dx_1}{dt} = x_2 + x_1(0.5 - x_1^2 - x_2^2) \]
-\[ \frac{dx_2}{dt} = -x_1 + x_2(0.5 - x_1^2 - x_2^2) \]
-
-And we have to determine the trajectory of the motion on interval $[0, 15]$ with following initial conditions:
-$ x_1(0) = 8; x_2(0) = 9 $
-In this section we will use Runge-Kutta method of $4^{th}$ order and Adams PC with different step-sizes until we find an optimal constant step size - when the decrease of the step size does not influence the solution significantly.
-
-\subsection{Theoretical Introdution}
-Determining the trajectory of the motion in this example can be mathematically described as solving a system of first order ordinary differential equations with given initical conditions. That is why we use Runge-Kutta method of order 4 which deals with exactly this kind of problem.
-\subsubsection{Runge-Kutta method of order 4}
-Any single step method are defined by the following formula, where h is a fixed step-size:
-\[ y_{n+1} = y_n + \Phi_f(x_n, y_n, h) \]
-where:
-\[ x_n = x_0 + nh \]
-\[ y(x_0) = y_0 = y_a \]
-where $y_a$ is given.
-Runge-Kutta method of order 4 - RK4 method looks like this:
-\[ y_{n+1} = y_n + \frac{1}{6}(k_1 + 2k_2+2k_3+k_4) \]
-\[ k_1 = f(x_n, y_n) \]
-\[ k_3 = f(x_n + \frac{1}{2}h, y_n + \frac{1}{2}hk_1) \]
-\[ k_2 = f(x_n + \frac{1}{2}h, y_n + \frac{1}{2}hk_2) \]
-\[ k_4 = f(x_n + h, y_n + hk_3) \]
-
-
-\subsection{Adams PC method}
-Adams method with $P_kEC_kE$ algorithm has the following form: \\
-P: \[ y_n^{[0]} = y_{n-1} + h\sum_{j=1}^k \beta_jf_{n-j} \]
-E: \[ f_n^{[0]} = f(x_n, y_n^{[0]}) \]
-C: \[ y_n = y_{n-1} + h \sum_{j=1}^k \beta_j^* f_{n-j} + h \beta_0^* f_n^{[0]}\]
-E: \[ f_n = f(x_n, y_n) \]
-
-When compared to explicit and implicit adams method PC metho has smaller absolute stability intervals than implicit method, while having significant advantage in calculations cost.
-
-
-
-\section{b) Runge-Kutta method of $4^{th}$ order with variable step size automatically adjusted}
-\subsection{Problem}
-We are given following equations:
-\[ \frac{dx_1}{dt} = x_2 + x_1(0.5 - x_1^2 - x_2^2) \]
-\[ \frac{dx_2}{dt} = -x_1 + x_2(0.5 - x_1^2 - x_2^2) \]
-And we have to determine the trajectory of the motion on interval $[0, 15]$ with following initial conditions:
-$ x_1(0) = 8; x_2(0) = 9 $
-In this section we will use Runge-Kutta method of $4^{th}$ order with step size automatically adjusted by the algorithm, with error estimation made according to the step-doubling rule.
-\subsection{Theoretical Introdution}
-Since Runge-Kutta method was explained in previous task I will focus on step-doubling rule.
-Everytime we increase step size we receive less accurate results at the benefit of less calculations cost, this means that we need to have reasonable approach to setting step size to maximise accuracy and minimize calculations cost. We will use step-doubling rule in this example.
-
-\subsubsection{Error estimation using step doubling-approach}
-For every step of size $h$ we perform two additional steps of size $\frac{h}{2}$. We denote: \\
-$y_n^{1}$ as a new point obtained using the original step-size $h$ \\
-$y_n^{2}$ as a new point obtained using steps of the size $\frac{h}{2}$ \\
-$r^{(1)}$ - approximation error affter the single step $h$ \\
-$r^{(2)}$ - summed approximation errors after the two smaller steps of length $\frac{h}{2}$ each. \\
-We have: \\
-\newpage
-After a single step:
-\[ y(x_n + h) = y_n^{(1)} + \frac{r_n^{p+1}(0)}{(p+1)!}h^{p+1} + O(h^{p+2}) \]
-After a double step:
-\[ y(x_n+h) \simeq y_n^{(2)} + 2\frac{r_n^{p+1}(0)}{(p+1)!}(\frac{h}{2})^{p+1} + O(h^{p+2}) \]
-
-We evaluate unknown coefficient from the first equation $ \frac{r_n^{p+1}(0)}{(p+1)!} $ and insert it into second one:
-\[ y(x_n+h) = y_n^{(2)} + \frac{h^{p+1}}{2^p}\frac{(x_n+h) - y_n^{(1)}}{h^{p+1} + O(h^{p+2})} \]
-We continue further and receive:
-\[ y(x_n + h)(1-\frac{1}{2^p}) = y_n^{(2)}(1-\frac{1}{2^p}) + \frac{y_n^{2}}{2^p} - \frac{y_n^{(1)}}{2^p} + O(h^{p+2}) \]
-We multiply by $\frac{2^p}{2^p - 1}$ and get:
-\begin{equation}
-y(x_n+h) = y_n^{(2)} + \frac{ y_n^{(2)} - y_n^{(1)} }{ 2^p - 1 } + O(h^{p+2})
-\end{equation}
-We also obtain for first equation in a similar way:
- \[ y(x_n+h) = y_n^{(1)} + 2^p\frac{y_n^{(2)} - y_n^{(1)}}{2^p - 1} + O(h^{p+2}) \]
-Assuming we take the main part of the error we get error estimate:
-\[ \delta_n(h) = \frac{2^p}{2^p-1}(y_n^{(2)} - y_n^{(1)}) \]
-But from the equation (2.1) we can treat expression:
-\[ \delta_n(2 \times \frac{h}{2}) = \frac{ y_n^{(2)} - y_n^{(1)}}{2^p - 1} \]
-as en estimate of the error of two consecutive steps of size $\frac{h}{2}$
-\subsubsection{Actual correction of the step size}
-In general formula for main part of the approximation error where:
-\\ $h$ - length of a step
-\[ \gamma = \frac{r_n^{(p+1)}(0)}{(p+1)!} \]
-Looks like this:
-\[ \delta_n(h) = \gamma h^{p+1} \]
-If we change step-size to $\alpha h$ then we get:
-\[ \delta_n(\alpha h) = \gamma (\alpha h)^{p+1} \]
-Then:
-\[ \delta_n(\alpha h) = \alpha^{p+1} \delta_n (h) \]
-We assume tolerance $\epsilon$:
-\[ |\delta_n(\alpha h)| = \epsilon \]
-We get:
-\[ \alpha^{p+1}|\delta_n(h)| = \epsilon \]
-Coefficient $\alpha$ for the step-size correction can be evaluated in such a way:
-\[ \alpha = (\frac{\epsilon}{|\delta_n (h)|})^{\frac{1}{p+1}} \]
-
-This method is also correct for RK4 method when $\delta_n(h) = \delta_n(2 \times \frac{h}{2}) $
-We should also take into considertaion lack of accuracy we do so by using safety factor $s$:
-\[ h_{n+1} = s \alpha h_n \]
-where $ s < 1 $
-For RK4 we use $ s \approx 0.9 $ \\
-We define accuracy parameters in such a way:
-\[ \epsilon = |y_n| \epsilon_r + \epsilon_a \]
-where $\epsilon_r$ is relative tolerance and $\epsilon_a$ is absolute tolerance. \\
-In case of set of more than on differential equations we must use worst case approach so the equations that need smallest step-size define step-size for all other equations.
-\newpage
-For RK methods we have following parameters:
-\[ \delta_n(h)_i = \frac{(y_i)_n^{(2)} - (y_i)_n^{(1)}}{2^p - 1} \]
-\[ \epsilon_i = |(y_i)_n^{(2)}| \epsilon_r + \epsilon_a \]
-\[ \alpha = \min_{1 \leq i \leq m} (\frac{\epsilon_i}{|\delta_n(h)_i}|)^{\frac{1}{p+1}} \]
-
-\subsection{Flow diagram}
-\begin{tikzpicture}[node distance=5cm]
- \node (start) [startstop, align=center]
- {
- START
- \begin{itemize}
-
- \item Functions from task
- \item Initial values
- \item Initial step size
- \item Integration interval
- \item Absolute error
- \item Relative error
- \end{itemize}
- };
- \node (solution) [align=center, startstop, below of = start]
- {
- Calculate solution:
- \[ x_{n+1} = x_n + h_n \]
- \[ y_{n+1} = y_n + h \phi_f(x_n; y_n; h) \]
- };
- \node (interval) [align=center, io, below of = solution]
- {
- $x_n$ > integration interval?
- };
- \node (finish) [startstop, align=center, , right=3cm of interval] {Finish};
- \node (error) [startstop, align=center, , below of = interval]
- {
- Estimate error and update step size:
- \[ h_{n+1} = s\alpha h_n \]
- };
-
-\path [-stealth, thick]
- (start) edge (solution);
-\path [-stealth, thick]
- (solution) edge (interval);
-\path [-stealth, thick]
- (interval) edge node[anchor=south] {YES} (finish);
-\path [-stealth, thick]
- (interval) edge node[anchor=east] {NO} (error);
-\path [-stealth, thick]
- (error) edge [bend left = 90] (solution);
-
-\end{tikzpicture}
-
-\section{Results}
-
-\includepdf[pages=-]{20-eps-converted-to.pdf}
-\includepdf[pages=-]{21-eps-converted-to.pdf}
-\includepdf[pages=-]{22-eps-converted-to.pdf}
-\includepdf[pages=-]{23-eps-converted-to.pdf}
-\includepdf[pages=-]{24-eps-converted-to.pdf}
-\includepdf[pages=-]{25-eps-converted-to.pdf}
-\includepdf[pages=-]{26-eps-converted-to.pdf}
-\includepdf[pages=-]{27-eps-converted-to.pdf}
-\includepdf[pages=-]{28-eps-converted-to.pdf}
-\includepdf[pages=-]{29-eps-converted-to.pdf}
-
-\section{Discussion of results}
-As we can see using RK4 algorithm with auto step size results in best solutions error-wise, trajectory plot is almost the same as the one generated by matlab function. Especially graph of step approximation error for RK4 auto step algorithm looks very good with errors as low as $10^{-7}$. Adam PC method on the other hand suffers from bigger accuarcy loss though the results are still satisfactory while requiring much less work on the coding part.
-
-\chapter{Code appendix}
-
-\section{functionDataPoints.m}
-\subsection{functionDataPoints}
-\begin{simplechar}
-\begin{lstlisting}
-function dataPoints = functionDataPoints()
- dataPoints = (-5:5)';
- dataPoints(:, 2) = [
- -6.5743
- 0.9765
- 3.1026
- 1.8572
- 1.3165
- -0.6144
- 0.1032
- 0.3729
- 2.5327
- 7.3857
- 9.4892
- ];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\section{task1.m}
-\subsection{task1}
-\begin{simplechar}
-\begin{lstlisting}
-function task1(polynomialDegree)
- for currentPolynomialDegree = 0 : polynomialDegree
- dataPoints = functionDataPoints();
- % obtain LSPSolutions of approximating polynomial
- [LSPSolutions, error, conditionNumber] = approximate(dataPoints, currentPolynomialDegree);
- displayInfo(currentPolynomialDegree, error, conditionNumber);
- plotGraph(currentPolynomialDegree, dataPoints, LSPSolutions)
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{displayInfo}
-\begin{simplechar}
-\begin{lstlisting}
-function displayInfo(currentPolynomialDegree, error, conditionNumber)
- disp("Current Polynomial Degree:");
- disp(currentPolynomialDegree);
- disp("Error: ");
- disp(error);
- disp("Condition number of Gram's Matrix: ");
- disp(conditionNumber);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{plotGraph}
-\begin{simplechar}
-\begin{lstlisting}
-function plotGraph(currentPolynomialDegree, dataPoints, LSPSolutions)
- figure;
- grid on;
- hold on;
- plotDataPoints(currentPolynomialDegree, dataPoints);
- plotApproximation(dataPoints, LSPSolutions);
- hold off;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{plotDataPoints}
-\begin{simplechar}
-\begin{lstlisting}
-function plotDataPoints(currentPolynomialDegree, dataPoints)
- title(['Polynomial approximation of the funtion using: ', num2str(currentPolynomialDegree), ' degree']);
- scatter(dataPoints(:, 1), dataPoints(:, 2), 72, 'x');
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{plotApproximation}
-\begin{simplechar}
-\begin{lstlisting}
-function plotApproximation(dataPoints, LSPSolutions)
- x = dataPoints(1):0.05:dataPoints(end, 1);
- y = valueApproximationAtx(LSPSolutions, x);
- plot(x, y);
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{approximate}
-\begin{simplechar}
-\begin{lstlisting}
-% find the approximating polynomial of the given degree
-function [LSPSolutions, error, conditionNumber] = approximate(dataPoints, polydeg)
- % initialize A matrix
- A = zeros(size(dataPoints, 1), polydeg + 1);
-
- A = calculateACells(dataPoints, A);
- LSPSolutions = solveLSP(A, dataPoints);
-
- % Calculate error of solution
- error = norm(dataPoints(:, 2) - A * LSPSolutions);
- % Calculate condition number of Gram's matrix
- GramsMatrix = A' * A;
- conditionNumber = cond(GramsMatrix);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{calculateACells}
-\begin{simplechar}
-\begin{lstlisting}
-function Matrix = calculateACells(dataPoints, Matrix)
- for row = 1 : size(Matrix, 1)
- for column = 1 : size(Matrix, 2)
- Matrix(row, column) = dataPoints(row, 1) ^ (column - 1);
- end
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{solveLSP}
-\begin{simplechar}
-\begin{lstlisting}
-function solutions = solveLSP(Matrix, dataPoints)
- [Q, eqsys, invqtq] = QRDecomposition(Matrix);
- eqsys(:, end + 1) = invqtq * Q' * dataPoints(:, 2);
- solutions = backSubstitution(eqsys);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{valueApproximationAtx}
-\begin{simplechar}
-\begin{lstlisting}
-function arrayOfValues = valueApproximationAtx(LSPSolutions, arrayOfArguments)
- arrayOfValues = zeros(1, size(arrayOfArguments, 2));
- arrayOfValues = calculateArrayofValues(arrayOfArguments, arrayOfValues, LSPSolutions);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{calculateArrayofValues}
-\begin{simplechar}
-\begin{lstlisting}
-function arrayOfValues = calculateArrayofValues(arrayOfArguments, arrayOfValues, LSPSolutions)
- for x = 1 : size(arrayOfArguments, 2)
- for i = 1 : size(LSPSolutions, 1)
- arrayOfValues(x) = arrayOfValues(x) + LSPSolutions(i) * arrayOfArguments(x) ^ (i - 1);
- end
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\section{task2.m}
-\subsection{task2}
-\begin{simplechar}
-\begin{lstlisting}
-function task2()
- [ordinaryDifferentialEquations, initialValues, interval, algorithms] = initialize();
- solveAndPrintODEs(algorithms, ordinaryDifferentialEquations, initialValues, interval);
- [result, sizes, errors] = solveAndPlotODEAutomatic(ordinaryDifferentialEquations, initialValues, interval);
- plotStatistics(result, sizes, errors);
- plotComparisonToMatlabFunction(ordinaryDifferentialEquations, interval, initialValues);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [ordinaryDifferentialEquations, initialValues, interval, algorithms] = initialize()
- ordinaryDifferentialEquations = {
- @(x) x(2) + x(1) * (0.5 - x(1)^2 - x(2)^2);
- @(x) -x(1) + x(2) * (0.5 - x(1)^2 - x(2)^2)
- };
- initialValues = [8; 9];
- interval = [0; 15];
-
- algorithms = {
- 'RK4 algorithm', @RK4, [0.01, 0.011];
- 'Adams PC algorithm', @AdamsPCMethod, [0.002, 0.013]
- };
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{solveAndPrintODEs}
-\begin{simplechar}
-\begin{lstlisting}
-function solveAndPrintODEs(algorithms, ordinaryDifferentialEquations, initialValues, interval)
- for algorithm = 1 : 2
- [algorithmName, algorithmFunction, stepSizes] = algorithms{algorithm, :};
- stepResults = solveForEachStep(stepSizes, ordinaryDifferentialEquations, initialValues, interval, algorithmFunction);
- plotAgainstTime(ordinaryDifferentialEquations, algorithmName, stepResults);
- plotAgainst(algorithmName, stepResults);
-
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{solveForEachStep}
-\begin{simplechar}
-\begin{lstlisting}
-function stepResults = solveForEachStep(stepSizes, ordinaryDifferentialEquations, initialValues, interval, algorithmFunction)
- stepResults = cell(size(stepSizes, 2), 3);
- stepNames = {'Optimal Step Size', 'Slightly Larger Step Size'};
- for stepNumber = 1:size(stepSizes, 2)
- result = algorithmFunction(ordinaryDifferentialEquations, initialValues, interval, stepSizes(stepNumber));
- stepResults(stepNumber, :) = {stepSizes(stepNumber), stepNames{stepNumber}, result};
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{beginPlot}
-\begin{simplechar}
-\begin{lstlisting}
-function beginPlot()
- figure;
- grid on;
- hold on;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{plotAgainstTime}
-\begin{simplechar}
-\begin{lstlisting}
-function plotAgainstTime(ordinaryDifferentialEquations, algorithmName, stepResults)
- for equationNumber = 1:size(ordinaryDifferentialEquations, 1)
- beginPlot();
-
- title([algorithmName, ', x_', num2str(equationNumber), ' ODE']);
-
- for stepresult = stepResults'
- plot(stepresult{3}(1, :), stepresult{3}(equationNumber + 1, :));
- end
-
- hold off;
- legend(stepResults{:, 2});
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{plotAgainst}
-\begin{simplechar}
-\begin{lstlisting}
-function plotAgainst(algorithmName, stepResults)
- beginPlot();
- title([algorithmName, ' trajectory plot (x_2 compared to x_1)']);
- for stepresult = stepResults'
- plot(stepresult{3}(2, :), stepresult{3}(3, :));
- end
- hold off;
- legend(stepResults{:, 2});
-% %print(['report/', func2str(algfunc), 'traj'], '-dpdf');
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{solveAndPlotODEAutomatic}
-\begin{simplechar}
-\begin{lstlisting}
-function [result, sizes, errors] = solveAndPlotODEAutomatic(ordinaryDifferentialEquations, initialValues, interval)
- [result, sizes, errors] = solveRKAutomatic(ordinaryDifferentialEquations, initialValues, interval);
- plotTrajectory(result);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{solveRKAutomatic}
-\begin{simplechar}
-\begin{lstlisting}
-function [result, sizes, errors] = solveRKAutomatic(ordinaryDifferentialEquations, initialValues, interval)
- initialStepSize = 1e-5;
- relativeEpsilon = 1e-9;
- absoluteEpsilon = 1e-9;
- [result, sizes, errors] = RK4Automatic(ordinaryDifferentialEquations, initialValues, interval, initialStepSize, relativeEpsilon, absoluteEpsilon);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{plotTrajectory}
-\begin{simplechar}
-\begin{lstlisting}
-function plotTrajectory(result)
- figure;
- plot(result(2, :), result(3, :));
- grid on;
- title('RK4 with auto step trajectory plot (x_2 against x_1)');
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{plotStatistics}
-\begin{simplechar}
-\begin{lstlisting}
-function plotStatistics(result, sizes, errors)
- stats = {
- "RK4 with auto step step size", "rk4sizes", sizes;
- "RK4 with auto step approximation error", "rk4errors", errors
- };
- for stat = stats'
- figure;
- plot(result(1, 2:(end - 1)), stat{3});
- grid on;
- title(stat{1});
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{plotComparisonToMatlabFunction}
-\begin{simplechar}
-\begin{lstlisting}
-function plotComparisonToMatlabFunction(ordinaryDifferentialEquations, interval, initialValues)
- % compare results with ODE45
- odefun = @(t, x) [ ordinaryDifferentialEquations{1}(x); ordinaryDifferentialEquations{2}(x) ];
- odeoptions = odeset('RelTol', 10e-10, 'AbsTol', 10e-10);
- [~, x] = ode45(odefun, interval, initialValues, odeoptions);
- figure;
- plot(x(:, 1), x(:, 2));
- grid on;
- title('ODE45 trajectory plot (x_2 against x_1)');
-end
-\end{lstlisting}
-\end{simplechar}
-
-\section{AdamsPCMethod.m}
-\subsection{AdamsPCMethod}
-\begin{simplechar}
-\begin{lstlisting}
-function x = AdamsPCMethod(functions, initialValues, interval, stepSize)
- [x, derrivatives, explicitCoefficients, implicitCoefficients, stepCount] = initialize(functions, initialValues, interval, stepSize);
- x = adamsPcLoop(x, derrivatives, explicitCoefficients, implicitCoefficients, stepCount, functions, stepSize);
- % append arguments to output
- x = [interval(1):stepSize:(stepCount * stepSize); x];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [x, derrivatives, explicitCoefficients, implicitCoefficients, stepCount] = initialize(functions, initialValues, interval, stepSize)
- % obtain first five steps from RK4
- [x, derrivatives] = RK4(functions, initialValues, interval, stepSize, 5);
- x = x(2:end, :);
-
- % define coefficient
- explicitCoefficients = [1901, -2774, 1616, -1274, 251] / 720;
- % Constants that can be found on the Internet or in Mister Tatjewski
- % book on page 177, notice how beta(3) = 1616 instead of 2616
- % I have found on the internet different value for this parameter and
- % got better results with it so I decided to stick with it
- implicitCoefficients = [475, 1427, -798, 482, -173, 27] / 1440;
- % Constants that can be found on the Internet or in Mister Tatjewski
- % book on page 178
- % build output based on preceding values
- stepCount = ceil((interval(2) - interval(1)) / stepSize);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{adamsPcLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function x = adamsPcLoop(x, derrivatives, explicitCoefficients, implicitCoefficients, stepCount, functions, stepSize)
- for step = 6: (stepCount + 1)
- [x, derrivatives] = PECE(x, derrivatives, explicitCoefficients, implicitCoefficients, step, functions, stepSize);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{PECE}
-\begin{simplechar}
-\begin{lstlisting}
-function [x, derrivatives] = PECE(x, derrivatives, explicitCoefficients, implicitCoefficients, step, functions, stepSize)
- % P
- predictionOfX = adamsPredict(x, step, stepSize, explicitCoefficients, derrivatives);
-
- % E
- derrivativePrediction = zeros(size(functions, 1), 1);
- derrivativePrediction = adamsEvaluate(functions, predictionOfX, derrivativePrediction);
-
- % C
- x = adamsCorrect(step, functions, stepSize, implicitCoefficients, derrivatives, derrivativePrediction, x);
-
- % E
- derrivatives = adamsEvaluateTwo(functions, step, x, derrivatives);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{adamsPredict}
-\begin{simplechar}
-\begin{lstlisting}
-function predictionOfX = adamsPredict(x, step, stepSize, explicitCoefficients, derrivatives)
- % predict
- predictionOfX = x(:, step - 1);
- for equationNumber = 1 : 2
- for previous = 1:5
- predictionOfX(equationNumber) = predictionOfX(equationNumber) ...
- + stepSize * explicitCoefficients(previous) * derrivatives(equationNumber, step - previous);
- end
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{adamsEvaluate}
-\begin{simplechar}
-\begin{lstlisting}
-function derrivativePrediction = adamsEvaluate(functions, predictionOfX, derrivativePrediction)
- for equationNumber = 1:size(functions, 1)
- derrivativePrediction(equationNumber) = functions{equationNumber}(predictionOfX);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{adamsCorrect}
-\begin{simplechar}
-\begin{lstlisting}
-function x = adamsCorrect(step, functions, stepSize, implicitCoefficients, derrivatives, derrivativePrediction, x)
- x(:, step) = x(:, step - 1);
- for equationNumber = 1:size(functions, 1)
- for previous = 1:5
- x(equationNumber, step) = x(equationNumber, step) + stepSize * implicitCoefficients(previous + 1) * derrivatives(equationNumber, step - previous);
- end
- x(equationNumber, step) = x(equationNumber, step) + stepSize * implicitCoefficients(1) * derrivativePrediction(equationNumber);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{adamsEvaluateTwo}
-\begin{simplechar}
-\begin{lstlisting}
-function derrivatives = adamsEvaluateTwo(functions, step, x, derrivatives)
- for equationNumber = 1:size(functions, 1)
- derrivatives(equationNumber, step) = functions{equationNumber}(x(:, step));
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\section{QRDecomposition.m}
-\subsection{QRDecomposition}
-\begin{simplechar}
-\begin{lstlisting}
-function [Q, R, QTQInverse] = QRDecomposition(A)
- [Q, R, QTQInverse, upperLoopLimit] = initialize(A);
- [Q, R, QTQInverse] = GramSchmidtAlgorithm(A, Q, R, QTQInverse, upperLoopLimit);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [Q, R, QTQInverse, upperLoopLimit] = initialize(Matrix)
- Q = zeros(size(Matrix));
- upperLoopLimit = size(Matrix, 2);
- R = eye(upperLoopLimit);
- QTQInverse = zeros(upperLoopLimit);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{GramSchmidtAlgorithm}
-\begin{simplechar}
-\begin{lstlisting}
-function [Q, R, QTQInverse] = GramSchmidtAlgorithm(A, Q, R, QTQInverse, upperLoopLimit)
- for column = 1 : upperLoopLimit
- [Q, R, QTQInverse, A] = GramSchmidtAlgorithmOuterLoop(upperLoopLimit, A, Q, R, QTQInverse, column);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{GramSchmidtAlgorithmOuterLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [Q, R, QTQInverse, A] = GramSchmidtAlgorithmOuterLoop(upperLoopLimit, A, Q, R, QTQInverse, column)
-
- [columnDotProduct, QTQInverse, Q] = calculateColumnDotProduct(A, column, Q, QTQInverse);
- [R, A] = orthogonalizeFurther(column, A, columnDotProduct, Q, R, upperLoopLimit);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{calculateColumnDotProduct}
-\begin{simplechar}
-\begin{lstlisting}
-function [columnDotProduct, QTQInverse, Q] = calculateColumnDotProduct(A, column, Q, QTQInverse)
- Q(:, column) = A(:, column);
-
- columnDotProduct = dot(Q(:, column), Q(:, column));
- QTQInverse(column, column) = 1 / columnDotProduct;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{orthogonalizeFurther}
-\begin{simplechar}
-\begin{lstlisting}
-function [R, A] = orthogonalizeFurther(column, A, columnDotProduct, Q, R, upperLoopLimit)
- for next = (column + 1): upperLoopLimit
- R(column, next) = dot(Q(:, column), A(:, next)) / columnDotProduct;
- A(:, next) = A(:, next) - R(column, next) * Q(:, column);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\section{RK4.m}
-\subsection{RK4}
-\begin{simplechar}
-\begin{lstlisting}
-function [x, derivativesTable] = RK4(equations, initialValues, interval, stepSize, maxSteps)
- x = initialValues;
-
- derivativesTable = buildDerivatiesTable(x, equations);
-
- % Calculate stepCount
- stepCount = ceil((interval(2) - interval(1)) / stepSize);
- if nargin == 5
- stepCount = min(stepCount, maxSteps - 1);
- end % IF we include max steps in our function input
- % (nargin is number of arguments in input)
- % then choose smaller number between maxSteps and stepCount and choose
- % it for stepCount
-
- [x, derivativesTable] = rk4Loop(x, stepCount, stepSize, equations, derivativesTable);
-
-
- % append arguments to output
- x = [interval(1):stepSize:(stepCount * stepSize); x];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{buildDerivatiesTable}
-\begin{simplechar}
-\begin{lstlisting}
-function derivativesTable = buildDerivatiesTable(x, equations)
- derivativesTable = zeros(size(x));
- for eqnum = 1:size(equations, 1)
- derivativesTable(eqnum, 1) = equations{eqnum}(x(:, 1));
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{rk4Loop}
-\begin{simplechar}
-\begin{lstlisting}
-function [x, derivativesTable] = rk4Loop(x, stepCount, stepSize, equations, derivativesTable)
- for step = 1 : stepCount
- [x, derivativesTable] = rk4stepLoop(x, step, equations, stepSize, derivativesTable);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{rk4stepLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [x, derivativesTable] = rk4stepLoop(x, step, equations, stepSize, derivativesTable)
- stepValue = x(:, step);
- [x, derivativesTable] = equationsLoop(x, equations, stepValue, stepSize, step, derivativesTable);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{equationsLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [x, derivativesTable] = equationsLoop(x, equations, stepValue, stepSize, step, derivativesTable)
- for equationNumber = 1 : 2
- Phi = RK4Phi(equations{equationNumber}, stepValue, stepSize);
- x(equationNumber, step + 1) = x(equationNumber, step) + stepSize * Phi;
-
- derivativesTable(equationNumber, step + 1) = equations{equationNumber}(x(:, step + 1));
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\section{RK4Automatic.m}
-\subsection{RK4Automatic}
-\begin{simplechar}
-\begin{lstlisting}
-function [x, sizes, errors] = RK4Automatic(equations, initialValues, interval, initialStepSize, relativeEpsilon, absoluteEpsilon)
- [functionArguments, x, sizes, errors, stepSize, step, flag] = Initialize(interval, initialValues, initialStepSize);
- [functionArguments, x, sizes, errors] = RK4AutomaticLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag);
- x = [functionArguments; x];
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{Initialize}
-\begin{simplechar}
-\begin{lstlisting}
-function [functionArguments, x, sizes, errors, stepSize, step, flag] = Initialize(interval, initialValues, initialStepSize)
- functionArguments = interval(1);
- x = initialValues;
-
- sizes = double.empty();
- errors = double.empty();
-
- stepSize = initialStepSize;
- step = 0;
- flag = 1;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{RK4AutomaticLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [functionArguments, x, sizes, errors] = RK4AutomaticLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag)
- while flag
- [functionArguments, x, sizes, errors, stepSize, step, interval, flag] = insideWhileLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{insideWhileLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [functionArguments, x, sizes, errors, stepSize, step, interval, flag] = insideWhileLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag)
- [step, stepValue, x, functionArguments, flag] = calculateXandFunctionArguments(step, x, equations, stepSize, functionArguments, interval);
- if ~flag
- return;
- end
- [stepSize, errors] = calculateStepAndErrors(equations, stepValue, stepSize, x, step, relativeEpsilon, absoluteEpsilon, errors);
- sizes(step) = stepSize;
-
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{calculateXandFunctionArguments}
-\begin{simplechar}
-\begin{lstlisting}
-function [step, stepValue, x, functionArguments, flag] = calculateXandFunctionArguments(step, x, equations, stepSize, functionArguments, interval)
- [step, stepValue] = initializeSteps(step, x);
- x = equationsLoop(x, equations, stepValue, stepSize, step);
- [flag, functionArguments] = stopAlgorithm(functionArguments, stepSize, step, interval);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{calculateStepAndErrors}
-\begin{simplechar}
-\begin{lstlisting}
-function [stepSize, errors] = calculateStepAndErrors(equations, stepValue, stepSize, x, step, relativeEpsilon, absoluteEpsilon, errors)
- stepValue = calculateNextStep(equations, stepValue, stepSize);
- [stepCorrectionFactor, errors] = calculateStepCorrection(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors);
- stepSize = 0.9 * stepCorrectionFactor * stepSize;
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{initializeSteps}
-\begin{simplechar}
-\begin{lstlisting}
-function [step, stepValue] = initializeSteps(step, x)
- step = step + 1;
- stepValue = x(:, step);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{equationsLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function x = equationsLoop(x, equations, stepValue, stepSize, step)
- for equationNumber = 1 : 2
- Phi = RK4Phi(equations{equationNumber}, stepValue, stepSize);
- x(equationNumber, step + 1) = x(equationNumber, step) + stepSize * Phi;
- end
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{stopAlgorithm}
-\begin{simplechar}
-\begin{lstlisting}
-function [flag, functionArguments] = stopAlgorithm(functionArguments, stepSize, step, interval)
- functionArguments(step + 1) = functionArguments(step) + stepSize;
- if functionArguments(end) >= interval(2)
- flag = 0;
- else
- flag = 1;
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{calculateNextStep}
-\begin{simplechar}
-\begin{lstlisting}
-function stepValue = calculateNextStep(equations, stepValue, stepSize)
- for halfStep = 1 : 2
- for equationsNumber = 1:size(equations, 1)
- Phi = RK4Phi(equations{equationsNumber}, stepValue, stepSize / 2);
- stepValue(equationsNumber) = stepValue(equationsNumber) + (stepSize / 2) * Phi;
- end
- end
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{calculateStepCorrection}
-\begin{simplechar}
-\begin{lstlisting}
-function [stepCorrectionFactor, errors] = calculateStepCorrection(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors)
- stepCorrectionFactor = Inf; % Initialize stepCorrectionFactor
- [stepCorrectionFactor, errors] = calculateStepCorrectionLoop(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors, stepCorrectionFactor);
- stepCorrectionFactor = stepCorrectionFactor ^ (1/5);
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{calculateStepCorrectionLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function [stepCorrectionFactor, errors] = calculateStepCorrectionLoop(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors, stepCorrectionFactor)
- for equationsNumber = 1 : 2
- approximationError = abs(stepValue(equationsNumber) - x(equationsNumber, step + 1)) / 15;
- errors(step) = approximationError;
-
- epsilon = abs(stepValue(equationsNumber)) * relativeEpsilon + absoluteEpsilon;
- equationAlpha = epsilon / approximationError;
-
- if equationAlpha < stepCorrectionFactor
- stepCorrectionFactor = equationAlpha;
- end
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\section{backSubstitution.m}
-\subsection{backSubstitution}
-\begin{simplechar}
-\begin{lstlisting}
-function solution = backSubstitution(Matrix)
- Columns = size(Matrix, 1);
- Matrix = backSubstitutionOuterLoop(Matrix, Columns);
- % rightmost column of the Matrix is now our result
- solution = Matrix(:, size(Matrix, 2));
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{backSubstitutionOuterLoop}
-\begin{simplechar}
-\begin{lstlisting}
-function Matrix = backSubstitutionOuterLoop(Matrix, Columns)
- for k = Columns : -1 : 1
- % Diagonal coefficients of matrix need to be equal to 1
- Matrix(k, :) = Matrix(k, :) / Matrix(k, k);
- Matrix = eliminateFactors(Matrix, k);
- end
-end
-\end{lstlisting}
-\end{simplechar}
-
-\subsection{eliminateFactors}
-\begin{simplechar}
-\begin{lstlisting}
-function Matrix = eliminateFactors(Matrix, k)
- for row = (k - 1) : -1 : 1
- Matrix(row, :) = Matrix(row, :) - Matrix(k, :) * (Matrix(row, k) / Matrix(k, k));
- end
-end
-
-\end{lstlisting}
-\end{simplechar}
-
-\section{RK4Phi.m}
-\subsection{RK4Phi}
-\begin{simplechar}
-\begin{lstlisting}
-function Phi = RK4Phi(algorithm, stepValue, stepSize)
- k1 = algorithm(stepValue);
- k2 = algorithm(stepValue + 0.5 * stepSize * k1);
- k3 = algorithm(stepValue + 0.5 * stepSize * k2);
- k4 = algorithm(stepValue + stepSize * k3);
- Phi = (k1 + 2 * k2 + 2 * k3 + k4) / 6;
-end
-% calculates the Phi used in RK4 algorithms
-
-\end{lstlisting}
-\end{simplechar}
-
-
-
-
-\begin{thebibliography}{9}
-\bibitem{texbook}
-Piotr Tatjewski (2014) \emph{Numerical Methods}, Oficyna Wydawnicza Politechniki Warszawskiej
-\end{thebibliography}
-
-
+ \input{sections/01-problem}
+ \input{sections/02-theoretical-introduction}
+ \input{sections/03-results}
+ \input{sections/04-discussion-of-results}
+ \input{sections/05-a-runge-kutta-method-of-4}
+ \input{sections/06-b-runge-kutta-method-of-4}
+ \input{sections/07-results}
+ \input{sections/08-discussion-of-results}
+ \input{sections/09-functiondatapoints-m}
+ \input{sections/10-task1-m}
+ \input{sections/11-task2-m}
+ \input{sections/12-adamspcmethod-m}
+ \input{sections/13-qrdecomposition-m}
+ \input{sections/14-rk4-m}
+ \input{sections/15-rk4automatic-m}
+ \input{sections/16-backsubstitution-m}
+ \input{sections/17-rk4phi-m}
\end{document}
diff --git a/NotProgramming/ENUME/projectC/sections/01-problem.tex b/NotProgramming/ENUME/projectC/sections/01-problem.tex
new file mode 100644
index 00000000..6d1b9c7f
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/01-problem.tex
@@ -0,0 +1,36 @@
+\section{Problem}
+Given following samples:
+\begin{center}
+ \begin{tabular}{| c | c |}
+\hline
+$x_i$ & $y_i$ \\
+\hline
+-5 & -6.5743\\
+\hline
+-4 & 0.9765\\
+\hline
+-3 & 3.1026\\
+\hline
+-2 & 1.8572 \\
+\hline
+-1 & 1.3165 \\
+\hline
+0 & -0.6144 \\
+\hline
+1 & 0.1032 \\
+\hline
+2 & 0.3729 \\
+\hline
+3 & 2.5327 \\
+\hline
+4 & 7.3857 \\
+\hline
+5 & 9.4892 \\
+\hline
+
+\end{tabular}
+\end{center}
+
+We have to determine polynomial function $ y = f(x) $ that best fits this data. \\
+We will use least-square approximation using system of normal equation with QR factorization.
+
diff --git a/NotProgramming/ENUME/projectC/sections/02-theoretical-introduction.tex b/NotProgramming/ENUME/projectC/sections/02-theoretical-introduction.tex
new file mode 100644
index 00000000..14a0a030
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/02-theoretical-introduction.tex
@@ -0,0 +1,67 @@
+\section{Theoretical introduction}
+\subsection{Linear Least Squares Problem}
+We have polynomial function:
+\[ y(x) = a_nx^n + a_{n-1}x^{n-1} + \dots + a_1x^1 + a_0 \]
+where n - degree of the polynomial we use to approximate function \\
+Given matrix $\mathbf{A} \in \mathbb{R}^{m \times n} \quad (m > n)$ and vector $\mathbf{y} \in \mathbb{R}^m$ \\
+We need to find vector \^{x} such that:
+\[ \forall x \in \mathbb{R}^n \quad|| \mathbf{y} - \mathbf{A} \hat{x} ||_2 \leq || \mathbf{y} - \mathbf{A}x ||_2 \]
+$\mathbf{A}\hat{x}$ is the vector of values of the approximating function at each data point and $y$ is the vector of values of data points. \\
+We have to minimize the Euclidean norm of difference between approximation and data points. \\
+To obtain $\hat{x}$ we will calculate the derrivative of error function with respect to $b_n$ and equate it to 0. This way we will get system of equations caled \textbf{normal equations} which have unique solution in form of vector $\hat{x}$
+
+\subsection{Gram matrix and QR decomposition}
+We will use Gram's matrix since it's condition number tends to be pretty high which improves the accuracy of our solution. \\
+Gram's matrix is a matrix of set of normal equations. The simplest way to present normal equations is by using formula:
+\[ \langle \phi_i, \phi_k \rangle \myeq \sum_{j=0}^N \phi_i(x_j)fi_k(x_j) \]
+Which then leads to following matrix \textbf{A}:
+
+\[
+A = \begin{bmatrix}
+\phi_0(x_0) & \phi_1(x_0) & \dots & \phi_n(x_0) \\
+\phi_0(x_1) & \phi_1(x_1) & \dots & \phi_n(x_1) \\
+\phi_0(x_2) & \phi_1(x_2) & \dots & \phi_n(x_2) \\
+\vdots & \vdots & \vdots & \vdots \\
+\phi_0(x_N) & \phi_1(x_N) & \dots & \phi_n(x_N) \\
+\end{bmatrix}
+\]
+
+In our case we define matrix \textbf{A} as:
+\[
+A = \begin{bmatrix}
+1 & x_0 & (x_0)^2 & \dots & (x_0)^n \\
+1 & x_1 & (x_1)^2 & \dots & (x_1)^n\\
+1 & x_2 & (x_2)^2 & \dots & (x_2)^n\\
+\vdots & \vdots & \vdots & \vdots \\
+1 & x_N & (x_N)^2 & \dots & (x_N)^n\\
+\end{bmatrix}
+\]
+
+Where $x_N$ is the x-axis position for the N-th data point. Then we can express system of natural equations using A in this way:
+\[ A^Ty = (A^TA)\hat{x} \]
+
+With condition number of A equal to square root of condition number of Gram's matrix which gives us small errors. It is also usefull for QR factoization since we can rewrite it as follows:
+\[ (R^TQ^T)(QR)\hat{x} = (R^TQ^T)y \]
+Since determinant of $R \neq 0$ and $Q^TQ = I$ we can simplify aforementioned equation to:
+\[ R\hat{x} = Q^Ty \]
+And to optimize even further ahead insetead of using QR decomposition we can use faster $\tilde{Q}\tilde{R}$ decomposition:
+\[ \tilde{R}\hat{x} = (\tilde{Q}^T\tilde{Q})^{-1}(\tilde{Q}^T) \]
+This is faster since $\tilde{R}$ is an upper triangular matrix, easily solved using back-substitution.
+
+\subsection{Gram-Schmidt algorithm}
+We will use Gram-Schmidt algorithm for $\tilde{Q}\tilde{R}$ decomposition.
+Gram-Schmidt algorithm takes non-orthogonal function basis denoted as:
+\[ \phi_0, \dots, \phi_n \]
+and orthogonalizes it into orthogonal function basis denoted as:
+\[ \psi_0, \dots, \psi_n \]
+Standard Gram-Schmid algorithm looks like this:
+\[ \psi_0 = \phi_0 \]
+\[ \psi_1 = \phi_1 - \frac{\langle \psi_0, \phi_1 \rangle}{\langle \psi_0, \psi_0 \rangle} \psi_0 \]
+\[ \psi_n = \phi_n - \sum_{j = 0}^{i-1} \frac{\langle \psi_j, \phi_i \rangle}{\langle \psi_j, \psi_j \rangle} \psi_j \]
+Where $ i = 2, \dots, n $
+Then we get a very well conditioned set of normal equations:
+\[ a_0\langle \psi_0, \psi_0 \rangle = \langle f, \psi_0 \rangle \]
+\[ a_1\langle \psi_1, \psi_1 \rangle = \langle f, \psi_1 \rangle \]
+\[ \vdots \]
+\[ a_n\langle \psi_n, \psi_n \rangle = \langle f, \psi_n \rangle \]
+
diff --git a/NotProgramming/ENUME/projectC/sections/03-results.tex b/NotProgramming/ENUME/projectC/sections/03-results.tex
new file mode 100644
index 00000000..8c8d90f8
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/03-results.tex
@@ -0,0 +1,50 @@
+\section{Results}
+
+I decided to simulate polynomials up to $\mathbf{10^{th}}$ degree.
+
+\includepdf[pages=-]{10-eps-converted-to.pdf}
+\includepdf[pages=-]{11-eps-converted-to.pdf}
+\includepdf[pages=-]{12-eps-converted-to.pdf}
+\includepdf[pages=-]{13-eps-converted-to.pdf}
+\includepdf[pages=-]{14-eps-converted-to.pdf}
+\includepdf[pages=-]{15-eps-converted-to.pdf}
+\includepdf[pages=-]{16-eps-converted-to.pdf}
+\includepdf[pages=-]{17-eps-converted-to.pdf}
+\includepdf[pages=-]{18-eps-converted-to.pdf}
+\includepdf[pages=-]{19-eps-converted-to.pdf}
+\includepdf[pages=-]{110-eps-converted-to.pdf}
+\includepdf[pages=-]{111-eps-converted-to.pdf}
+
+\begin{center}
+ \begin{tabular}{| c | c | c |}
+\hline
+
+Degree & Error & Condition number of Gram's Matrix \\
+\hline
+0& 13.2040& 1\\
+\hline
+1& 9.1281& 10\\
+\hline
+2& 8.8257& 408.7796\\
+\hline
+3& 4.2365& 8.5584e+03\\
+\hline
+4& 1.5418& 3.1798e+05\\
+\hline
+5& 1.5413& 7.4675e+06\\
+\hline
+6& 1.1689& 2.8316e+08\\
+\hline
+7& 0.9345& 7.6462e+09\\
+\hline
+8& 0.8883& 3.3055e+11\\
+\hline
+9& 0.8334& 1.5167e+13\\
+\hline
+10& 6.3645e-13& 9.2930e+14\\
+\hline
+11 & 2.2390 & 8.7763e+17 \\
+\hline
+ \end{tabular}
+\end{center}
+
diff --git a/NotProgramming/ENUME/projectC/sections/04-discussion-of-results.tex b/NotProgramming/ENUME/projectC/sections/04-discussion-of-results.tex
new file mode 100644
index 00000000..a57b3679
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/04-discussion-of-results.tex
@@ -0,0 +1,11 @@
+\section{Discussion of results}
+As expected, with the increase in polynomial degree error of the solution decreased and condion number of Gram's matrix increased. The most interesting part is how for polynomial of degree \textbf{10} the error got significantly lower, $10^{-12}$ times lower than for polynomial of lower degree, with only around 100 times bigger Gram's matrix condition number, and then for polynomial of degree 11, the error become much much higher and so did Gram's matrix. I suppose that since we get 11 data points, approaching number of data points with the degree of the polynomial lowers the erorr until we have the same polynomial degree as data points at which point the error increases again.
+
+
+
+
+
+
+\chapter{Determine trajectory of the motion}
+
+
diff --git a/NotProgramming/ENUME/projectC/sections/05-a-runge-kutta-method-of-4.tex b/NotProgramming/ENUME/projectC/sections/05-a-runge-kutta-method-of-4.tex
new file mode 100644
index 00000000..de96a3fa
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/05-a-runge-kutta-method-of-4.tex
@@ -0,0 +1,38 @@
+\section{a) Runge-Kutta method of $4^{th}$ order and Adams PC}
+\subsection{Problem}
+We are given following equations:
+\[ \frac{dx_1}{dt} = x_2 + x_1(0.5 - x_1^2 - x_2^2) \]
+\[ \frac{dx_2}{dt} = -x_1 + x_2(0.5 - x_1^2 - x_2^2) \]
+
+And we have to determine the trajectory of the motion on interval $[0, 15]$ with following initial conditions:
+$ x_1(0) = 8; x_2(0) = 9 $
+In this section we will use Runge-Kutta method of $4^{th}$ order and Adams PC with different step-sizes until we find an optimal constant step size - when the decrease of the step size does not influence the solution significantly.
+
+\subsection{Theoretical Introdution}
+Determining the trajectory of the motion in this example can be mathematically described as solving a system of first order ordinary differential equations with given initical conditions. That is why we use Runge-Kutta method of order 4 which deals with exactly this kind of problem.
+\subsubsection{Runge-Kutta method of order 4}
+Any single step method are defined by the following formula, where h is a fixed step-size:
+\[ y_{n+1} = y_n + \Phi_f(x_n, y_n, h) \]
+where:
+\[ x_n = x_0 + nh \]
+\[ y(x_0) = y_0 = y_a \]
+where $y_a$ is given.
+Runge-Kutta method of order 4 - RK4 method looks like this:
+\[ y_{n+1} = y_n + \frac{1}{6}(k_1 + 2k_2+2k_3+k_4) \]
+\[ k_1 = f(x_n, y_n) \]
+\[ k_3 = f(x_n + \frac{1}{2}h, y_n + \frac{1}{2}hk_1) \]
+\[ k_2 = f(x_n + \frac{1}{2}h, y_n + \frac{1}{2}hk_2) \]
+\[ k_4 = f(x_n + h, y_n + hk_3) \]
+
+
+\subsection{Adams PC method}
+Adams method with $P_kEC_kE$ algorithm has the following form: \\
+P: \[ y_n^{[0]} = y_{n-1} + h\sum_{j=1}^k \beta_jf_{n-j} \]
+E: \[ f_n^{[0]} = f(x_n, y_n^{[0]}) \]
+C: \[ y_n = y_{n-1} + h \sum_{j=1}^k \beta_j^* f_{n-j} + h \beta_0^* f_n^{[0]}\]
+E: \[ f_n = f(x_n, y_n) \]
+
+When compared to explicit and implicit adams method PC metho has smaller absolute stability intervals than implicit method, while having significant advantage in calculations cost.
+
+
+
diff --git a/NotProgramming/ENUME/projectC/sections/06-b-runge-kutta-method-of-4.tex b/NotProgramming/ENUME/projectC/sections/06-b-runge-kutta-method-of-4.tex
new file mode 100644
index 00000000..e6539b61
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/06-b-runge-kutta-method-of-4.tex
@@ -0,0 +1,117 @@
+\section{b) Runge-Kutta method of $4^{th}$ order with variable step size automatically adjusted}
+\subsection{Problem}
+We are given following equations:
+\[ \frac{dx_1}{dt} = x_2 + x_1(0.5 - x_1^2 - x_2^2) \]
+\[ \frac{dx_2}{dt} = -x_1 + x_2(0.5 - x_1^2 - x_2^2) \]
+And we have to determine the trajectory of the motion on interval $[0, 15]$ with following initial conditions:
+$ x_1(0) = 8; x_2(0) = 9 $
+In this section we will use Runge-Kutta method of $4^{th}$ order with step size automatically adjusted by the algorithm, with error estimation made according to the step-doubling rule.
+\subsection{Theoretical Introdution}
+Since Runge-Kutta method was explained in previous task I will focus on step-doubling rule.
+Everytime we increase step size we receive less accurate results at the benefit of less calculations cost, this means that we need to have reasonable approach to setting step size to maximise accuracy and minimize calculations cost. We will use step-doubling rule in this example.
+
+\subsubsection{Error estimation using step doubling-approach}
+For every step of size $h$ we perform two additional steps of size $\frac{h}{2}$. We denote: \\
+$y_n^{1}$ as a new point obtained using the original step-size $h$ \\
+$y_n^{2}$ as a new point obtained using steps of the size $\frac{h}{2}$ \\
+$r^{(1)}$ - approximation error affter the single step $h$ \\
+$r^{(2)}$ - summed approximation errors after the two smaller steps of length $\frac{h}{2}$ each. \\
+We have: \\
+\newpage
+After a single step:
+\[ y(x_n + h) = y_n^{(1)} + \frac{r_n^{p+1}(0)}{(p+1)!}h^{p+1} + O(h^{p+2}) \]
+After a double step:
+\[ y(x_n+h) \simeq y_n^{(2)} + 2\frac{r_n^{p+1}(0)}{(p+1)!}(\frac{h}{2})^{p+1} + O(h^{p+2}) \]
+
+We evaluate unknown coefficient from the first equation $ \frac{r_n^{p+1}(0)}{(p+1)!} $ and insert it into second one:
+\[ y(x_n+h) = y_n^{(2)} + \frac{h^{p+1}}{2^p}\frac{(x_n+h) - y_n^{(1)}}{h^{p+1} + O(h^{p+2})} \]
+We continue further and receive:
+\[ y(x_n + h)(1-\frac{1}{2^p}) = y_n^{(2)}(1-\frac{1}{2^p}) + \frac{y_n^{2}}{2^p} - \frac{y_n^{(1)}}{2^p} + O(h^{p+2}) \]
+We multiply by $\frac{2^p}{2^p - 1}$ and get:
+\begin{equation}
+y(x_n+h) = y_n^{(2)} + \frac{ y_n^{(2)} - y_n^{(1)} }{ 2^p - 1 } + O(h^{p+2})
+\end{equation}
+We also obtain for first equation in a similar way:
+ \[ y(x_n+h) = y_n^{(1)} + 2^p\frac{y_n^{(2)} - y_n^{(1)}}{2^p - 1} + O(h^{p+2}) \]
+Assuming we take the main part of the error we get error estimate:
+\[ \delta_n(h) = \frac{2^p}{2^p-1}(y_n^{(2)} - y_n^{(1)}) \]
+But from the equation (2.1) we can treat expression:
+\[ \delta_n(2 \times \frac{h}{2}) = \frac{ y_n^{(2)} - y_n^{(1)}}{2^p - 1} \]
+as en estimate of the error of two consecutive steps of size $\frac{h}{2}$
+\subsubsection{Actual correction of the step size}
+In general formula for main part of the approximation error where:
+\\ $h$ - length of a step
+\[ \gamma = \frac{r_n^{(p+1)}(0)}{(p+1)!} \]
+Looks like this:
+\[ \delta_n(h) = \gamma h^{p+1} \]
+If we change step-size to $\alpha h$ then we get:
+\[ \delta_n(\alpha h) = \gamma (\alpha h)^{p+1} \]
+Then:
+\[ \delta_n(\alpha h) = \alpha^{p+1} \delta_n (h) \]
+We assume tolerance $\epsilon$:
+\[ |\delta_n(\alpha h)| = \epsilon \]
+We get:
+\[ \alpha^{p+1}|\delta_n(h)| = \epsilon \]
+Coefficient $\alpha$ for the step-size correction can be evaluated in such a way:
+\[ \alpha = (\frac{\epsilon}{|\delta_n (h)|})^{\frac{1}{p+1}} \]
+
+This method is also correct for RK4 method when $\delta_n(h) = \delta_n(2 \times \frac{h}{2}) $
+We should also take into considertaion lack of accuracy we do so by using safety factor $s$:
+\[ h_{n+1} = s \alpha h_n \]
+where $ s < 1 $
+For RK4 we use $ s \approx 0.9 $ \\
+We define accuracy parameters in such a way:
+\[ \epsilon = |y_n| \epsilon_r + \epsilon_a \]
+where $\epsilon_r$ is relative tolerance and $\epsilon_a$ is absolute tolerance. \\
+In case of set of more than on differential equations we must use worst case approach so the equations that need smallest step-size define step-size for all other equations.
+\newpage
+For RK methods we have following parameters:
+\[ \delta_n(h)_i = \frac{(y_i)_n^{(2)} - (y_i)_n^{(1)}}{2^p - 1} \]
+\[ \epsilon_i = |(y_i)_n^{(2)}| \epsilon_r + \epsilon_a \]
+\[ \alpha = \min_{1 \leq i \leq m} (\frac{\epsilon_i}{|\delta_n(h)_i}|)^{\frac{1}{p+1}} \]
+
+\subsection{Flow diagram}
+\begin{tikzpicture}[node distance=5cm]
+ \node (start) [startstop, align=center]
+ {
+ START
+ \begin{itemize}
+
+ \item Functions from task
+ \item Initial values
+ \item Initial step size
+ \item Integration interval
+ \item Absolute error
+ \item Relative error
+ \end{itemize}
+ };
+ \node (solution) [align=center, startstop, below of = start]
+ {
+ Calculate solution:
+ \[ x_{n+1} = x_n + h_n \]
+ \[ y_{n+1} = y_n + h \phi_f(x_n; y_n; h) \]
+ };
+ \node (interval) [align=center, io, below of = solution]
+ {
+ $x_n$ > integration interval?
+ };
+ \node (finish) [startstop, align=center, , right=3cm of interval] {Finish};
+ \node (error) [startstop, align=center, , below of = interval]
+ {
+ Estimate error and update step size:
+ \[ h_{n+1} = s\alpha h_n \]
+ };
+
+\path [-stealth, thick]
+ (start) edge (solution);
+\path [-stealth, thick]
+ (solution) edge (interval);
+\path [-stealth, thick]
+ (interval) edge node[anchor=south] {YES} (finish);
+\path [-stealth, thick]
+ (interval) edge node[anchor=east] {NO} (error);
+\path [-stealth, thick]
+ (error) edge [bend left = 90] (solution);
+
+\end{tikzpicture}
+
diff --git a/NotProgramming/ENUME/projectC/sections/07-results.tex b/NotProgramming/ENUME/projectC/sections/07-results.tex
new file mode 100644
index 00000000..5fc95217
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/07-results.tex
@@ -0,0 +1,13 @@
+\section{Results}
+
+\includepdf[pages=-]{20-eps-converted-to.pdf}
+\includepdf[pages=-]{21-eps-converted-to.pdf}
+\includepdf[pages=-]{22-eps-converted-to.pdf}
+\includepdf[pages=-]{23-eps-converted-to.pdf}
+\includepdf[pages=-]{24-eps-converted-to.pdf}
+\includepdf[pages=-]{25-eps-converted-to.pdf}
+\includepdf[pages=-]{26-eps-converted-to.pdf}
+\includepdf[pages=-]{27-eps-converted-to.pdf}
+\includepdf[pages=-]{28-eps-converted-to.pdf}
+\includepdf[pages=-]{29-eps-converted-to.pdf}
+
diff --git a/NotProgramming/ENUME/projectC/sections/08-discussion-of-results.tex b/NotProgramming/ENUME/projectC/sections/08-discussion-of-results.tex
new file mode 100644
index 00000000..8a3ddc6d
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/08-discussion-of-results.tex
@@ -0,0 +1,5 @@
+\section{Discussion of results}
+As we can see using RK4 algorithm with auto step size results in best solutions error-wise, trajectory plot is almost the same as the one generated by matlab function. Especially graph of step approximation error for RK4 auto step algorithm looks very good with errors as low as $10^{-7}$. Adam PC method on the other hand suffers from bigger accuarcy loss though the results are still satisfactory while requiring much less work on the coding part.
+
+\chapter{Code appendix}
+
diff --git a/NotProgramming/ENUME/projectC/sections/09-functiondatapoints-m.tex b/NotProgramming/ENUME/projectC/sections/09-functiondatapoints-m.tex
new file mode 100644
index 00000000..f8c4f4c1
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/09-functiondatapoints-m.tex
@@ -0,0 +1,23 @@
+\section{functionDataPoints.m}
+\subsection{functionDataPoints}
+\begin{simplechar}
+\begin{lstlisting}
+function dataPoints = functionDataPoints()
+ dataPoints = (-5:5)';
+ dataPoints(:, 2) = [
+ -6.5743
+ 0.9765
+ 3.1026
+ 1.8572
+ 1.3165
+ -0.6144
+ 0.1032
+ 0.3729
+ 2.5327
+ 7.3857
+ 9.4892
+ ];
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectC/sections/10-task1-m.tex b/NotProgramming/ENUME/projectC/sections/10-task1-m.tex
new file mode 100644
index 00000000..f68875a6
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/10-task1-m.tex
@@ -0,0 +1,133 @@
+\section{task1.m}
+\subsection{task1}
+\begin{simplechar}
+\begin{lstlisting}
+function task1(polynomialDegree)
+ for currentPolynomialDegree = 0 : polynomialDegree
+ dataPoints = functionDataPoints();
+ % obtain LSPSolutions of approximating polynomial
+ [LSPSolutions, error, conditionNumber] = approximate(dataPoints, currentPolynomialDegree);
+ displayInfo(currentPolynomialDegree, error, conditionNumber);
+ plotGraph(currentPolynomialDegree, dataPoints, LSPSolutions)
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{displayInfo}
+\begin{simplechar}
+\begin{lstlisting}
+function displayInfo(currentPolynomialDegree, error, conditionNumber)
+ disp("Current Polynomial Degree:");
+ disp(currentPolynomialDegree);
+ disp("Error: ");
+ disp(error);
+ disp("Condition number of Gram's Matrix: ");
+ disp(conditionNumber);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{plotGraph}
+\begin{simplechar}
+\begin{lstlisting}
+function plotGraph(currentPolynomialDegree, dataPoints, LSPSolutions)
+ figure;
+ grid on;
+ hold on;
+ plotDataPoints(currentPolynomialDegree, dataPoints);
+ plotApproximation(dataPoints, LSPSolutions);
+ hold off;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{plotDataPoints}
+\begin{simplechar}
+\begin{lstlisting}
+function plotDataPoints(currentPolynomialDegree, dataPoints)
+ title(['Polynomial approximation of the funtion using: ', num2str(currentPolynomialDegree), ' degree']);
+ scatter(dataPoints(:, 1), dataPoints(:, 2), 72, 'x');
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{plotApproximation}
+\begin{simplechar}
+\begin{lstlisting}
+function plotApproximation(dataPoints, LSPSolutions)
+ x = dataPoints(1):0.05:dataPoints(end, 1);
+ y = valueApproximationAtx(LSPSolutions, x);
+ plot(x, y);
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{approximate}
+\begin{simplechar}
+\begin{lstlisting}
+% find the approximating polynomial of the given degree
+function [LSPSolutions, error, conditionNumber] = approximate(dataPoints, polydeg)
+ % initialize A matrix
+ A = zeros(size(dataPoints, 1), polydeg + 1);
+
+ A = calculateACells(dataPoints, A);
+ LSPSolutions = solveLSP(A, dataPoints);
+
+ % Calculate error of solution
+ error = norm(dataPoints(:, 2) - A * LSPSolutions);
+ % Calculate condition number of Gram's matrix
+ GramsMatrix = A' * A;
+ conditionNumber = cond(GramsMatrix);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{calculateACells}
+\begin{simplechar}
+\begin{lstlisting}
+function Matrix = calculateACells(dataPoints, Matrix)
+ for row = 1 : size(Matrix, 1)
+ for column = 1 : size(Matrix, 2)
+ Matrix(row, column) = dataPoints(row, 1) ^ (column - 1);
+ end
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{solveLSP}
+\begin{simplechar}
+\begin{lstlisting}
+function solutions = solveLSP(Matrix, dataPoints)
+ [Q, eqsys, invqtq] = QRDecomposition(Matrix);
+ eqsys(:, end + 1) = invqtq * Q' * dataPoints(:, 2);
+ solutions = backSubstitution(eqsys);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{valueApproximationAtx}
+\begin{simplechar}
+\begin{lstlisting}
+function arrayOfValues = valueApproximationAtx(LSPSolutions, arrayOfArguments)
+ arrayOfValues = zeros(1, size(arrayOfArguments, 2));
+ arrayOfValues = calculateArrayofValues(arrayOfArguments, arrayOfValues, LSPSolutions);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{calculateArrayofValues}
+\begin{simplechar}
+\begin{lstlisting}
+function arrayOfValues = calculateArrayofValues(arrayOfArguments, arrayOfValues, LSPSolutions)
+ for x = 1 : size(arrayOfArguments, 2)
+ for i = 1 : size(LSPSolutions, 1)
+ arrayOfValues(x) = arrayOfValues(x) + LSPSolutions(i) * arrayOfArguments(x) ^ (i - 1);
+ end
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectC/sections/11-task2-m.tex b/NotProgramming/ENUME/projectC/sections/11-task2-m.tex
new file mode 100644
index 00000000..419fc70c
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/11-task2-m.tex
@@ -0,0 +1,177 @@
+\section{task2.m}
+\subsection{task2}
+\begin{simplechar}
+\begin{lstlisting}
+function task2()
+ [ordinaryDifferentialEquations, initialValues, interval, algorithms] = initialize();
+ solveAndPrintODEs(algorithms, ordinaryDifferentialEquations, initialValues, interval);
+ [result, sizes, errors] = solveAndPlotODEAutomatic(ordinaryDifferentialEquations, initialValues, interval);
+ plotStatistics(result, sizes, errors);
+ plotComparisonToMatlabFunction(ordinaryDifferentialEquations, interval, initialValues);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [ordinaryDifferentialEquations, initialValues, interval, algorithms] = initialize()
+ ordinaryDifferentialEquations = {
+ @(x) x(2) + x(1) * (0.5 - x(1)^2 - x(2)^2);
+ @(x) -x(1) + x(2) * (0.5 - x(1)^2 - x(2)^2)
+ };
+ initialValues = [8; 9];
+ interval = [0; 15];
+
+ algorithms = {
+ 'RK4 algorithm', @RK4, [0.01, 0.011];
+ 'Adams PC algorithm', @AdamsPCMethod, [0.002, 0.013]
+ };
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{solveAndPrintODEs}
+\begin{simplechar}
+\begin{lstlisting}
+function solveAndPrintODEs(algorithms, ordinaryDifferentialEquations, initialValues, interval)
+ for algorithm = 1 : 2
+ [algorithmName, algorithmFunction, stepSizes] = algorithms{algorithm, :};
+ stepResults = solveForEachStep(stepSizes, ordinaryDifferentialEquations, initialValues, interval, algorithmFunction);
+ plotAgainstTime(ordinaryDifferentialEquations, algorithmName, stepResults);
+ plotAgainst(algorithmName, stepResults);
+
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{solveForEachStep}
+\begin{simplechar}
+\begin{lstlisting}
+function stepResults = solveForEachStep(stepSizes, ordinaryDifferentialEquations, initialValues, interval, algorithmFunction)
+ stepResults = cell(size(stepSizes, 2), 3);
+ stepNames = {'Optimal Step Size', 'Slightly Larger Step Size'};
+ for stepNumber = 1:size(stepSizes, 2)
+ result = algorithmFunction(ordinaryDifferentialEquations, initialValues, interval, stepSizes(stepNumber));
+ stepResults(stepNumber, :) = {stepSizes(stepNumber), stepNames{stepNumber}, result};
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{beginPlot}
+\begin{simplechar}
+\begin{lstlisting}
+function beginPlot()
+ figure;
+ grid on;
+ hold on;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{plotAgainstTime}
+\begin{simplechar}
+\begin{lstlisting}
+function plotAgainstTime(ordinaryDifferentialEquations, algorithmName, stepResults)
+ for equationNumber = 1:size(ordinaryDifferentialEquations, 1)
+ beginPlot();
+
+ title([algorithmName, ', x_', num2str(equationNumber), ' ODE']);
+
+ for stepresult = stepResults'
+ plot(stepresult{3}(1, :), stepresult{3}(equationNumber + 1, :));
+ end
+
+ hold off;
+ legend(stepResults{:, 2});
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{plotAgainst}
+\begin{simplechar}
+\begin{lstlisting}
+function plotAgainst(algorithmName, stepResults)
+ beginPlot();
+ title([algorithmName, ' trajectory plot (x_2 compared to x_1)']);
+ for stepresult = stepResults'
+ plot(stepresult{3}(2, :), stepresult{3}(3, :));
+ end
+ hold off;
+ legend(stepResults{:, 2});
+% %print(['report/', func2str(algfunc), 'traj'], '-dpdf');
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{solveAndPlotODEAutomatic}
+\begin{simplechar}
+\begin{lstlisting}
+function [result, sizes, errors] = solveAndPlotODEAutomatic(ordinaryDifferentialEquations, initialValues, interval)
+ [result, sizes, errors] = solveRKAutomatic(ordinaryDifferentialEquations, initialValues, interval);
+ plotTrajectory(result);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{solveRKAutomatic}
+\begin{simplechar}
+\begin{lstlisting}
+function [result, sizes, errors] = solveRKAutomatic(ordinaryDifferentialEquations, initialValues, interval)
+ initialStepSize = 1e-5;
+ relativeEpsilon = 1e-9;
+ absoluteEpsilon = 1e-9;
+ [result, sizes, errors] = RK4Automatic(ordinaryDifferentialEquations, initialValues, interval, initialStepSize, relativeEpsilon, absoluteEpsilon);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{plotTrajectory}
+\begin{simplechar}
+\begin{lstlisting}
+function plotTrajectory(result)
+ figure;
+ plot(result(2, :), result(3, :));
+ grid on;
+ title('RK4 with auto step trajectory plot (x_2 against x_1)');
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{plotStatistics}
+\begin{simplechar}
+\begin{lstlisting}
+function plotStatistics(result, sizes, errors)
+ stats = {
+ "RK4 with auto step step size", "rk4sizes", sizes;
+ "RK4 with auto step approximation error", "rk4errors", errors
+ };
+ for stat = stats'
+ figure;
+ plot(result(1, 2:(end - 1)), stat{3});
+ grid on;
+ title(stat{1});
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{plotComparisonToMatlabFunction}
+\begin{simplechar}
+\begin{lstlisting}
+function plotComparisonToMatlabFunction(ordinaryDifferentialEquations, interval, initialValues)
+ % compare results with ODE45
+ odefun = @(t, x) [ ordinaryDifferentialEquations{1}(x); ordinaryDifferentialEquations{2}(x) ];
+ odeoptions = odeset('RelTol', 10e-10, 'AbsTol', 10e-10);
+ [~, x] = ode45(odefun, interval, initialValues, odeoptions);
+ figure;
+ plot(x(:, 1), x(:, 2));
+ grid on;
+ title('ODE45 trajectory plot (x_2 against x_1)');
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectC/sections/12-adamspcmethod-m.tex b/NotProgramming/ENUME/projectC/sections/12-adamspcmethod-m.tex
new file mode 100644
index 00000000..21e84ed9
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/12-adamspcmethod-m.tex
@@ -0,0 +1,120 @@
+\section{AdamsPCMethod.m}
+\subsection{AdamsPCMethod}
+\begin{simplechar}
+\begin{lstlisting}
+function x = AdamsPCMethod(functions, initialValues, interval, stepSize)
+ [x, derrivatives, explicitCoefficients, implicitCoefficients, stepCount] = initialize(functions, initialValues, interval, stepSize);
+ x = adamsPcLoop(x, derrivatives, explicitCoefficients, implicitCoefficients, stepCount, functions, stepSize);
+ % append arguments to output
+ x = [interval(1):stepSize:(stepCount * stepSize); x];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [x, derrivatives, explicitCoefficients, implicitCoefficients, stepCount] = initialize(functions, initialValues, interval, stepSize)
+ % obtain first five steps from RK4
+ [x, derrivatives] = RK4(functions, initialValues, interval, stepSize, 5);
+ x = x(2:end, :);
+
+ % define coefficient
+ explicitCoefficients = [1901, -2774, 1616, -1274, 251] / 720;
+ % Constants that can be found on the Internet or in Mister Tatjewski
+ % book on page 177, notice how beta(3) = 1616 instead of 2616
+ % I have found on the internet different value for this parameter and
+ % got better results with it so I decided to stick with it
+ implicitCoefficients = [475, 1427, -798, 482, -173, 27] / 1440;
+ % Constants that can be found on the Internet or in Mister Tatjewski
+ % book on page 178
+ % build output based on preceding values
+ stepCount = ceil((interval(2) - interval(1)) / stepSize);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{adamsPcLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function x = adamsPcLoop(x, derrivatives, explicitCoefficients, implicitCoefficients, stepCount, functions, stepSize)
+ for step = 6: (stepCount + 1)
+ [x, derrivatives] = PECE(x, derrivatives, explicitCoefficients, implicitCoefficients, step, functions, stepSize);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{PECE}
+\begin{simplechar}
+\begin{lstlisting}
+function [x, derrivatives] = PECE(x, derrivatives, explicitCoefficients, implicitCoefficients, step, functions, stepSize)
+ % P
+ predictionOfX = adamsPredict(x, step, stepSize, explicitCoefficients, derrivatives);
+
+ % E
+ derrivativePrediction = zeros(size(functions, 1), 1);
+ derrivativePrediction = adamsEvaluate(functions, predictionOfX, derrivativePrediction);
+
+ % C
+ x = adamsCorrect(step, functions, stepSize, implicitCoefficients, derrivatives, derrivativePrediction, x);
+
+ % E
+ derrivatives = adamsEvaluateTwo(functions, step, x, derrivatives);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{adamsPredict}
+\begin{simplechar}
+\begin{lstlisting}
+function predictionOfX = adamsPredict(x, step, stepSize, explicitCoefficients, derrivatives)
+ % predict
+ predictionOfX = x(:, step - 1);
+ for equationNumber = 1 : 2
+ for previous = 1:5
+ predictionOfX(equationNumber) = predictionOfX(equationNumber) ...
+ + stepSize * explicitCoefficients(previous) * derrivatives(equationNumber, step - previous);
+ end
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{adamsEvaluate}
+\begin{simplechar}
+\begin{lstlisting}
+function derrivativePrediction = adamsEvaluate(functions, predictionOfX, derrivativePrediction)
+ for equationNumber = 1:size(functions, 1)
+ derrivativePrediction(equationNumber) = functions{equationNumber}(predictionOfX);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{adamsCorrect}
+\begin{simplechar}
+\begin{lstlisting}
+function x = adamsCorrect(step, functions, stepSize, implicitCoefficients, derrivatives, derrivativePrediction, x)
+ x(:, step) = x(:, step - 1);
+ for equationNumber = 1:size(functions, 1)
+ for previous = 1:5
+ x(equationNumber, step) = x(equationNumber, step) + stepSize * implicitCoefficients(previous + 1) * derrivatives(equationNumber, step - previous);
+ end
+ x(equationNumber, step) = x(equationNumber, step) + stepSize * implicitCoefficients(1) * derrivativePrediction(equationNumber);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{adamsEvaluateTwo}
+\begin{simplechar}
+\begin{lstlisting}
+function derrivatives = adamsEvaluateTwo(functions, step, x, derrivatives)
+ for equationNumber = 1:size(functions, 1)
+ derrivatives(equationNumber, step) = functions{equationNumber}(x(:, step));
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectC/sections/13-qrdecomposition-m.tex b/NotProgramming/ENUME/projectC/sections/13-qrdecomposition-m.tex
new file mode 100644
index 00000000..08da6fa3
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/13-qrdecomposition-m.tex
@@ -0,0 +1,69 @@
+\section{QRDecomposition.m}
+\subsection{QRDecomposition}
+\begin{simplechar}
+\begin{lstlisting}
+function [Q, R, QTQInverse] = QRDecomposition(A)
+ [Q, R, QTQInverse, upperLoopLimit] = initialize(A);
+ [Q, R, QTQInverse] = GramSchmidtAlgorithm(A, Q, R, QTQInverse, upperLoopLimit);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [Q, R, QTQInverse, upperLoopLimit] = initialize(Matrix)
+ Q = zeros(size(Matrix));
+ upperLoopLimit = size(Matrix, 2);
+ R = eye(upperLoopLimit);
+ QTQInverse = zeros(upperLoopLimit);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{GramSchmidtAlgorithm}
+\begin{simplechar}
+\begin{lstlisting}
+function [Q, R, QTQInverse] = GramSchmidtAlgorithm(A, Q, R, QTQInverse, upperLoopLimit)
+ for column = 1 : upperLoopLimit
+ [Q, R, QTQInverse, A] = GramSchmidtAlgorithmOuterLoop(upperLoopLimit, A, Q, R, QTQInverse, column);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{GramSchmidtAlgorithmOuterLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [Q, R, QTQInverse, A] = GramSchmidtAlgorithmOuterLoop(upperLoopLimit, A, Q, R, QTQInverse, column)
+
+ [columnDotProduct, QTQInverse, Q] = calculateColumnDotProduct(A, column, Q, QTQInverse);
+ [R, A] = orthogonalizeFurther(column, A, columnDotProduct, Q, R, upperLoopLimit);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{calculateColumnDotProduct}
+\begin{simplechar}
+\begin{lstlisting}
+function [columnDotProduct, QTQInverse, Q] = calculateColumnDotProduct(A, column, Q, QTQInverse)
+ Q(:, column) = A(:, column);
+
+ columnDotProduct = dot(Q(:, column), Q(:, column));
+ QTQInverse(column, column) = 1 / columnDotProduct;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{orthogonalizeFurther}
+\begin{simplechar}
+\begin{lstlisting}
+function [R, A] = orthogonalizeFurther(column, A, columnDotProduct, Q, R, upperLoopLimit)
+ for next = (column + 1): upperLoopLimit
+ R(column, next) = dot(Q(:, column), A(:, next)) / columnDotProduct;
+ A(:, next) = A(:, next) - R(column, next) * Q(:, column);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectC/sections/14-rk4-m.tex b/NotProgramming/ENUME/projectC/sections/14-rk4-m.tex
new file mode 100644
index 00000000..143f3114
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/14-rk4-m.tex
@@ -0,0 +1,74 @@
+\section{RK4.m}
+\subsection{RK4}
+\begin{simplechar}
+\begin{lstlisting}
+function [x, derivativesTable] = RK4(equations, initialValues, interval, stepSize, maxSteps)
+ x = initialValues;
+
+ derivativesTable = buildDerivatiesTable(x, equations);
+
+ % Calculate stepCount
+ stepCount = ceil((interval(2) - interval(1)) / stepSize);
+ if nargin == 5
+ stepCount = min(stepCount, maxSteps - 1);
+ end % IF we include max steps in our function input
+ % (nargin is number of arguments in input)
+ % then choose smaller number between maxSteps and stepCount and choose
+ % it for stepCount
+
+ [x, derivativesTable] = rk4Loop(x, stepCount, stepSize, equations, derivativesTable);
+
+
+ % append arguments to output
+ x = [interval(1):stepSize:(stepCount * stepSize); x];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{buildDerivatiesTable}
+\begin{simplechar}
+\begin{lstlisting}
+function derivativesTable = buildDerivatiesTable(x, equations)
+ derivativesTable = zeros(size(x));
+ for eqnum = 1:size(equations, 1)
+ derivativesTable(eqnum, 1) = equations{eqnum}(x(:, 1));
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{rk4Loop}
+\begin{simplechar}
+\begin{lstlisting}
+function [x, derivativesTable] = rk4Loop(x, stepCount, stepSize, equations, derivativesTable)
+ for step = 1 : stepCount
+ [x, derivativesTable] = rk4stepLoop(x, step, equations, stepSize, derivativesTable);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{rk4stepLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [x, derivativesTable] = rk4stepLoop(x, step, equations, stepSize, derivativesTable)
+ stepValue = x(:, step);
+ [x, derivativesTable] = equationsLoop(x, equations, stepValue, stepSize, step, derivativesTable);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{equationsLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [x, derivativesTable] = equationsLoop(x, equations, stepValue, stepSize, step, derivativesTable)
+ for equationNumber = 1 : 2
+ Phi = RK4Phi(equations{equationNumber}, stepValue, stepSize);
+ x(equationNumber, step + 1) = x(equationNumber, step) + stepSize * Phi;
+
+ derivativesTable(equationNumber, step + 1) = equations{equationNumber}(x(:, step + 1));
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectC/sections/15-rk4automatic-m.tex b/NotProgramming/ENUME/projectC/sections/15-rk4automatic-m.tex
new file mode 100644
index 00000000..dfc570fb
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/15-rk4automatic-m.tex
@@ -0,0 +1,159 @@
+\section{RK4Automatic.m}
+\subsection{RK4Automatic}
+\begin{simplechar}
+\begin{lstlisting}
+function [x, sizes, errors] = RK4Automatic(equations, initialValues, interval, initialStepSize, relativeEpsilon, absoluteEpsilon)
+ [functionArguments, x, sizes, errors, stepSize, step, flag] = Initialize(interval, initialValues, initialStepSize);
+ [functionArguments, x, sizes, errors] = RK4AutomaticLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag);
+ x = [functionArguments; x];
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{Initialize}
+\begin{simplechar}
+\begin{lstlisting}
+function [functionArguments, x, sizes, errors, stepSize, step, flag] = Initialize(interval, initialValues, initialStepSize)
+ functionArguments = interval(1);
+ x = initialValues;
+
+ sizes = double.empty();
+ errors = double.empty();
+
+ stepSize = initialStepSize;
+ step = 0;
+ flag = 1;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{RK4AutomaticLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [functionArguments, x, sizes, errors] = RK4AutomaticLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag)
+ while flag
+ [functionArguments, x, sizes, errors, stepSize, step, interval, flag] = insideWhileLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{insideWhileLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [functionArguments, x, sizes, errors, stepSize, step, interval, flag] = insideWhileLoop(functionArguments, x, sizes, errors, stepSize, step, equations, relativeEpsilon, absoluteEpsilon, interval, flag)
+ [step, stepValue, x, functionArguments, flag] = calculateXandFunctionArguments(step, x, equations, stepSize, functionArguments, interval);
+ if ~flag
+ return;
+ end
+ [stepSize, errors] = calculateStepAndErrors(equations, stepValue, stepSize, x, step, relativeEpsilon, absoluteEpsilon, errors);
+ sizes(step) = stepSize;
+
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{calculateXandFunctionArguments}
+\begin{simplechar}
+\begin{lstlisting}
+function [step, stepValue, x, functionArguments, flag] = calculateXandFunctionArguments(step, x, equations, stepSize, functionArguments, interval)
+ [step, stepValue] = initializeSteps(step, x);
+ x = equationsLoop(x, equations, stepValue, stepSize, step);
+ [flag, functionArguments] = stopAlgorithm(functionArguments, stepSize, step, interval);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{calculateStepAndErrors}
+\begin{simplechar}
+\begin{lstlisting}
+function [stepSize, errors] = calculateStepAndErrors(equations, stepValue, stepSize, x, step, relativeEpsilon, absoluteEpsilon, errors)
+ stepValue = calculateNextStep(equations, stepValue, stepSize);
+ [stepCorrectionFactor, errors] = calculateStepCorrection(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors);
+ stepSize = 0.9 * stepCorrectionFactor * stepSize;
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{initializeSteps}
+\begin{simplechar}
+\begin{lstlisting}
+function [step, stepValue] = initializeSteps(step, x)
+ step = step + 1;
+ stepValue = x(:, step);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{equationsLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function x = equationsLoop(x, equations, stepValue, stepSize, step)
+ for equationNumber = 1 : 2
+ Phi = RK4Phi(equations{equationNumber}, stepValue, stepSize);
+ x(equationNumber, step + 1) = x(equationNumber, step) + stepSize * Phi;
+ end
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{stopAlgorithm}
+\begin{simplechar}
+\begin{lstlisting}
+function [flag, functionArguments] = stopAlgorithm(functionArguments, stepSize, step, interval)
+ functionArguments(step + 1) = functionArguments(step) + stepSize;
+ if functionArguments(end) >= interval(2)
+ flag = 0;
+ else
+ flag = 1;
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{calculateNextStep}
+\begin{simplechar}
+\begin{lstlisting}
+function stepValue = calculateNextStep(equations, stepValue, stepSize)
+ for halfStep = 1 : 2
+ for equationsNumber = 1:size(equations, 1)
+ Phi = RK4Phi(equations{equationsNumber}, stepValue, stepSize / 2);
+ stepValue(equationsNumber) = stepValue(equationsNumber) + (stepSize / 2) * Phi;
+ end
+ end
+end
+
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{calculateStepCorrection}
+\begin{simplechar}
+\begin{lstlisting}
+function [stepCorrectionFactor, errors] = calculateStepCorrection(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors)
+ stepCorrectionFactor = Inf; % Initialize stepCorrectionFactor
+ [stepCorrectionFactor, errors] = calculateStepCorrectionLoop(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors, stepCorrectionFactor);
+ stepCorrectionFactor = stepCorrectionFactor ^ (1/5);
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{calculateStepCorrectionLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function [stepCorrectionFactor, errors] = calculateStepCorrectionLoop(stepValue, x, step, relativeEpsilon, absoluteEpsilon, errors, stepCorrectionFactor)
+ for equationsNumber = 1 : 2
+ approximationError = abs(stepValue(equationsNumber) - x(equationsNumber, step + 1)) / 15;
+ errors(step) = approximationError;
+
+ epsilon = abs(stepValue(equationsNumber)) * relativeEpsilon + absoluteEpsilon;
+ equationAlpha = epsilon / approximationError;
+
+ if equationAlpha < stepCorrectionFactor
+ stepCorrectionFactor = equationAlpha;
+ end
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectC/sections/16-backsubstitution-m.tex b/NotProgramming/ENUME/projectC/sections/16-backsubstitution-m.tex
new file mode 100644
index 00000000..cfd15a41
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/16-backsubstitution-m.tex
@@ -0,0 +1,38 @@
+\section{backSubstitution.m}
+\subsection{backSubstitution}
+\begin{simplechar}
+\begin{lstlisting}
+function solution = backSubstitution(Matrix)
+ Columns = size(Matrix, 1);
+ Matrix = backSubstitutionOuterLoop(Matrix, Columns);
+ % rightmost column of the Matrix is now our result
+ solution = Matrix(:, size(Matrix, 2));
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{backSubstitutionOuterLoop}
+\begin{simplechar}
+\begin{lstlisting}
+function Matrix = backSubstitutionOuterLoop(Matrix, Columns)
+ for k = Columns : -1 : 1
+ % Diagonal coefficients of matrix need to be equal to 1
+ Matrix(k, :) = Matrix(k, :) / Matrix(k, k);
+ Matrix = eliminateFactors(Matrix, k);
+ end
+end
+\end{lstlisting}
+\end{simplechar}
+
+\subsection{eliminateFactors}
+\begin{simplechar}
+\begin{lstlisting}
+function Matrix = eliminateFactors(Matrix, k)
+ for row = (k - 1) : -1 : 1
+ Matrix(row, :) = Matrix(row, :) - Matrix(k, :) * (Matrix(row, k) / Matrix(k, k));
+ end
+end
+
+\end{lstlisting}
+\end{simplechar}
+
diff --git a/NotProgramming/ENUME/projectC/sections/17-rk4phi-m.tex b/NotProgramming/ENUME/projectC/sections/17-rk4phi-m.tex
new file mode 100644
index 00000000..3aff1ca1
--- /dev/null
+++ b/NotProgramming/ENUME/projectC/sections/17-rk4phi-m.tex
@@ -0,0 +1,25 @@
+\section{RK4Phi.m}
+\subsection{RK4Phi}
+\begin{simplechar}
+\begin{lstlisting}
+function Phi = RK4Phi(algorithm, stepValue, stepSize)
+ k1 = algorithm(stepValue);
+ k2 = algorithm(stepValue + 0.5 * stepSize * k1);
+ k3 = algorithm(stepValue + 0.5 * stepSize * k2);
+ k4 = algorithm(stepValue + stepSize * k3);
+ Phi = (k1 + 2 * k2 + 2 * k3 + k4) / 6;
+end
+% calculates the Phi used in RK4 algorithms
+
+\end{lstlisting}
+\end{simplechar}
+
+
+
+
+\begin{thebibliography}{9}
+\bibitem{texbook}
+Piotr Tatjewski (2014) \emph{Numerical Methods}, Oficyna Wydawnicza Politechniki Warszawskiej
+\end{thebibliography}
+
+
diff --git a/NotProgramming/MOM/report_one.tex b/NotProgramming/MOM/report_one.tex
index a6cfa374..4bc84d51 100644
--- a/NotProgramming/MOM/report_one.tex
+++ b/NotProgramming/MOM/report_one.tex
@@ -12,793 +12,8 @@
\begin{document}
\maketitle
-\section{Zadanie 1. Sieć przepływowa}
-
-\subsection{Model sieciowy}
-\paragraph{Problem do rozwiązania}
-Należy rozwiązać problem najtańszego przepływu \\
-\begin{figure}[htb]
-\caption{Koszty transportowe i przepustowości na poszczególnych odcinkach}
-\begin{center}
-\begin{tabular}{ | c | c | c | c | c | c | }
-\hline
- & D & E & F & G & H \\
- \hline
- A & 4, 15 & 2, 10 & - & - & -\\
- \hline
- B & 4, 4 & 3, 9 & - & 8, 9 & - \\
- \hline
- C & 2, 20 & 6, 10 & - & - & - \\
- \hline
- D & - & - & 3, 10 & 7, 3 & 2, 2 \\
- \hline
- E & 5, 20 & - & 7, 5 & 6, 5 & 3, 5 \\
- \hline
-\end{tabular}
-\end{center}
-\end{figure}
-\begin{figure}[htb]
-\caption{Zdolności wydobywcze kopalń (w tys. ton)}
-\begin{center}
-\begin{tabular}{ | c | c |}
-\hline
- $W_A$ & 10 \\
- \hline
-$W_B$ & 13 \\
- \hline
- $W_C$ & 17 \\
- \hline
-\end{tabular}
-\end{center}
-\end{figure}
-\begin{figure}[htb]
-\caption{Średnie zużycie dobowe węgla przez elektronie (w tys. ton)}
-\begin{center}
-\begin{tabular}{ | c | c |}
-\hline
- $Z_F$ & 15 \\
- \hline
-$Z_G$ & 13 \\
- \hline
- $Z_H$ & 7 \\
- \hline
-\end{tabular}
-\end{center}
-\end{figure}
-\paragraph{Sformułowanie}
-Matematyczne sformułowanie zadania:
-\begin{enumerate}
-\item Parametry \\
-s - źródło \\
-B - Budynki (kopalnie, stacje, elektrownie) \\
-K - kopalnie \\
-$c_{ij}$ - koszt transportu z budynku i do budynku j ($c_{sk}$ = 0) \\
-$W_k$ - zdolność wydobywcza kopalni k [w tonach] \\
-$p_{ij}$ - przepustowość transportu z budynku i do budynku j [w tonach] ($u_{sk}$ = $W_k$) \\
-E - elektrownie \\
-$Z_e$ - średnie zużycie dobowe przez elektrownię e [w tonach] \\
-\item Zmienne decyzyjne
-$f_{ij}$ - przepływ transportu z budynku i do obiektu j \\
-\item Funkcja celu
-\begin{align*}
- Q &= \min\left(\sum_{(i, j) \in B \backslash \{s\}} c_{ij} f_{ij}\right) \\
- &= \min(4f_{AD} + 2f_{AE} + 4f_{BD} + 3f_{BE} + 8f_{BG} + 2f_{CD} \\
- &\quad + 6f_{CE} + 3f_{DF} + 7f_{DG} + 2f_{DH} + 5f_{ED} + 7f_{EF} \\
- &\quad + 6f_{EG} + 3f_{EH})
-\end{align*}
-
-\item Ograniczenia
-\begin{equation}
- 0 \leq f_{sk} \leq W_k, \; k \in K = \{A, B, C\}
-\end{equation}
-\begin{equation}
- f_{si} = 0, \; i \in B \backslash K
-\end{equation}
-\begin{equation}
- f_{is} = 0, \; i \in B
-\end{equation}
-\begin{equation}
- 0 \leq f_{ij} \leq p_{uj}, \; (i, j) \in B \backslash \{s\}
-\end{equation}
-\begin{equation}
- f_{is} = 0, \; i \in B
-\end{equation}
-\begin{equation}
- \sum_{b \in B} f_{be} \ge Z_e, \; e \in E = \{F, G, H\}
-\end{equation}
-\begin{equation}
- \sum_{i \in B \backslash \{ s \} } f_{bi} \leq \sum_{j \in B} f_{bn}, \; b \in B \backslash \{s\}
-\end{equation}
-
-\end{enumerate}
-\paragraph{Narysowanie modelu}
-\includepdf[pages=-]{1flow.pdf}
-
-\subsection{Rozwiązanie}
-\paragraph{Zadanie programowania liniowego}
-
-\begin{lstlisting}[caption= plik dat]
-data;
-
-set BudynkiNaStart := s, A, B, C, D, E, F, G, H;
-set Budynki := A, B, C, D, E, F, G, H;
-set Elektrownie := F, G, H;
-
-param Z := F 15 G 13 H 7;
-
-param p :=
-s A 10 s B 13 s C 17 s D 0 s E 0 s F 0 s G 0 s H 0
-A A 0 A B 0 A C 0 A D 15 A E 10 A F 0 A G 0 A H 0
-B A 0 B B 0 B C 0 B D 4 B E 9 B F 0 B G 9 B H 0
-C A 0 C B 0 C C 0 C D 20 C E 10 C F 0 C G 0 C H 0
-D A 0 D B 0 D C 0 D D 0 D E 0 D F 10 D G 3 D H 2
-E A 0 E B 0 E C 0 E D 20 E E 0 E F 5 E G 5 E H 5
-F A 0 F B 0 F C 0 F D 0 F E 0 F F 0 F G 0 F H 0
-G A 0 G B 0 G C 0 G D 0 G E 0 G F 0 G G 0 G H 0
-H A 0 H B 0 H C 0 H D 0 H E 0 H F 0 H G 0 H H 0;
-
-param c :=
-s A 0 s B 0 s C 0 s D 0 s E 0 s F 0 s G 0 s H 0
-A A 0 A B 0 A C 0 A D 4 A E 2 A F 0 A G 0 A H 0
-B A 0 B B 0 B C 0 B D 4 B E 3 B F 0 B G 8 B H 0
-C A 0 C B 0 C C 0 C D 2 C E 6 C F 0 C G 0 C H 0
-D A 0 D B 0 D C 0 D D 0 D E 0 D F 3 D G 7 D H 2
-E A 0 E B 0 E C 0 E D 5 E E 0 E F 7 E G 6 E H 3
-F A 0 F B 0 F C 0 F D 0 F E 0 F F 0 F G 0 F H 0
-G A 0 G B 0 G C 0 G D 0 G E 0 G F 0 G G 0 G H 0
-H A 0 H B 0 H C 0 H D 0 H E 0 H F 0 H G 0 H H 0;
-
-end;
-\end{lstlisting}
-\begin{lstlisting}[caption= plik mod]
-set BudynkiNaStart;
-set Budynki;
-set Elektrownie;
-
-param Z{e in Elektrownie};
-param p{i in BudynkiNaStart, j in Budynki};
-param c{i in BudynkiNaStart, j in Budynki};
-
-var f{i in BudynkiNaStart, j in Budynki}, >= 0;
-
-minimize Q: sum {i in Budynki, j in Budynki} c[i,j] * f[i,j];
-
-subject to
- Ograniczenie_jeden{i in BudynkiNaStart, j in Budynki}:
- f[i,j] >= 0;
- Ograniczenie_dwa{i in BudynkiNaStart, j in Budynki}:
- f[i,j] <= p[i,j];
- Ograniczenie_trzy{e in Elektrownie}:
- sum {n in BudynkiNaStart} f[n,e] >= Z[e];
- Ograniczenie_cztery{n in Budynki}:
- sum {i in Budynki} f[n,i] <= sum {j in BudynkiNaStart} f[j,n];
-
-solve;
-display {i in Budynki, j in Budynki: f[i,j] > 0}: f[i,j];
-display: Q;
-\end{lstlisting}
-\paragraph{Wynik}
-\begin{lstlisting}[caption=Wynik z glpk]
-f[A,E].val = 10
-f[B,E].val = 4
-f[B,G].val = 9
-f[C,D].val = 12
-f[D,F].val = 10
-f[D,H].val = 2
-f[E,F].val = 5
-f[E,G].val = 4
-f[E,H].val = 5
-Q.val = 236
-\end{lstlisting}
-
-\begin{figure}[htb]
-\caption{Plan dostaw węgla}
-\begin{center}
-\begin{tabular}{ | c | c | c | c | c | c | }
-\hline
- & D & E & F & G & H \\
- \hline
- A & 10 & - & - & - & -\\
- \hline
- B & 0 & 4 & - & 9 & - \\
- \hline
- C & 12 & - & - & - & - \\
- \hline
- D & - & - & 10 & - & 2 \\
- \hline
- E & - & - & 5 & 4 & 5 \\
- \hline
-\end{tabular}
-\end{center}
-\end{figure}
-
-\[ Q = 236 \]
-
-\subsection{Wąskie gardło}
-Następny szukamy przekroju o jak najmniejszej przepustowości \\
-W tym celu usunęliśmy parametry dotyczące średniego zużycia dobowego oraz kosztów transportu i zostawiliśmy wyłącznie przepustowość
-\begin{lstlisting}[caption= plik dat]
-data;
-
-set BudynkiNaStart := s, A, B, C, D, E, F, G, H;
-set Budynki := A, B, C, D, E, F, G, H;
-set Elektrownie := F, G, H;
-
-param p :=
-s A 10 s B 13 s C 17 s D 0 s E 0 s F 0 s G 0 s H 0
-A A 0 A B 0 A C 0 A D 15 A E 10 A F 0 A G 0 A H 0
-B A 0 B B 0 B C 0 B D 4 B E 9 B F 0 B G 9 B H 0
-C A 0 C B 0 C C 0 C D 20 C E 10 C F 0 C G 0 C H 0
-D A 0 D B 0 D C 0 D D 0 D E 0 D F 10 D G 3 D H 2
-E A 0 E B 0 E C 0 E D 20 E E 0 E F 5 E G 5 E H 5
-F A 0 F B 0 F C 0 F D 0 F E 0 F F 0 F G 0 F H 0
-G A 0 G B 0 G C 0 G D 0 G E 0 G F 0 G G 0 G H 0
-H A 0 H B 0 H C 0 H D 0 H E 0 H F 0 H G 0 H H 0;
-
-end;
-\end{lstlisting}
-\begin{lstlisting}[caption= plik mod]
-set BudynkiNaStart;
-set Budynki;
-set Elektrownie;
-
-param p{i in BudynkiNaStart, j in Budynki};
-
-var f{i in BudynkiNaStart, j in Budynki}, >= 0;
-
-maximize Q: sum {i in Budynki, e in Elektrownie} f[i,e];
-
-subject to
- Ograniczenie_jeden{i in BudynkiNaStart, j in Budynki}:
- f[i,j] >= 0;
- Ograniczenie_dwa{i in BudynkiNaStart, j in Budynki}:
- f[i,j] <= p[i,j];
- Ograniczenie_trzy{n in Budynki}:
- sum {i in Budynki} f[n,i] <= sum {j in BudynkiNaStart} f[j,n];
-
-solve;
-display {i in Budynki, j in Budynki: f[i,j] > 0}: f[i,j];
-display: Q;
-\end{lstlisting}
-
-\paragraph{Wyniki}
-\begin{lstlisting}[caption=Wynik z glpk]
-f[A,D].val = 9
-f[A,E].val = 1
-f[B,E].val = 4
-f[B,G].val = 9
-f[C,D].val = 6
-f[C,E].val = 10
-f[D,F].val = 10
-f[D,G].val = 3
-f[D,H].val = 2
-f[E,F].val = 5
-f[E,G].val = 5
-f[E,H].val = 5
-Q.val = 39
-\end{lstlisting}
-
-\begin{figure}[htb]
-\caption{Wyniki poszukiwań wąskiego gardła}
-\begin{center}
-\begin{tabular}{ | c | c | c | c | c | c | }
-\hline
- & D & E & F & G & H \\
- \hline
- A & 9 & 1 & - & - & -\\
- \hline
- B & - & 4 & - & 9 & - \\
- \hline
- C & 6 & 10 & - & - & - \\
- \hline
- D & - & - & 10 & 3 & 2 \\
- \hline
- E & - & - & 5 & 5 & 5 \\
- \hline
-\end{tabular}
-\end{center}
-\end{figure}
-
-\[ Q = 39 \]
-
-\includepdf[pages=-]{flow12.pdf}
-
-\paragraph{Wnioski}
-Następujące przepływy są zbyt niskie w porównaniu do przepustowości:
-\[ p_{AD} = 9 \le 15 \]
-\[ p_{AE} = 1 \le 10 \]
-\[ p_{BE} = 4 \le 9 \]
-\[ p_{CD} = 6 \le 20 \]
-Zwiększenie przepływów do poziomu maksymalnej przepustowości zwiększyło by wydajność sieci
-
-
-
-\section{Zadanie 2. Zadanie przydziału}
-\subsection{Zadanie 2.1 Planowanie realizacji portfela przy ograniczonych kompetencjach}
-\begin{figure}[htb]
-\caption{Kompetencje zespołów}
-\begin{center}
-\begin{tabular}{ | c | c | c | c | c | c | c | }
-\hline
- & A & B & C & D & E & F \\
- \hline
- 1 & - & X & - & X & X & - \\
- \hline
- 2 & - & X & X & - & X & - \\
- \hline
- 3 & X & - & - & X & - & X \\
- \hline
- 4 & X & - & X & - & - & X \\
- \hline
- 5 & - & X & - & - & X & X \\
- \hline
- 6 & X & - & X & X & - & - \\
- \hline
-\end{tabular}
-\end{center}
-\end{figure}
-\subsubsection{Problem do rozwiązania}
-\paragraph{Sformułowanie}
-Matematyczne sformułowanie zadania:
-\begin{enumerate}
-\item Parametry \\
-s - źródło \\
-w - wyjście \\
-N - węzły (N = {s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F})
-P - projekty (P = {1, 2, 3, 4, 5, 6} $\subseteq$ N)
-Z - zespoły (Z = {A, B, C, D, E, F} $\subseteq$ N)
-$u_{ij}$ - przepustowość pomiędzy węzłem i a węzłem j
-\item Zmienne decyzyjne
-$f_{ij}$ - przepływ między węzłem i a węzłem j
-\item Funkcja celu
-\begin{align*}
- Q &= \max\left(\sum_{p \in P} f_{pt} \right) \\
- &= \max(f_{1t} + f_{2t} + f_{3t} + f_{4t} + f{5t} + f_{6t})
-\end{align*}
-
-\item Ograniczenia
-\setcounter{equation}{0}
-\begin{equation}
-0 \leq f_{ij} \leq 1, (i, j) \in N
-\end{equation}
-\begin{equation}
-0 \leq f_{zp} \leq u_{zp}, z \in Z, p \in P
-\end{equation}
-\begin{equation}
-f_{si} = 0, i \in \{ s, t, 1, 2, 3, 4, 5, 6 \}
-\end{equation}
-\begin{equation}
-f_{is} = 0, i \in N
-\end{equation}
-\begin{equation}
-f_{ti} = 0, i \in N
-\end{equation}
-\begin{equation}
-f_{it} = 0, i \in \{s, t, A, B, C, D, E, F\}
-\end{equation}
-\begin{equation}
-\sum_{z \in Z} f_{zp} = 1, p \in P = \{ 1, 2, 3, 4, 5, 6 \}
-\end{equation}
-
-\begin{equation}
-\sum_{p \in P} f_{zp} = 1, z \in Z = \{ A, B, C, D, E, F \}
-\end{equation}
-
-\begin{equation}
-\sum_{i \in N \backslash \{s\}} f_{ni} = \sum_{j \in N \backslash \{t\}} f_{jn}, n \in N \backslash \{ s, t \}
-\end{equation}
-
-
-
-\end{enumerate}
-
-\paragraph{Model sieciowy rysunek}
-\includepdf[pages=-]{flowchart21.pdf}
-\paragraph{Rozwiazanie}
-\begin{lstlisting}[caption= plik dat]
-data;
-
-set Wyjscie := t;
-set Wezly := 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set StartWezly := s, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set WyjscieWezly := t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set StartWyjscieWezly := s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set Projekty := 1, 2, 3, 4, 5, 6;
-set Zespoly := A, B, C, D, E, F;
-
-param u :=
-A 1 0 A 2 0 A 3 1 A 4 1 A 5 0 A 6 1
-B 1 1 B 2 1 B 3 0 B 4 0 B 5 1 B 6 0
-C 1 1 C 2 0 C 3 1 C 4 0 C 5 0 C 6 1
-D 1 1 D 2 0 D 3 1 D 4 0 D 5 0 D 6 1
-E 1 1 E 2 1 E 3 0 E 4 0 E 5 1 E 6 0
-F 1 0 F 2 0 F 3 1 F 4 1 F 5 1 F 6 0;
-
-end;
-\end{lstlisting}
-\begin{lstlisting}[caption= plik mod]
-set Wyjscie;
-set Wezly;
-set StartWezly;
-set WyjscieWezly;
-set StartWyjscieWezly;
-set Projekty;
-set Zespoly;
-
-param u{z in Zespoly, p in Projekty};
-
-var f{i in StartWyjscieWezly, j in StartWyjscieWezly}, >= 0;
-
-maximize Q: sum {p in Projekty, t in Wyjscie} f[p,t];
-
- Ograniczeni_jeden{i in StartWyjscieWezly, j in StartWyjscieWezly}:
- f[i,j] >= 0;
- Ograniczeni_dwa{i in StartWyjscieWezly, j in StartWyjscieWezly}:
- f[i,j] <= 1;
- Ograniczeni_trzy{p in Projekty, z in Zespoly}:
- f[z,p] <= u[z,p];
- Ograniczeni_cztery{p in Projekty}:
- sum {z in Zespoly} f[z,p] = 1;
- Ograniczeni_piec{z in Zespoly}:
- sum {p in Projekty} f[z,p] = 1;
- Ograniczeni_szesc{n in Wezly}:
- sum {i in WyjscieWezly} f[n,i] = sum {j in StartWezly} f[j,n];
- solve;
-display {i in Wezly, j in Wezly: f[i,j] > 0}: f[i,j];
-display: Q;
-
-
-\end{lstlisting}
-\paragraph{Przydział zespołów do projektów}
-\begin{lstlisting}[caption=wynik z glpk]
-f[A,6].val = 1
-f[B,5].val = 1
-f[C,1].val = 1
-f[D,3].val = 1
-f[E,2].val = 1
-f[F,4].val = 1
-Q.val = 6
-\end{lstlisting}
-Wyniki: \\
-Projekt numer \textbf{1} zostanie przydzielony zespołowi \textbf{C} \\
-Projekt numer \textbf{2} zostanie przydzielony zespołowi \textbf{E} \\
-Projekt numer \textbf{3} zostanie przydzielony zespołowi \textbf{D} \\
-Projekt numer \textbf{4} zostanie przydzielony zespołowi \textbf{F} \\
-Projekt numer \textbf{5} zostanie przydzielony zespołowi \textbf{B} \\
-Projekt numer \textbf{6} zostanie przydzielony zespołowi \textbf{A} \\
-\subsection{Zadanie 2.2 Minimalizacja kosztów realizacji projektów}
-\paragraph{Problem do rozwiązania}
-\begin{figure}[htb]
-\caption{Koszty wynajmu}
-\begin{center}
-\begin{tabular}{ | c | c | c | c | c | c | c | }
-\hline
- & A & B & C & D & E & F \\
- \hline
- 1 & - & 13 & - & 14 & 18 & - \\
- \hline
- 2 & - & 4 & 2 & - & 3 & - \\
- \hline
- 3 & 2 & - & - & 10 & - & 13 \\
- \hline
- 4 & 10 & - & 5 & - & - & 15 \\
- \hline
- 5 & - & 10 & - & - & 17 & 12 \\
- \hline
- 6 & 20 & - & 6 & 16 & - & - \\
- \hline
-\end{tabular}
-\end{center}
-\end{figure}
-
-\begin{enumerate}
-\item Parametry \\
-s - źródło \\
-w - wyjście \\
-N - węzły (N = {s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F})
-P - projekty (P = {1, 2, 3, 4, 5, 6} $\subseteq$ N)
-Z - zespoły (Z = {A, B, C, D, E, F} $\subseteq$ N)
-$k_{zp}$ - koszty przyporządkowania zespołu z do projektu p
-
-\item Zmienne decyzyjne:
-$f_{ij}$ - przeływ pomiędzy węzłem i oraz węzłem j
-\item Funkcja celu
-\begin{align*}
- Q &= \min \left(\sum_{z \in Z, p \in P} c_{zp}f_{zp} \right) \\
- &= \min \big( 13f_{B1} + 14f_{D1} + 18f_{E1} + 4f_{B2} + 2f_{C2} + 3f_{E2} \\
- &\quad + 2f_{A3} + 10f_{D3} + 13f_{F3} + 10f_{A4} + 5f_{C4} + 15f_{F4} \\
- &\quad + 10f_{B5} + 17f_{E5} + 12f_{F5} + 20f_{A6} + 6f_{C6} + 16f_{D6} \big)
-\end{align*}
-
-
-\item Ograniczenia
-\setcounter{equation}{0}
-\begin{equation}
-0 \leq f_{ij} \leq 1, (i, j) \in N
-\end{equation}
-\begin{equation}
-f_{si} = 0, i \in \{ s, t, 1, 2, 3, 4, 5, 6 \}
-\end{equation}
-\begin{equation}
-f_{is} = 0, i \in N
-\end{equation}
-\begin{equation}
-f_{ti} = 0, i \in N
-\end{equation}
-\begin{equation}
-f_{it} = 0, i \in \{s, t, A, B, C, D, E, F\}
-\end{equation}
-\begin{equation}
-\sum_{z \in Z} f_{zp} = 1, p \in P = \{ 1, 2, 3, 4, 5, 6 \}
-\end{equation}
-\begin{equation}
-\sum_{p \in P} f_{zp} = 1, z \in Z = \{ A, B, C, D, E, F \}
-\end{equation}
-\begin{equation}
-\sum_{i \in N \backslash \{s\}} f_{ni} = \sum_{j \in N \backslash \{t\}} f_{jn}, n \in N \backslash \{ s, t \}
-\end{equation}
-
-\end{enumerate}
-\paragraph{Model sieciowy rysunek}
-\includepdf[pages=-]{flowchart22.pdf}
-\paragraph{Rozwiazanie}
-\begin{lstlisting}[caption= plik dat]
-data;
-
-set Wyjscie := t;
-set Wezly := 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set StartWezly := s, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set WyjscieWezly := t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set StartWyjscieWezly := s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set Projekty := 1, 2, 3, 4, 5, 6;
-set Zespoly := A, B, C, D, E, F;
-
-param k :=
-A 1 1000 A 2 1000 A 3 2 A 4 10 A 5 1000 A 6 20
-B 1 13 B 2 4 B 3 1000 B 4 1000 B 5 10 B 6 1000
-C 1 1000 C 2 2 C 3 1000 C 4 5 C 5 1000 C 6 6
-D 1 14 D 2 1000 D 3 10 D 4 1000 D 5 1000 D 6 16
-E 1 18 E 2 3 E 3 1000 E 4 1000 E 5 17 E 6 1000
-F 1 1000 F 2 1000 F 3 13 F 4 15 F 5 12 F 6 1000;
-
-end;
-\end{lstlisting}
-\begin{lstlisting}[caption= plik mod]
-set Wyjscie;
-set Wezly;
-set StartWezly;
-set WyjscieWezly;
-set StartWyjscieWezly;
-set Projekty;
-set Zespoly;
-
-param k{z in Zespoly, p in Projekty};
-
-var f{i in StartWyjscieWezly, j in StartWyjscieWezly}, >= 0;
-
-minimize Q: sum {p in Projekty, z in Zespoly} k[z, p] * f[z, p];
-
- Ograniczenie_jeden{i in StartWyjscieWezly, j in StartWyjscieWezly}:
- f[i,j] >= 0;
- Ograniczenie_dwa{i in StartWyjscieWezly, j in StartWyjscieWezly}:
- f[i,j] <= 1;
- Ograniczenie_trzy{p in Projekty}:
- sum {z in Zespoly} f[z,p] = 1;
- Ograniczenie_cztery{z in Zespoly}:
- sum {p in Projekty} f[z,p] = 1;
- Ograniczenie_piec{n in Wezly}:
- sum {i in WyjscieWezly} f[n,i] = sum {j in StartWezly} f[j,n];
- solve;
-display {i in Wezly, j in Wezly: f[i,j] > 0}: f[i,j];
-display: Q;
-
-
-
-\end{lstlisting}
-\paragraph{Przydział zespołów do projektów}
-\begin{lstlisting}[caption=wynik z glpk]
-f[A,3].val = 1
-f[B,5].val = 1
-f[C,6].val = 1
-f[D,1].val = 1
-f[E,2].val = 1
-f[F,4].val = 1
-Q.val = 50
-\end{lstlisting}
-Wyniki: \\
-Projekt numer \textbf{1} zostanie przydzielony zespołowi \textbf{D} \\
-Projekt numer \textbf{2} zostanie przydzielony zespołowi \textbf{E} \\
-Projekt numer \textbf{3} zostanie przydzielony zespołowi \textbf{A} \\
-Projekt numer \textbf{4} zostanie przydzielony zespołowi \textbf{F} \\
-Projekt numer \textbf{5} zostanie przydzielony zespołowi \textbf{B} \\
-Projekt numer \textbf{6} zostanie przydzielony zespołowi \textbf{C} \\
-\subsection{Zadanie 2.3 Minimalizacja terminu realizacji puli projektów}
-\begin{figure}[htb]
-\caption{Czas realizacji projektów}
-\begin{center}
-\begin{tabular}{ | c | c | c | c | c | c | c | }
-\hline
- & A & B & C & D & E & F \\
- \hline
- 1 & - & 13 & - & 14 & 18 & - \\
- \hline
- 2 & - & 4 & 2 & - & 3 & - \\
- \hline
- 3 & 2 & - & - & 10 & - & 13 \\
- \hline
- 4 & 10 & - & 5 & - & - & 15 \\
- \hline
- 5 & - & 10 & - & - & 17 & 12 \\
- \hline
- 6 & 20 & - & 6 & 16 & - & - \\
- \hline
-\end{tabular}
-\end{center}
-\end{figure}
-
-\begin{enumerate}
-\item Parametry \\
-s - źródło \\
-w - wyjście \\
-N - węzły (N = {s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F})
-P - projekty (P = {1, 2, 3, 4, 5, 6} $\subseteq$ N)
-Z - zespoły (Z = {A, B, C, D, E, F} $\subseteq$ N)
-$t_{zp}$ - czas realizacji projektu p przez zespół z [w miesiącach]
-
-\item Zmienne decyzyjne:
-$f_{ij}$ - przeływ pomiędzy węzłem i oraz węzłem j
-\item Funkcja celu
-\begin{align*}
- Q &= \min \left( \max_{z \in Z, p \in P} c_{zp} f_{zp} \right) \\
- &= \min \big\{13f_{B1}, 14f_{D1}, 18f_{E1}, 4f_{B2}, 2f_{C2}, 3f_{E2}, \\
- &\quad 2f_{A3}, 10f_{D3},13f_{F3}, 10f_{A4}, 5f_{C4}, 15f_{F4} \\
- &\quad 10f_{B5}, 17f_{E5}, 12f_{F5}, 20f_{A6}, 6f_{C6}, 16f_{D6} \big\}
-\end{align*}
-
-
-\item Ograniczenia
-\setcounter{equation}{0}
-\begin{equation}
-0 \leq f_{ij} \leq 1, \; (i, j) \in N
-\end{equation}
-\begin{equation}
-f_{si} = 0, \; i \in \{ s, t, 1, 2, 3, 4, 5, 6 \}
-\end{equation}
-\begin{equation}
-f_{is} = 0, \; i \in N
-\end{equation}
-\begin{equation}
-f_{ti} = 0, \; i \in N
-\end{equation}
-\begin{equation}
-f_{it} = 0, \; i \in \{s, t, A, B, C, D, E, F\}
-\end{equation}
-\begin{equation}
-\sum_{z \in Z} f_{zp} = 1, \; p \in P = \{ 1, 2, 3, 4, 5, 6 \}
-\end{equation}
-\begin{equation}
-\sum_{p \in P} f_{zp} = 1, \; z \in Z = \{ A, B, C, D, E, F \}
-\end{equation}
-\begin{equation}
-\sum_{i \in N \backslash \{s\}} f_{ni} = \sum_{j \in N \backslash \{t\}} f_{jn}, \; n \in N \backslash \{ s, t \}
-\end{equation}
-
-\end{enumerate}
-\paragraph{Model sieciowy rysunek}
-\includepdf[pages=-]{flowchart22.pdf}
-\paragraph{Model programowania liniowego}
-\begin{lstlisting}[caption= plik dat]
-data;
-
-set Wyjscie := t;
-set Wezly := 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set StartWezly := s, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set WyjscieWezly := t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set StartWyjscieWezly := s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
-set Projekty := 1, 2, 3, 4, 5, 6;
-set Zespoly := A, B, C, D, E, F;
-
-param c :=
-A 1 1000 A 2 1000 A 3 2 A 4 10 A 5 1000 A 6 20
-B 1 13 B 2 4 B 3 1000 B 4 1000 B 5 10 B 6 1000
-C 1 1000 C 2 2 C 3 1000 C 4 5 C 5 1000 C 6 6
-D 1 14 D 2 1000 D 3 10 D 4 1000 D 5 1000 D 6 16
-E 1 18 E 2 3 E 3 1000 E 4 1000 E 5 17 E 6 1000
-F 1 1000 F 2 1000 F 3 13 F 4 15 F 5 12 F 6 1000;
-
-end;
-\end{lstlisting}
-\begin{lstlisting}[caption= plik mod]
-set Wyjscie;
-set Wezly;
-set StartWezly;
-set WyjscieWezly;
-set StartWyjscieWezly;
-set Projekty;
-set Zespoly;
-
-param c{z in Zespoly, p in Projekty};
-
-var f{i in StartWyjscieWezly, j in StartWyjscieWezly}, >= 0, integer;
-var cmax, >= 0;
-
-minimize Q: cmax;
-
-subject to
- Ograniczenie_jeden{i in StartWyjscieWezly, j in StartWyjscieWezly}:
- f[i,j] >= 0;
- Ograniczenie_dwa{i in StartWyjscieWezly, j in StartWyjscieWezly}:
- f[i,j] <= 1;
- Ograniczenie_trzy{p in Projekty}:
- sum {z in Zespoly} f[z,p] = 1;
- Ograniczenie_cztery{z in Zespoly}:
- sum {p in Projekty} f[z,p] = 1;
- Ograniczenie_piec{n in Wezly}:
- sum {i in WyjscieWezly} f[n,i] = sum {j in StartWezly} f[j,n];
- Ograniczenie_szesc{z in Zespoly, p in Projekty}:
- c[z,p] * f[z,p] <= cmax;
-solve;
-display {i in Wezly, j in Wezly: f[i,j] > 0}: f[i,j];
-display: Q;
-\end{lstlisting}
-
-\begin{lstlisting}[caption=wynik z glpk]
-f[A,4].val = 1
-f[B,1].val = 1
-f[C,6].val = 1
-f[D,3].val = 1
-f[E,2].val = 1
-f[F,5].val = 1
-Q.val = 13
-\end{lstlisting}
-Wyniki: \\
-Projekt numer \textbf{1} zostanie przydzielony zespołowi \textbf{B} \\
-Projekt numer \textbf{2} zostanie przydzielony zespołowi \textbf{E} \\
-Projekt numer \textbf{3} zostanie przydzielony zespołowi \textbf{D} \\
-Projekt numer \textbf{4} zostanie przydzielony zespołowi \textbf{A} \\
-Projekt numer \textbf{5} zostanie przydzielony zespołowi \textbf{F} \\
-Projekt numer \textbf{6} zostanie przydzielony zespołowi \textbf{C} \\
-\section{Zadanie 3}
-\paragraph{Model programowania liniowego}
-\begin{enumerate}
-\item Parametry \\
-m - liczba różnych zasobów, i $\in$ N \\
-n - liczba różnych produktów, j $\in$ N \\
-$c_{i}^{max}$ - Maksymalna przepustowość dla zasobu i \\
-$A_{ij}$ - Użycie zasobu i przez produkt j \\
-$q_j$ - Limit produkcji dla produktu j, po którym zmniejsza się przychód na jednostce \\
-$p_j$ - Normalny przychód na pojedyńczej sztuce produktu j \\
-$p_j^{disc}$ - Pomniejszony przychód na sztuce produktu j
-
-\item Zmienne decyzyjne
-$x_j$ - Wolumin produkcji produktu j
-\item Zmienne pomocnicze
-$r_j(u)$ - Funkcja wyliczająca przychód dla produktu j bazując na poziomie produkcji u \\
-$c_i$ - Całkowite zużycie zasobu typu i
-
-\item Funkcja celu
-\[ \max Z = \sum_{j=1}^n r_j u_j \]
-\[ r_j(u) = \{ \]
-\[ p_{j} u \qquad \qquad \qquad \qquad u <= q_j \]
-\[ p_j q_j + p_{j}^{disc}(u-q_j), \qquad u => q_j \]
-\[ \} \]
-
-\item Ograniczenia
-\setcounter{equation}{0}
-Całkowite zużycie zasobów nie może przekraczać dostępnośli dla żadnego zasobu
-\begin{equation}
-\sum_{j=1}^n A_{ij} \cdot x_j \leq c_i^{max}, \qquad i \in N
-\end{equation}
-Produkcja każdego produktu j, jest powiżana z właściwym $u_j$
-\begin{equation}
-u_j = x_j, \qquad j \in N
-\end{equation}
-Wolumin produkcji nie może być mniejszy od zera
-\begin{equation}
-x_j \geq 0, \qquad j \in N
-\end{equation}
-
-
-\end{enumerate}
+ \input{sections/01-zadanie-1-siec-przeplywowa}
+ \input{sections/02-zadanie-2-zadanie-przydzialu}
+ \input{sections/03-zadanie-3}
\end{document}
diff --git a/NotProgramming/MOM/report_three/report_three.tex b/NotProgramming/MOM/report_three/report_three.tex
index 83ca36ce..c06979a1 100644
--- a/NotProgramming/MOM/report_three/report_three.tex
+++ b/NotProgramming/MOM/report_three/report_three.tex
@@ -9,290 +9,8 @@
\setcounter{section}{-1}
\begin{document}
\maketitle
-\section{Wstęp}
-2 Fabryki, F1, F2 \\
-4 Magazyny, M1, M2, M3, M4 \\
-6 Klientów, K1, K2, K3, K4, K5, K6 \\
-\paragraph{Koszty dystrybucji towaru}
-
-\begin{center}
- \begin{tabular}{ | c | c | c | c | c | c | c | }
- \hline
- zaopatruje & F1 & F2 & M1 & M2 & M3 & M4 \\
- \hline
- Magazyny & & & & & & \\
- \hline
- M1 & 0.3 & - & & & & \\
- \hline
- M2 & 0.5 & 0.4 & & & & \\
- \hline
- M3 & 1.2 & 0.5 & & & & \\
- \hline
- M4 & 0.8 & 0.3 & & & & \\
- \hline
- Klientów & & & & & & \\
- \hline
- K1 & 1.2 & 1.8 & - & 1.4 & - & - \\
- \hline
- K2 & - & - & 1.2 & 0.3 & 1.3 & - \\
- \hline
- K3 & 1.2 & - & 0.2 & 1.8 & 2.0 & 0.4 \\
- \hline
- K4 & 2.0 & - & 1.7 & 1.3 & - & 2.0 \\
- \hline
- K5 & - & - & - & 0.5 & 0.3 & 0.5 \\
- \hline
- K6 & 1.1 & - & 2.0 & - & 1.4 & 1.5 \\
- \hline
- \end{tabular}
- \end{center}
-\section{Model Dwukryterialny}
-\paragraph{Zbiory}
-\begin{itemize}
- \item $i, k \in F$ - Fabryki
- \item $i, l \in M$ - Magazyny
- \item $j \in K$ - Klienci
-\end{itemize}
-\paragraph{Parametery}
-\begin{itemize}
- \item $C_{i, j}$ - Koszty transportu dóbr z punktów $i$ (fabryka lub magazyn) do klienta $j$
- \item $C_{k, l}$ - Koszty transportu dóbr z fabryki $i$ do magazynu $k$
- \item $P_{i, j}$ - Binarnie określa czy preferencja klienta zostąła spełniona (1) czy nie (0)
- \item $S_j$ - Poziom satysfakcji klienta $j$ - poziom satysfakcji liczymy w zależności od tego ile dany klient zamówił towaru \\
- Zadowolenie klientów którzy zamawiają więcej towarów jest traktowane priorytetowo:
- \[ S_1 = \frac{50}{60} \]
- \[ S_2 = \frac{10}{60} \]
- \[ S_3 = \frac{40}{60} \]
- \[ S_4 = \frac{35}{60} \]
- \[ S_5 = \frac{60}{60} \]
- \[ S_6 = \frac{20}{60} \]
- \item $D_j$ - Zapotrzebowanie klienta $j$
-\end{itemize}
-\paragraph{Zmienne decyzyjne}
-\begin{itemize}
- \item $x_{i,j}$ - Liczba dóbr (w tys. ton) przetransportowana z punktu $i$ (fabryka lub magazyn) do klienta $j$
- \item $y_{k, l}$ - Liczba dóbr (w tys. ton) przetransportowana z fabryki $k$ do magazynu $l$
-\end{itemize}
-\paragraph{Funkcja celu}
-\begin{enumerate}
- \item Minimalizacja kosztów dystrybucji \\
- \[ Min(\sum_{i, j} C_{i, j} * x_{i, j} + \sum{i, k} C_{i, k} * y_{i, k}) \]
- \item Maksymalizacja satysfakcja klienta \\
- W celu maksymalizacji satysfakcji klienta policzymy ile z dostaw do klientów odbyło się z preferencyjnych źródeł \\
- \[ Max(\sum_{j} S_j * P_{i,j} * x_{i, j}) \]
-\end{enumerate}
-\paragraph{Funkcja celu alpha beta}
-\[ \alpha * (Min(\sum_{i, j} C_{i, j} * x_{i, j} + \sum{i, k} C_{i, k} * y_{i, k})) + \beta * (Max(\sum_{j} S_j * P_{i,j} * x_{i, j})) \]
-\paragraph{Ograniczenia}
-Miesięczne możliwości produkcyjne fabryk
-\begin{equation}
- \sum_j x_{F1, j} + \sum_k y_{F1, k} \leq 150
-\end{equation}
-\begin{equation}
- \sum_j x_{F2, j} + \sum_k y_{F2, k} \leq 200
-\end{equation}
-Miesięczna ilośc obsługiwanego towaru przez magazyny
-\begin{equation}
- \sum_j x_{M1, j} \leq 70
-\end{equation}
-\begin{equation}
- \sum_j x_{M2, j} \leq 50
-\end{equation}
-\begin{equation}
- \sum_j x_{M3, j} \leq 100
-\end{equation}
-\begin{equation}
- \sum_j x_{M4, j} \leq 40
-\end{equation}
-Spełnienie preferencji klienta
-\begin{equation}
- \sum_i x_{i, j} = D_j
-\end{equation}
-Wartości niezerowe
-\begin{equation}
- x_{i, j}, y_{i, k} \geq 0
-\end{equation}
-
-\section{Implementacja}
-Do implementacji użyty został python z biblioteką pulp \href{https://coin-or.github.io/pulp/index.html}{https://coin-or.github.io/pulp/index.html} \\
-Dzięki temu wykorzystujemy zarówno łatwość pythona jak i możliwości używania różnych solverów (CBC, GLPK, CPLEX, Gurobi...) przez pulpa \\
-\begin{lstlisting}[language=Python, caption={Import bilbioteki pulp i bibliotek używanych do wykresu}]
- import pulp
- import sys
-\end{lstlisting}
-\begin{lstlisting}[language=Python, caption={Iniicjalizacja modelu}]
- model = pulp.LpProblem("Optimal_Distribution", pulp.LpMinimize)
-\end{lstlisting}
-
-\begin{lstlisting}[language=Python, caption={Zdefiniowanie zmiennych i parametrów}]
- fabryki = ['F1', 'F2']
- magazyny = ['M1', 'M2', 'M3', 'M4']
- dostawcy = fabryki + magazyny
-
- klienci = ['K1', 'K2', 'K3', 'K4', 'K5', 'K6']
-
- koszt = {
- 'F1': {'M1': 0.3, 'M2': 0.5, 'M3': 1.2, 'M4': 0.8,
- 'K1': 1.2, 'K2': 999, K3': 1.2, 'K4': 2.0,
- 'K5': 999, 'K6': 1.1},
- 'F2': {'M1': 999, 'M2': 0.4, 'M3': 0.5, 'M4': 0.3,
- 'K1': 1.8, 'K2': 999, 'K3': 999, 'K4': 999,
- 'K5': 999, 'K6': 999},
- 'M1': {'K1': 999, 'K2': 1.2, 'K3': 0.2, 'K4': 1.7,
- 'K5': 999, 'K6': 2.0},
- 'M2': {'K1': 1.4, 'K2': 0.3, 'K3': 1.8, 'K4': 1.3,
- 'K5': 0.5, 'K6': 999},
- 'M3': {'K1': 999, 'K2': 1.3, 'K3': 2.0, 'K4': 999,
- 'K5': 0.3, 'K6': 1.4},
- 'M4': {'K1': 999, 'K2': 999, 'K3': 0.4, 'K4': 2.0,
- 'K5': 0.5, 'K6': 1.6}
- }
- P = pulp.LpVariable.dicts(
- "P", [(i, j) for i in dostawcy for j in klienci],
- cat='Binary')
- maksymalne_zamowienie = 60
- poziom_satysfakcji = {
- 'K1': 50 / maksymalne_zamowienie,
- 'K2': 10 / maksymalne_zamowienie,
- 'K3': 40 / maksymalne_zamowienie,
- 'K4': 35 / maksymalne_zamowienie,
- 'K5': 60 / maksymalne_zamowienie,
- 'K6': 20 / maksymalne_zamowienie}
- preferencja_klienta = {
- 'K1': ['F2'], 'K2': ['M1'], 'K3': ['M2', 'M3'],
- 'K4': ['F1'], 'K5': [], 'K6': ['M3', 'M4']}
- suma_satysfakcji = pulp.lpSum(
- [poziom_satysfakcji[j] * P[(i, j)]
- for i in dostawcy for j in klienci])
-\end{lstlisting}
-
-\begin{lstlisting}[language=Python, caption={Zmienne decyzyjne}]
- x = pulp.LpVariable.dicts(
- "x",
- [(i, j) for i in dostawcy for j in klienci],
- lowBound=0, cat='Integer')
- y = pulp.LpVariable.dicts("y",
- [(i, k) for i in fabryki for k in magazyny],
- lowBound=0, cat='Integer')
-\end{lstlisting}
-
-\begin{lstlisting}[language=Python, caption={Funkcje celu}]
- koszt_dystrybucji = pulp.lpSum(
- [koszt[i][j] * x[(i, j)]
- for i in dostawcy for j in klienci])
- koszt_magazynowania = pulp.lpSum(
- [koszt[i][k] * y[(i, k)]
- for i in fabryki for k in magazyny])
- alpha = 0.5
- beta = 0.5
- model += alpha
- * (koszt_dystrybucji + koszt_magazynowania)
- - beta * suma_satysfakcji
-\end{lstlisting}
-
-\begin{lstlisting}[language=Python, caption={Ograniczenia}]
-for i in fabryki:
- model += pulp.lpSum(
- [x[(i, j)] for j in klienci]
- + [y[(i, k)] for k in magazyny])
- <= mozliwosci_fabryki[i]
-
-for k in magazyny:
- model += pulp.lpSum(
- [x[(k, j)] for j in klienci]
- ) <= pojemnosc_magazynu[k]
-
-for j in klienci:
- model += pulp.lpSum(
- [x[(i, j)] for i in dostawcy]) == zamowienia_klientow[j]
-\end{lstlisting}
-
-\begin{lstlisting}[language=Python, caption={Rozwiązanie problemu}]
- model.solve()
-\end{lstlisting}
-\
-
-\begin{lstlisting}[language=Python, caption={Przedstawienie wyników}]
-for v in model.variables():
- print(v.name, "=", v.varValue)
-\end{lstlisting}
-
-\section{Rozwiązanie efektywne}
-Aby zdefiniować rozwiązanie efektywne sprawdzamy sumaryczy obu funkcji celu dla wartości $\alpha$ i $beta$ od 1 do 10 \\
-w tym celu napisany został kod który modyfikuje wartości $\alpha$ i $\beta$ w pętli
-
-\begin{lstlisting}[language=Python, caption={Wyznaczanie alpha i beta}]
- koszt_wyniki = []
- zadowolenie_wyniki = []
- wyniki_funkcji = []
- maksymalny_wynik = 0;
- for alpha in range(0, 11):
- beta = 10 - alpha + sys.float_info.epsilon
- alpha /= 10.0
- beta /= 10.0
- # Update objective function
- model.objective = alpha * koszt_dystrybucji
- - beta * suma_satysfakcji
-
- # Solve the model
- model.solve()
- print(alpha)
-
- # Record the wyniki
- calkowity_koszt = pulp.value(koszt_dystrybucji)
- calkowite_zadowolenie = pulp.value(suma_satysfakcji)
- wynik_funkcji = pulp.value(alpha * koszt_dystrybucji
- - beta * suma_satysfakcji)
- koszt_wyniki.append(calkowity_koszt)
- zadowolenie_wyniki.append(calkowite_zadowolenie)
- if wynik_funkcji > maksymalny_wynik:
- maksymalny_wynik = wynik_funkcji
- wyniki_funkcji.append(wynik_funkcji)
-
- print("maksymalny_wynik", maksymalny_wynik, wyniki_funkcji)
-
-\end{lstlisting}
-Najwyższy wynik zostął uzyskany dla $\alpha = 10$ i $\beta = 0$ i wynosił on \textbf{156.5}
-
-\paragraph{Symulacja procesu podejmowania decyzji}
-Przeprowadzone zostały symulacje dla 5 sytuacji:
-\begin{enumerate}
- \item Tylko minimalizacja kosztów $\alpha = 1.0$ $\beta = 0.0$
- \item Priorytet na minimalizacji kosztów $\alpha = 0.8$ $\beta = 0.2$
- \item Równy podział $\alpha = 0.5$ $\beta = 0.5$
- \item Priorytet na satysfakcji klientów $\alpha = 0.2$ $\beta = 0.8$
- \item Tylko satysfakcja klientów $\alpha = 0.0$ $\beta = 1.0$
-\end{enumerate}
-
-Ponownie w celu przeprowadzenia symulacji napisano kod w pythonie
-\begin{lstlisting}[language=Python]
-# Pseudo-code, assuming model setup as previously discussed
-scemariusze = [
- (1.0, sys.float_info.epsilon),
- (0.8, 0.2),
- (0.5, 0.5),
- (0.2, 0.8),
- (sys.float_info.epsilon, 1.0)]
-wyniki = []
-
-for alpha, beta in scemariusze:
- model.objective = alpha * koszt_dystrybucji
- - beta * suma_satysfakcji
-
- model.solve()
-
- calkowity_koszt = pulp.value(koszt_dystrybucji)
- calkowite_zadowolenie = pulp.value(suma_satysfakcji)
- wyniki.append(
- (alpha, beta, calkowity_koszt, calkowite_zadowolenie)
- )
-
-for idx, (alpha, beta, koszt, zadowolenie) in enumerate(wyniki):
- print(f"Krok {idx+1}:")
- print(f" koszt: {alpha}, zadowolenie: {beta}")
- print(f"
- Calkowity koszt: {koszt},
- zadowolenie klienta: {zadowolenie}\n")
-\end{lstlisting}
-
+ \input{sections/01-wstep}
+ \input{sections/02-model-dwukryterialny}
+ \input{sections/03-implementacja}
+ \input{sections/04-rozwiazanie-efektywne}
\end{document}
\ No newline at end of file
diff --git a/NotProgramming/MOM/report_three/sections/01-wstep.tex b/NotProgramming/MOM/report_three/sections/01-wstep.tex
new file mode 100644
index 00000000..8f295bab
--- /dev/null
+++ b/NotProgramming/MOM/report_three/sections/01-wstep.tex
@@ -0,0 +1,37 @@
+\section{Wstęp}
+2 Fabryki, F1, F2 \\
+4 Magazyny, M1, M2, M3, M4 \\
+6 Klientów, K1, K2, K3, K4, K5, K6 \\
+\paragraph{Koszty dystrybucji towaru}
+
+\begin{center}
+ \begin{tabular}{ | c | c | c | c | c | c | c | }
+ \hline
+ zaopatruje & F1 & F2 & M1 & M2 & M3 & M4 \\
+ \hline
+ Magazyny & & & & & & \\
+ \hline
+ M1 & 0.3 & - & & & & \\
+ \hline
+ M2 & 0.5 & 0.4 & & & & \\
+ \hline
+ M3 & 1.2 & 0.5 & & & & \\
+ \hline
+ M4 & 0.8 & 0.3 & & & & \\
+ \hline
+ Klientów & & & & & & \\
+ \hline
+ K1 & 1.2 & 1.8 & - & 1.4 & - & - \\
+ \hline
+ K2 & - & - & 1.2 & 0.3 & 1.3 & - \\
+ \hline
+ K3 & 1.2 & - & 0.2 & 1.8 & 2.0 & 0.4 \\
+ \hline
+ K4 & 2.0 & - & 1.7 & 1.3 & - & 2.0 \\
+ \hline
+ K5 & - & - & - & 0.5 & 0.3 & 0.5 \\
+ \hline
+ K6 & 1.1 & - & 2.0 & - & 1.4 & 1.5 \\
+ \hline
+ \end{tabular}
+ \end{center}
diff --git a/NotProgramming/MOM/report_three/sections/02-model-dwukryterialny.tex b/NotProgramming/MOM/report_three/sections/02-model-dwukryterialny.tex
new file mode 100644
index 00000000..103b5451
--- /dev/null
+++ b/NotProgramming/MOM/report_three/sections/02-model-dwukryterialny.tex
@@ -0,0 +1,67 @@
+\section{Model Dwukryterialny}
+\paragraph{Zbiory}
+\begin{itemize}
+ \item $i, k \in F$ - Fabryki
+ \item $i, l \in M$ - Magazyny
+ \item $j \in K$ - Klienci
+\end{itemize}
+\paragraph{Parametery}
+\begin{itemize}
+ \item $C_{i, j}$ - Koszty transportu dóbr z punktów $i$ (fabryka lub magazyn) do klienta $j$
+ \item $C_{k, l}$ - Koszty transportu dóbr z fabryki $i$ do magazynu $k$
+ \item $P_{i, j}$ - Binarnie określa czy preferencja klienta zostąła spełniona (1) czy nie (0)
+ \item $S_j$ - Poziom satysfakcji klienta $j$ - poziom satysfakcji liczymy w zależności od tego ile dany klient zamówił towaru \\
+ Zadowolenie klientów którzy zamawiają więcej towarów jest traktowane priorytetowo:
+ \[ S_1 = \frac{50}{60} \]
+ \[ S_2 = \frac{10}{60} \]
+ \[ S_3 = \frac{40}{60} \]
+ \[ S_4 = \frac{35}{60} \]
+ \[ S_5 = \frac{60}{60} \]
+ \[ S_6 = \frac{20}{60} \]
+ \item $D_j$ - Zapotrzebowanie klienta $j$
+\end{itemize}
+\paragraph{Zmienne decyzyjne}
+\begin{itemize}
+ \item $x_{i,j}$ - Liczba dóbr (w tys. ton) przetransportowana z punktu $i$ (fabryka lub magazyn) do klienta $j$
+ \item $y_{k, l}$ - Liczba dóbr (w tys. ton) przetransportowana z fabryki $k$ do magazynu $l$
+\end{itemize}
+\paragraph{Funkcja celu}
+\begin{enumerate}
+ \item Minimalizacja kosztów dystrybucji \\
+ \[ Min(\sum_{i, j} C_{i, j} * x_{i, j} + \sum{i, k} C_{i, k} * y_{i, k}) \]
+ \item Maksymalizacja satysfakcja klienta \\
+ W celu maksymalizacji satysfakcji klienta policzymy ile z dostaw do klientów odbyło się z preferencyjnych źródeł \\
+ \[ Max(\sum_{j} S_j * P_{i,j} * x_{i, j}) \]
+\end{enumerate}
+\paragraph{Funkcja celu alpha beta}
+\[ \alpha * (Min(\sum_{i, j} C_{i, j} * x_{i, j} + \sum{i, k} C_{i, k} * y_{i, k})) + \beta * (Max(\sum_{j} S_j * P_{i,j} * x_{i, j})) \]
+\paragraph{Ograniczenia}
+Miesięczne możliwości produkcyjne fabryk
+\begin{equation}
+ \sum_j x_{F1, j} + \sum_k y_{F1, k} \leq 150
+\end{equation}
+\begin{equation}
+ \sum_j x_{F2, j} + \sum_k y_{F2, k} \leq 200
+\end{equation}
+Miesięczna ilośc obsługiwanego towaru przez magazyny
+\begin{equation}
+ \sum_j x_{M1, j} \leq 70
+\end{equation}
+\begin{equation}
+ \sum_j x_{M2, j} \leq 50
+\end{equation}
+\begin{equation}
+ \sum_j x_{M3, j} \leq 100
+\end{equation}
+\begin{equation}
+ \sum_j x_{M4, j} \leq 40
+\end{equation}
+Spełnienie preferencji klienta
+\begin{equation}
+ \sum_i x_{i, j} = D_j
+\end{equation}
+Wartości niezerowe
+\begin{equation}
+ x_{i, j}, y_{i, k} \geq 0
+\end{equation}
+
diff --git a/NotProgramming/MOM/report_three/sections/03-implementacja.tex b/NotProgramming/MOM/report_three/sections/03-implementacja.tex
new file mode 100644
index 00000000..1867a0cd
--- /dev/null
+++ b/NotProgramming/MOM/report_three/sections/03-implementacja.tex
@@ -0,0 +1,104 @@
+\section{Implementacja}
+Do implementacji użyty został python z biblioteką pulp \href{https://coin-or.github.io/pulp/index.html}{https://coin-or.github.io/pulp/index.html} \\
+Dzięki temu wykorzystujemy zarówno łatwość pythona jak i możliwości używania różnych solverów (CBC, GLPK, CPLEX, Gurobi...) przez pulpa \\
+\begin{lstlisting}[language=Python, caption={Import bilbioteki pulp i bibliotek używanych do wykresu}]
+ import pulp
+ import sys
+\end{lstlisting}
+\begin{lstlisting}[language=Python, caption={Iniicjalizacja modelu}]
+ model = pulp.LpProblem("Optimal_Distribution", pulp.LpMinimize)
+\end{lstlisting}
+
+\begin{lstlisting}[language=Python, caption={Zdefiniowanie zmiennych i parametrów}]
+ fabryki = ['F1', 'F2']
+ magazyny = ['M1', 'M2', 'M3', 'M4']
+ dostawcy = fabryki + magazyny
+
+ klienci = ['K1', 'K2', 'K3', 'K4', 'K5', 'K6']
+
+ koszt = {
+ 'F1': {'M1': 0.3, 'M2': 0.5, 'M3': 1.2, 'M4': 0.8,
+ 'K1': 1.2, 'K2': 999, K3': 1.2, 'K4': 2.0,
+ 'K5': 999, 'K6': 1.1},
+ 'F2': {'M1': 999, 'M2': 0.4, 'M3': 0.5, 'M4': 0.3,
+ 'K1': 1.8, 'K2': 999, 'K3': 999, 'K4': 999,
+ 'K5': 999, 'K6': 999},
+ 'M1': {'K1': 999, 'K2': 1.2, 'K3': 0.2, 'K4': 1.7,
+ 'K5': 999, 'K6': 2.0},
+ 'M2': {'K1': 1.4, 'K2': 0.3, 'K3': 1.8, 'K4': 1.3,
+ 'K5': 0.5, 'K6': 999},
+ 'M3': {'K1': 999, 'K2': 1.3, 'K3': 2.0, 'K4': 999,
+ 'K5': 0.3, 'K6': 1.4},
+ 'M4': {'K1': 999, 'K2': 999, 'K3': 0.4, 'K4': 2.0,
+ 'K5': 0.5, 'K6': 1.6}
+ }
+ P = pulp.LpVariable.dicts(
+ "P", [(i, j) for i in dostawcy for j in klienci],
+ cat='Binary')
+ maksymalne_zamowienie = 60
+ poziom_satysfakcji = {
+ 'K1': 50 / maksymalne_zamowienie,
+ 'K2': 10 / maksymalne_zamowienie,
+ 'K3': 40 / maksymalne_zamowienie,
+ 'K4': 35 / maksymalne_zamowienie,
+ 'K5': 60 / maksymalne_zamowienie,
+ 'K6': 20 / maksymalne_zamowienie}
+ preferencja_klienta = {
+ 'K1': ['F2'], 'K2': ['M1'], 'K3': ['M2', 'M3'],
+ 'K4': ['F1'], 'K5': [], 'K6': ['M3', 'M4']}
+ suma_satysfakcji = pulp.lpSum(
+ [poziom_satysfakcji[j] * P[(i, j)]
+ for i in dostawcy for j in klienci])
+\end{lstlisting}
+
+\begin{lstlisting}[language=Python, caption={Zmienne decyzyjne}]
+ x = pulp.LpVariable.dicts(
+ "x",
+ [(i, j) for i in dostawcy for j in klienci],
+ lowBound=0, cat='Integer')
+ y = pulp.LpVariable.dicts("y",
+ [(i, k) for i in fabryki for k in magazyny],
+ lowBound=0, cat='Integer')
+\end{lstlisting}
+
+\begin{lstlisting}[language=Python, caption={Funkcje celu}]
+ koszt_dystrybucji = pulp.lpSum(
+ [koszt[i][j] * x[(i, j)]
+ for i in dostawcy for j in klienci])
+ koszt_magazynowania = pulp.lpSum(
+ [koszt[i][k] * y[(i, k)]
+ for i in fabryki for k in magazyny])
+ alpha = 0.5
+ beta = 0.5
+ model += alpha
+ * (koszt_dystrybucji + koszt_magazynowania)
+ - beta * suma_satysfakcji
+\end{lstlisting}
+
+\begin{lstlisting}[language=Python, caption={Ograniczenia}]
+for i in fabryki:
+ model += pulp.lpSum(
+ [x[(i, j)] for j in klienci]
+ + [y[(i, k)] for k in magazyny])
+ <= mozliwosci_fabryki[i]
+
+for k in magazyny:
+ model += pulp.lpSum(
+ [x[(k, j)] for j in klienci]
+ ) <= pojemnosc_magazynu[k]
+
+for j in klienci:
+ model += pulp.lpSum(
+ [x[(i, j)] for i in dostawcy]) == zamowienia_klientow[j]
+\end{lstlisting}
+
+\begin{lstlisting}[language=Python, caption={Rozwiązanie problemu}]
+ model.solve()
+\end{lstlisting}
+\
+
+\begin{lstlisting}[language=Python, caption={Przedstawienie wyników}]
+for v in model.variables():
+ print(v.name, "=", v.varValue)
+\end{lstlisting}
+
diff --git a/NotProgramming/MOM/report_three/sections/04-rozwiazanie-efektywne.tex b/NotProgramming/MOM/report_three/sections/04-rozwiazanie-efektywne.tex
new file mode 100644
index 00000000..b36226c0
--- /dev/null
+++ b/NotProgramming/MOM/report_three/sections/04-rozwiazanie-efektywne.tex
@@ -0,0 +1,78 @@
+\section{Rozwiązanie efektywne}
+Aby zdefiniować rozwiązanie efektywne sprawdzamy sumaryczy obu funkcji celu dla wartości $\alpha$ i $beta$ od 1 do 10 \\
+w tym celu napisany został kod który modyfikuje wartości $\alpha$ i $\beta$ w pętli
+
+\begin{lstlisting}[language=Python, caption={Wyznaczanie alpha i beta}]
+ koszt_wyniki = []
+ zadowolenie_wyniki = []
+ wyniki_funkcji = []
+ maksymalny_wynik = 0;
+ for alpha in range(0, 11):
+ beta = 10 - alpha + sys.float_info.epsilon
+ alpha /= 10.0
+ beta /= 10.0
+ # Update objective function
+ model.objective = alpha * koszt_dystrybucji
+ - beta * suma_satysfakcji
+
+ # Solve the model
+ model.solve()
+ print(alpha)
+
+ # Record the wyniki
+ calkowity_koszt = pulp.value(koszt_dystrybucji)
+ calkowite_zadowolenie = pulp.value(suma_satysfakcji)
+ wynik_funkcji = pulp.value(alpha * koszt_dystrybucji
+ - beta * suma_satysfakcji)
+ koszt_wyniki.append(calkowity_koszt)
+ zadowolenie_wyniki.append(calkowite_zadowolenie)
+ if wynik_funkcji > maksymalny_wynik:
+ maksymalny_wynik = wynik_funkcji
+ wyniki_funkcji.append(wynik_funkcji)
+
+ print("maksymalny_wynik", maksymalny_wynik, wyniki_funkcji)
+
+\end{lstlisting}
+Najwyższy wynik zostął uzyskany dla $\alpha = 10$ i $\beta = 0$ i wynosił on \textbf{156.5}
+
+\paragraph{Symulacja procesu podejmowania decyzji}
+Przeprowadzone zostały symulacje dla 5 sytuacji:
+\begin{enumerate}
+ \item Tylko minimalizacja kosztów $\alpha = 1.0$ $\beta = 0.0$
+ \item Priorytet na minimalizacji kosztów $\alpha = 0.8$ $\beta = 0.2$
+ \item Równy podział $\alpha = 0.5$ $\beta = 0.5$
+ \item Priorytet na satysfakcji klientów $\alpha = 0.2$ $\beta = 0.8$
+ \item Tylko satysfakcja klientów $\alpha = 0.0$ $\beta = 1.0$
+\end{enumerate}
+
+Ponownie w celu przeprowadzenia symulacji napisano kod w pythonie
+\begin{lstlisting}[language=Python]
+# Pseudo-code, assuming model setup as previously discussed
+scemariusze = [
+ (1.0, sys.float_info.epsilon),
+ (0.8, 0.2),
+ (0.5, 0.5),
+ (0.2, 0.8),
+ (sys.float_info.epsilon, 1.0)]
+wyniki = []
+
+for alpha, beta in scemariusze:
+ model.objective = alpha * koszt_dystrybucji
+ - beta * suma_satysfakcji
+
+ model.solve()
+
+ calkowity_koszt = pulp.value(koszt_dystrybucji)
+ calkowite_zadowolenie = pulp.value(suma_satysfakcji)
+ wyniki.append(
+ (alpha, beta, calkowity_koszt, calkowite_zadowolenie)
+ )
+
+for idx, (alpha, beta, koszt, zadowolenie) in enumerate(wyniki):
+ print(f"Krok {idx+1}:")
+ print(f" koszt: {alpha}, zadowolenie: {beta}")
+ print(f"
+ Calkowity koszt: {koszt},
+ zadowolenie klienta: {zadowolenie}\n")
+\end{lstlisting}
+
diff --git a/NotProgramming/MOM/report_two/report_two.tex b/NotProgramming/MOM/report_two/report_two.tex
index 9c1c33da..0945ab4a 100644
--- a/NotProgramming/MOM/report_two/report_two.tex
+++ b/NotProgramming/MOM/report_two/report_two.tex
@@ -11,353 +11,12 @@
\date{\today}
\begin{document}
\maketitle
-\section{Parametry}
-z - stan początkowy \\
-S - zakupione surowce (S = \{S1, S2\}) \\
-G1 - surowiec S1 załadowany do wagonów \\
-P - surowce w przygotowywalni (P = \{P1, P2\}) \\
-O2 - surowiec S2 w zakładzie obróbki cieplnej \\
-D - półprodukty (D = \{D1, D2\}) \\
-W - wyroby (W = \{W1, W2\}) \\
-N - stany surowców/półproduktów/wyrobów (zakupione surowce, surowce w przechowalni, surowce w zakładzie obróbki cieplnej, półprodukty, wyroby) \\
-$r_w$ - cena sprzedaży wyrobu $w[\frac{1}{t}]$ \\
-$u_{ij}$ - przepustowośc przepływu ze stanu i do stanu j[t] \\
-$m_{pd}$ - mnożnik definiujący przepływ ze stanu 'surowiec w przygotowalni p' do stanu 'półprodukt d'
-
-\section{Zmienne decyzyjne}
-$f_{ij}$ = przepływ pomiędzy stanem i a stanem j [t] \\
-\section{Zmienne pomocnicze}
-$a_1$ - liczba zakupionego surowca S1 powyżej 2387 ton [t] \\
-$a_2$ - liczba zakupionego surowca S1 powyżej 6659 ton [t] \\
-$b_1$ - liczba zakupionego surowca S2 powyżej 2090 ton [t] \\
-$b_2$ - liczba zakupionego surowca S2 powyżej 4349 ton [t] \\
-$c_{P1}$ - liczba wagonów transportujących surowiec S1 do przygotowalni \\
-$e_{P2}$ - liczba ciężarówek transportujących surowiec S2 do przygotowalni \\
-$e_{O2}$ - liczba ciężarówek transportującyhc surowiec S2 do zakładu obróbki cieplnej \\
-$g_1$ - zmienna binarna przyjmująca wartość 1 gdy przepływ ze stanu "zakupiony surowiec S2" (S2) do stanu "surowiec S2 w zakładzie obróbki cieplnej" (O2) jest większy niż 2000 ton i mniejszy niż 4000 ton \\
-$g_2$ - zmienna binarna przyjmująca wartość 1 gdy przepływ ze stanu "zakupiony surowiec S2" (S2) do stanu "surowiec S2 w zakładzie obróbki cieplnej" (O2) jest większy niż 4000 ton i mniejszy niż 6000 ton \\
-l - liczba pracowników zatrudnionych w przygotowalni
-\section{Funkcja celu}
-\begin{align*}
-Q &= max[Zysk - Koszt] \\
-&= max[\sum_{i \in N, w \in W} r_w + f_{iw} \\
-&- (19f_{zS1} - 5a_1 - 4a_2 + 11f_{zS2} + 2b_1 + 2b_2 \\
-&+ 1290c_{P1} + 1500e_{P2} +1500e_{O2} + 160l + 10000g_1 + 40000g_2)]
-\end{align*}
-
-\section{Ograniczenia}
-\subsection{Ogólne}
-Przepływ musi być nieujemny oraz mniejszy przepustowości
-\begin{equation}
-0 \leq f_{ij} \leq u_{ij}, \qquad (i,j) \in N \\
-\end{equation}
-Wszystko co przypłyneło do stanu k musi stamtąd "odpłynąć"
-\begin{equation}
-\sum_{i \in N \backslash \{z\}} f_{ki} = \sum_{i \in N \backslash \{W\}} f_{jk}, \qquad k \in N \backslash \{z, W\}
-\end{equation}
-
-\subsection{Dostępne surowce}
-Nie możemy kupić więcej surowca S1 niż jest dostępne
-\begin{equation}
-f_{zS1} \leq 12000
-\end{equation}
-Nie możemy kupić więcej surowca S2 niż jest dostępne
-\begin{equation}
-f_{zS2} \leq 8000
-\end{equation}
-
-\subsection{Koszt zakupu surowców}
-Nie możemy kupić mniej niż 0 surowców
-\begin{equation}
-a_1 \geq 0
-\end{equation}
-\begin{equation}
-a_2 \geq 0
-\end{equation}
-\begin{equation}
-b_1 \geq 0
-\end{equation}
-\begin{equation}
-b_2 \geq 0
-\end{equation}
-Ograniczamy ile ton ponad dany limit kupiliśmy
-\begin{equation}
-a_1 \leq f_{zS1} - 2387
-\end{equation}
-liczba powyżej 2056 ton
-\begin{equation}
-a_2 \leq f_{zS1} - 6659
-\end{equation}
-liczba powyżej 2056 ton
-\begin{equation}
-b_1 \leq f_{zS2} - 2090
-\end{equation}
-liczba powyżej 2056 ton
-\begin{equation}
-b_2 \leq f_{zS2} - 4349
-\end{equation}
-\subsection{Transport surowca S1 do przygotowalni}
-wagon może przetransportować maks. 18 ton surowca S1
-\begin{equation}
-b_{P1} \geq [\frac{ f_{S1, G1} }{18}]
-\end{equation}
-\subsection{Transport surowca S2 do przygtowalni}
-ciężarówka może przetransportować maks. 25 ton surowca S2
-\begin{equation}
-c_{P2} \geq [ \frac{ f_{S2, P2} }{ 25 } ]
-\end{equation}
-\subsection{Praca przygotowalni}
-Przygotowalnia nie może mieć więcej surowców niż przepustowości
-\begin{equation}
-\sum_{i \in N, p \in P} f_{ip} \leq 16000
-\end{equation}
-ilość półproduktów w zależności od surowca
-\begin{equation}
-(\sum_{i \in N} f_{ip}) m_{pd} = f_{pd}, \qquad i \in N, p \in P, d \in D
-\end{equation}
-\subsection{Koszt pracy przygotowalni}
-3 pracowników może obsługiwać maksymalnie 150 ton całkowitej ilości przerabianych surowców
-\begin{equation}
-l \geq [ \frac{ \sum_{i\in N, p \in P} f_{ip} }{150} ]
-\end{equation}
-\subsection{Transport S2 do zakładu obróbki cieplnej}
-ciężarówka może przetransportować maks. 25 ton surowca S2
-\begin{equation}
-c_{O2} \geq [\frac{ f_{S2, O2} }{25}]
-\end{equation}
-\subsection{Praca zakładu obróbki cieplnej}
-ilość surowca S2 w zakładzie obróbki cieplnej nie może być większa od 6000
-\begin{equation}
-f_{S2, O2} \leq 6000
-\end{equation}
-\subsection{Minimalna dostarczona ilość wyrobów}
-Zgodnie z umową musimy dostarczyć przynajmniej 5000 ton wyrobów
-\begin{equation}
-\sum_{i \in N f_{iw}} \geq 5000, \qquad w \in W
-\end{equation}
-\subsection{Maksymalna liczba wagonow}
-Na jedna lokomotywę, nie może przypadać więcej niż 12 wagonów
-\begin{equation}
-12wl \geq c_{P1}
-\end{equation}
-
-\section{Model sieciowy}
-\includepdf{mom2.drawio.pdf}
-
-\section{Implementacja modelu}
-\begin{lstlisting}[caption= plik mod]
-# PARAMETRY
-# Stan poczatkowy
-set Z;
-# Zakupione surowce, s1 i s2
-set S; set S1; set S2;
-# Surowiec S1 zaladowany do wagonow
-set G1;
-# Surowce w przygotowywalni
-set P; set P1; set P2;
-# Surowiec S2 w zakladzie obrobki cieplnej
-set O2;
-# Polprodukty
-set D; set D1; set D2;
-# Wyroby
-set W; set W1; set W2;
-# Stany surowcow, zakupione, wyroby, obrobka cieplna
-set N; set Nz; set Nw; set Nzw;
-
-# Cena sprzedazy wyrobu
-param r{w in W};
-# Przepustowosc przeplwyu z jednego stanu do drugiego
-param u{i in N, j in N};
-# Mnoznik definijujacy przepwy ze stanu surowiec
-# w przygotowalni do stanu polprodukt
-param m{p in P, d in D};
-
-# ZMIENNE DECYZYJNE
-# przeplyw pomiedzy stanem i a stanem j
-var f{i in N, j in N}, >= 0, integer; # Ograniczenie 1
-
-# Zmienne pomocnicze
-# liczba zakupionego surowca S1 powyzej 2387 ton
-var a1, >= 0, integer; # Ograniczenie 5
-# liczba zakupionego surowca S1 powyzej 6659 ton
-var a2, >= 0, integer; # Ograniczenie 6
-# liczba zakupionego surowca S2 powyzej 2090 ton
-var b1, >= 0, integer; # Ograniczenie 7
-# liczba zakupionego surowca S2 powyzej 4349 ton
-var b2, >= 0, integer; # Ograniczenie 8
-# liczba wynajetych lokomotyw
-var wl, >= 0, integer;
-# liczba wagonow transportujacych surowiec S1 do przygotowalni
-var cp1, >= 0, integer;
-# liczba ciezarowek transportujacych surowiec S2 do przygotowalni
-var ep2, >= 0, integer;
-# liczba ciezarowek transportujacych surowiec S2
-# do zakladu obrobki cieplnej
-var eo2, >= 0, integer;
-var e1, >= 0, <=1, integer;
-var e2, >= 0, <=1, integer;
-# Liczba pracownikow
-var l, >= 0, integer;
-
-maximize Q: (sum {i in N, w in W} r[w] * f[i,w])
-- (19* (sum {z in Z, s1 in S1} f[z, s1] )
-- 5*a1
-- 4*a2
-+ 11* sum {z in Z, s2 in S2} (f[z, s2])
-+ 2*b1
-+ 2*b2
-+ 1290*cp1
-+ 1500*ep2
-+ 1500*eo2
-+ 160*l
-+ 10000*e1
-+ 40000*e2);
-
-# OGRANICZENIA
-subject to
- # Ogolne i Dostepne surowce
- Ogr_1_3_4{i in N, j in N}:
- f[i,j] <= u[i,j];
- Ogr_2{k in Nzw}:
- sum {i in Nz} f[k,i] = sum {j in Nw} f[j,k];
- # Koszt zakupu surowcow
- Ogr_9{z in Z, s1 in S1}:
- a1 <= f[z,s1] - 2387;
- Ogr_10{z in Z, s1 in S1}:
- a2 <= f[z,s1] - 6659;
- Ogr_11{z in Z, s2 in S2}:
- b1 >= f[z,s2] - 2090;
- Ogr_l2{z in Z, s2 in S2}:
- b2 >= f[z,s2] - 4349;
- # Transport surowca S1
- Ogr_13{s1 in S1, g1 in G1}:
- cp1 >= f[s1,g1] / 18;
- # Transport surowca S2
- Ogr_14{s2 in S2, p2 in P2}:
- ep2 >= f[s2,p2] / 25;
- # Praca przygotowalni
- Ogr_15:
- sum {i in N, p in P} f[i,p] <= 16000;
- Ogr_16{p in P, d in D}:
- (sum {i in N} f[i,p]) * m[p,d] = f[p,d];
- # Koszt pracy przygotowalni
- Ogr_17:
- l >= (sum {i in N, p in P} f[i,p])/150;
- # Transprot S2 do obrobki cieplnej
- Ogr_18{s2 in S2, o2 in O2}:
- eo2 >= f[s2,o2] / 25;
- # Praca zakladu obrobki cieplnej
- Ogr_19{s2 in S2, o2 in O2}:
- f[s2,o2] <= 6000;
- # Minimalna dostarczona ilosc wyrobow
- Ogr_20{w in W}:
- sum {i in N} f[i,w] >= 5000;
- # Na jedna lokomotywe przypada co najwyzej 12 wagonow
- Ogr_21:
- 12 * wl >= cp1;
-
-solve;
-display {i in N, j in N: f[i,j] > 0}: f[i,j];
-display: a1; display: a2; display: b1; display: b2; display: wl;
-display: cp1; display: ep2; display: eo2; display:
-e1; display: l;
-\end{lstlisting}
-
-\begin{lstlisting}[caption= plik dat]
-data;
-set Z := z;
-set S := s1, s2;
-set S1 := s1;
-set S2 := s2;
-set G1 := g1;
-set P := p1, p2;
-set P2 := p2;
-set O2 := o2;
-set D := d1, d2;
-set W := w1, w2;
-set N := z, s1, s2, g1, p1, p2, o2, d1, d2, w1, w2;
-set Nz := s1, s2, g1, p1, p2, o2, d1, d2, w1, w2;
-set Nw := z, s1, s2, g1, p1, p2, o2, d1, d2;
-set Nzw := s1, s2, g1, p1, p2, o2, d1, d2;
-param r := w1 467 w2 480;
-param u :=
-z z 0 z s1 12000 z s2 8000 z g1 0 z p1 0
-z p2 0 z o2 0 z d1 0 z d2 0 z w1 0 z w2 0
-s1 z 0 s1 s1 0 s1 s2 0 s1 g1 99999 s1 p1 0
-s1 p2 0 s1 o2 0 s1 d1 0 s1 d2 0 s1 w1 0 s1 w2 0
-s2 z 0 s2 s1 0 s2 s2 0 s2 g1 0 s2 p1 0
-s2 p2 99999 s2 o2 99999 s2 d1 0 s2 d2 0 s2 w1 0 s2 w2 0
-g1 z 0 g1 s1 0 g1 s2 0 g1 g1 0 g1 p1 99999
-g1 p2 0 g1 o2 0 g1 d1 0 g1 d2 0 g1 w1 0 g1 w2 0
-p1 z 0 p1 s1 0 p1 s2 0 p1 g1 0 p1 p1 0
-p1 p2 0 p1 o2 0 p1 d1 99999 p1 d2 99999 p1 w1 0 p1 w2 0
-p2 z 0 p2 s1 0 p2 s2 0 p2 g1 0 p2 p1 0
-p2 p2 0 p2 o2 0 p2 d1 99999 p2 d2 99999 p2 w1 0 p2 w2 0
-o2 z 0 o2 s1 0 o2 s2 0 o2 g1 0 o2 p1 0
-o2 p2 0 o2 o2 0 o2 d1 0 o2 d2 0 o2 w1 0 o2 w2 99999
-d1 z 0 d1 s1 0 d1 s2 0 d1 g1 0 d1 p1 0
-d1 p2 0 d1 o2 0 d1 d1 0 d1 d2 0 d1 w1 99999 d1 w2 0
-d2 z 0 d2 s1 0 d2 s2 0 d2 g1 0 d2 p1 0
-d2 p2 0 d2 o2 0 d2 d1 0 d2 d2 0 d2 w1 0 d2 w2 99999
-w1 z 0 w1 s1 0 w1 s2 0 w1 g1 0 w1 p1 0
-w1 p2 0 w1 o2 0 w1 d1 0 w1 d2 0 w1 w1 0 w1 w2 0
-w2 z 0 w2 s1 0 w2 s2 0 w2 g1 0 w2 p1 0
-w2 p2 0 w2 o2 0 w2 d1 0 w2 d2 0 w2 w1 0 w2 w2 0;
-param m := p1 d1 0.1 p1 d2 0.9 p2 d1 0.1 p2 d2 0.9;
-end;
-\end{lstlisting}
-
-\section{Wyniki}
-Model z takimi ograniczeniami \textbf{nie znajduje} rozwiązania \\
-Problemem jest tu ogranicznie mówiące o tym że należy dostaczyć co najmniej \textbf{5000} ton \textbf{każdego} produktu \\
-To ograniczenie jest niewykonywalne gdyż nawet zakładając dostarczenie maksymalnej liczby ton surowców (12000 + 8000 = 20000) ton, i ignorując ograniczenie przepustowośći przygotowalni 16000 ton, nie jesteśmy w stanie wytworzyć wystarczająco półproduktu D1 aby wytworzyć wystarczająco wyrobu W1 \\
-gdybyśmy całość dostępnych surowców (znowu, ignorując przepustowość przygotowalni), zużyli na wytwarzanie tylko i wyłącznie półproduktu D1 z którego potem uzyskujemy wyrób W1, otrzymalibyśmy:
-\[ (12000 + 8000) * 0.1 = 20000 * 0.1 = 2000 \]
-maksymalna liczba ton wyrobu W1 którą możemy uzyskać, ignorując przepustowość przygotowywalni oraz wymagania dotyczące W2 wynosi 2000 ton, czyli mniej niż 5000 wymaganych ton \\
-W związku z tym wyniki przedstawione niżej dotyczącą przypadku w którym \textbf{ignorujemy} ograniczenie związane z minimalną liczbą ton każdego produktu który musimy dostarczyć (ograniczenie 20) \\
-\begin{figure}[H]
-\caption{}
-\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
-\hline
- & z & S1 & S2 & G1 & P1 & P2 & O2 & D1 & D2 & W1 & W2 \\
-\hline
-z & 0 & 12000 & 8000 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
-\hline
-S1 & 0 & 0 & 0 & 12000 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
-\hline
-S2 & 0 & 0 & 0 & 0 & 0 & 2000 & 6000 & 0 & 0 & 0 & 0 \\
-\hline
-G1 & 0 & 0 & 0 & 0 & 12000 & 0 & 0 & 0 & 0 & 0 & 0 \\
-\hline
-P1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1200 & 10800 & 0 & 0 \\
-\hline
-P2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 200 & 1800 & 0 & 0 \\
-\hline
-O2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 6000 \\
-\hline
-D1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1400 & 0 \\
-\hline
-D2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 12600 \\
-\hline
-W1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
-\hline
-W2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
-\hline
-
-\end{tabular}
-\end{figure}
-
-\[ a_1 = 9613 \]
-\[ a_2 = 5341 \]
-\[ b_1 = 5910 \]
-\[ b_2 = 3651 \]
-\[ w_1 = 56 \]
-\[ c_{P1} = 667 \]
-\[ e_{P2} = 80 \]
-\[ e_{O2} = 240 \]
-\[ e_1 = 0 \]
-\[ e_2 = 0 \]
-\[ l = 94 \]
-Ponownie, wyniki powyżej są prawdziwe wyłącznie dla przypadku w którym \textbf{ignorujemy ograniczenie numer 20}
-
+ \input{sections/01-parametry}
+ \input{sections/02-zmienne-decyzyjne}
+ \input{sections/03-zmienne-pomocnicze}
+ \input{sections/04-funkcja-celu}
+ \input{sections/05-ograniczenia}
+ \input{sections/06-model-sieciowy}
+ \input{sections/07-implementacja-modelu}
+ \input{sections/08-wyniki}
\end{document}
\ No newline at end of file
diff --git a/NotProgramming/MOM/report_two/sections/01-parametry.tex b/NotProgramming/MOM/report_two/sections/01-parametry.tex
new file mode 100644
index 00000000..79de20ce
--- /dev/null
+++ b/NotProgramming/MOM/report_two/sections/01-parametry.tex
@@ -0,0 +1,13 @@
+\section{Parametry}
+z - stan początkowy \\
+S - zakupione surowce (S = \{S1, S2\}) \\
+G1 - surowiec S1 załadowany do wagonów \\
+P - surowce w przygotowywalni (P = \{P1, P2\}) \\
+O2 - surowiec S2 w zakładzie obróbki cieplnej \\
+D - półprodukty (D = \{D1, D2\}) \\
+W - wyroby (W = \{W1, W2\}) \\
+N - stany surowców/półproduktów/wyrobów (zakupione surowce, surowce w przechowalni, surowce w zakładzie obróbki cieplnej, półprodukty, wyroby) \\
+$r_w$ - cena sprzedaży wyrobu $w[\frac{1}{t}]$ \\
+$u_{ij}$ - przepustowośc przepływu ze stanu i do stanu j[t] \\
+$m_{pd}$ - mnożnik definiujący przepływ ze stanu 'surowiec w przygotowalni p' do stanu 'półprodukt d'
+
diff --git a/NotProgramming/MOM/report_two/sections/02-zmienne-decyzyjne.tex b/NotProgramming/MOM/report_two/sections/02-zmienne-decyzyjne.tex
new file mode 100644
index 00000000..50bd6307
--- /dev/null
+++ b/NotProgramming/MOM/report_two/sections/02-zmienne-decyzyjne.tex
@@ -0,0 +1,2 @@
+\section{Zmienne decyzyjne}
+$f_{ij}$ = przepływ pomiędzy stanem i a stanem j [t] \\
diff --git a/NotProgramming/MOM/report_two/sections/03-zmienne-pomocnicze.tex b/NotProgramming/MOM/report_two/sections/03-zmienne-pomocnicze.tex
new file mode 100644
index 00000000..7cff9da0
--- /dev/null
+++ b/NotProgramming/MOM/report_two/sections/03-zmienne-pomocnicze.tex
@@ -0,0 +1,11 @@
+\section{Zmienne pomocnicze}
+$a_1$ - liczba zakupionego surowca S1 powyżej 2387 ton [t] \\
+$a_2$ - liczba zakupionego surowca S1 powyżej 6659 ton [t] \\
+$b_1$ - liczba zakupionego surowca S2 powyżej 2090 ton [t] \\
+$b_2$ - liczba zakupionego surowca S2 powyżej 4349 ton [t] \\
+$c_{P1}$ - liczba wagonów transportujących surowiec S1 do przygotowalni \\
+$e_{P2}$ - liczba ciężarówek transportujących surowiec S2 do przygotowalni \\
+$e_{O2}$ - liczba ciężarówek transportującyhc surowiec S2 do zakładu obróbki cieplnej \\
+$g_1$ - zmienna binarna przyjmująca wartość 1 gdy przepływ ze stanu "zakupiony surowiec S2" (S2) do stanu "surowiec S2 w zakładzie obróbki cieplnej" (O2) jest większy niż 2000 ton i mniejszy niż 4000 ton \\
+$g_2$ - zmienna binarna przyjmująca wartość 1 gdy przepływ ze stanu "zakupiony surowiec S2" (S2) do stanu "surowiec S2 w zakładzie obróbki cieplnej" (O2) jest większy niż 4000 ton i mniejszy niż 6000 ton \\
+l - liczba pracowników zatrudnionych w przygotowalni
diff --git a/NotProgramming/MOM/report_two/sections/04-funkcja-celu.tex b/NotProgramming/MOM/report_two/sections/04-funkcja-celu.tex
new file mode 100644
index 00000000..c791ab6b
--- /dev/null
+++ b/NotProgramming/MOM/report_two/sections/04-funkcja-celu.tex
@@ -0,0 +1,8 @@
+\section{Funkcja celu}
+\begin{align*}
+Q &= max[Zysk - Koszt] \\
+&= max[\sum_{i \in N, w \in W} r_w + f_{iw} \\
+&- (19f_{zS1} - 5a_1 - 4a_2 + 11f_{zS2} + 2b_1 + 2b_2 \\
+&+ 1290c_{P1} + 1500e_{P2} +1500e_{O2} + 160l + 10000g_1 + 40000g_2)]
+\end{align*}
+
diff --git a/NotProgramming/MOM/report_two/sections/05-ograniczenia.tex b/NotProgramming/MOM/report_two/sections/05-ograniczenia.tex
new file mode 100644
index 00000000..c45ee516
--- /dev/null
+++ b/NotProgramming/MOM/report_two/sections/05-ograniczenia.tex
@@ -0,0 +1,96 @@
+\section{Ograniczenia}
+\subsection{Ogólne}
+Przepływ musi być nieujemny oraz mniejszy przepustowości
+\begin{equation}
+0 \leq f_{ij} \leq u_{ij}, \qquad (i,j) \in N \\
+\end{equation}
+Wszystko co przypłyneło do stanu k musi stamtąd "odpłynąć"
+\begin{equation}
+\sum_{i \in N \backslash \{z\}} f_{ki} = \sum_{i \in N \backslash \{W\}} f_{jk}, \qquad k \in N \backslash \{z, W\}
+\end{equation}
+
+\subsection{Dostępne surowce}
+Nie możemy kupić więcej surowca S1 niż jest dostępne
+\begin{equation}
+f_{zS1} \leq 12000
+\end{equation}
+Nie możemy kupić więcej surowca S2 niż jest dostępne
+\begin{equation}
+f_{zS2} \leq 8000
+\end{equation}
+
+\subsection{Koszt zakupu surowców}
+Nie możemy kupić mniej niż 0 surowców
+\begin{equation}
+a_1 \geq 0
+\end{equation}
+\begin{equation}
+a_2 \geq 0
+\end{equation}
+\begin{equation}
+b_1 \geq 0
+\end{equation}
+\begin{equation}
+b_2 \geq 0
+\end{equation}
+Ograniczamy ile ton ponad dany limit kupiliśmy
+\begin{equation}
+a_1 \leq f_{zS1} - 2387
+\end{equation}
+liczba powyżej 2056 ton
+\begin{equation}
+a_2 \leq f_{zS1} - 6659
+\end{equation}
+liczba powyżej 2056 ton
+\begin{equation}
+b_1 \leq f_{zS2} - 2090
+\end{equation}
+liczba powyżej 2056 ton
+\begin{equation}
+b_2 \leq f_{zS2} - 4349
+\end{equation}
+\subsection{Transport surowca S1 do przygotowalni}
+wagon może przetransportować maks. 18 ton surowca S1
+\begin{equation}
+b_{P1} \geq [\frac{ f_{S1, G1} }{18}]
+\end{equation}
+\subsection{Transport surowca S2 do przygtowalni}
+ciężarówka może przetransportować maks. 25 ton surowca S2
+\begin{equation}
+c_{P2} \geq [ \frac{ f_{S2, P2} }{ 25 } ]
+\end{equation}
+\subsection{Praca przygotowalni}
+Przygotowalnia nie może mieć więcej surowców niż przepustowości
+\begin{equation}
+\sum_{i \in N, p \in P} f_{ip} \leq 16000
+\end{equation}
+ilość półproduktów w zależności od surowca
+\begin{equation}
+(\sum_{i \in N} f_{ip}) m_{pd} = f_{pd}, \qquad i \in N, p \in P, d \in D
+\end{equation}
+\subsection{Koszt pracy przygotowalni}
+3 pracowników może obsługiwać maksymalnie 150 ton całkowitej ilości przerabianych surowców
+\begin{equation}
+l \geq [ \frac{ \sum_{i\in N, p \in P} f_{ip} }{150} ]
+\end{equation}
+\subsection{Transport S2 do zakładu obróbki cieplnej}
+ciężarówka może przetransportować maks. 25 ton surowca S2
+\begin{equation}
+c_{O2} \geq [\frac{ f_{S2, O2} }{25}]
+\end{equation}
+\subsection{Praca zakładu obróbki cieplnej}
+ilość surowca S2 w zakładzie obróbki cieplnej nie może być większa od 6000
+\begin{equation}
+f_{S2, O2} \leq 6000
+\end{equation}
+\subsection{Minimalna dostarczona ilość wyrobów}
+Zgodnie z umową musimy dostarczyć przynajmniej 5000 ton wyrobów
+\begin{equation}
+\sum_{i \in N f_{iw}} \geq 5000, \qquad w \in W
+\end{equation}
+\subsection{Maksymalna liczba wagonow}
+Na jedna lokomotywę, nie może przypadać więcej niż 12 wagonów
+\begin{equation}
+12wl \geq c_{P1}
+\end{equation}
+
diff --git a/NotProgramming/MOM/report_two/sections/06-model-sieciowy.tex b/NotProgramming/MOM/report_two/sections/06-model-sieciowy.tex
new file mode 100644
index 00000000..04d8b31f
--- /dev/null
+++ b/NotProgramming/MOM/report_two/sections/06-model-sieciowy.tex
@@ -0,0 +1,3 @@
+\section{Model sieciowy}
+\includepdf{mom2.drawio.pdf}
+
diff --git a/NotProgramming/MOM/report_two/sections/07-implementacja-modelu.tex b/NotProgramming/MOM/report_two/sections/07-implementacja-modelu.tex
new file mode 100644
index 00000000..3fe1a265
--- /dev/null
+++ b/NotProgramming/MOM/report_two/sections/07-implementacja-modelu.tex
@@ -0,0 +1,163 @@
+\section{Implementacja modelu}
+\begin{lstlisting}[caption= plik mod]
+# PARAMETRY
+# Stan poczatkowy
+set Z;
+# Zakupione surowce, s1 i s2
+set S; set S1; set S2;
+# Surowiec S1 zaladowany do wagonow
+set G1;
+# Surowce w przygotowywalni
+set P; set P1; set P2;
+# Surowiec S2 w zakladzie obrobki cieplnej
+set O2;
+# Polprodukty
+set D; set D1; set D2;
+# Wyroby
+set W; set W1; set W2;
+# Stany surowcow, zakupione, wyroby, obrobka cieplna
+set N; set Nz; set Nw; set Nzw;
+
+# Cena sprzedazy wyrobu
+param r{w in W};
+# Przepustowosc przeplwyu z jednego stanu do drugiego
+param u{i in N, j in N};
+# Mnoznik definijujacy przepwy ze stanu surowiec
+# w przygotowalni do stanu polprodukt
+param m{p in P, d in D};
+
+# ZMIENNE DECYZYJNE
+# przeplyw pomiedzy stanem i a stanem j
+var f{i in N, j in N}, >= 0, integer; # Ograniczenie 1
+
+# Zmienne pomocnicze
+# liczba zakupionego surowca S1 powyzej 2387 ton
+var a1, >= 0, integer; # Ograniczenie 5
+# liczba zakupionego surowca S1 powyzej 6659 ton
+var a2, >= 0, integer; # Ograniczenie 6
+# liczba zakupionego surowca S2 powyzej 2090 ton
+var b1, >= 0, integer; # Ograniczenie 7
+# liczba zakupionego surowca S2 powyzej 4349 ton
+var b2, >= 0, integer; # Ograniczenie 8
+# liczba wynajetych lokomotyw
+var wl, >= 0, integer;
+# liczba wagonow transportujacych surowiec S1 do przygotowalni
+var cp1, >= 0, integer;
+# liczba ciezarowek transportujacych surowiec S2 do przygotowalni
+var ep2, >= 0, integer;
+# liczba ciezarowek transportujacych surowiec S2
+# do zakladu obrobki cieplnej
+var eo2, >= 0, integer;
+var e1, >= 0, <=1, integer;
+var e2, >= 0, <=1, integer;
+# Liczba pracownikow
+var l, >= 0, integer;
+
+maximize Q: (sum {i in N, w in W} r[w] * f[i,w])
+- (19* (sum {z in Z, s1 in S1} f[z, s1] )
+- 5*a1
+- 4*a2
++ 11* sum {z in Z, s2 in S2} (f[z, s2])
++ 2*b1
++ 2*b2
++ 1290*cp1
++ 1500*ep2
++ 1500*eo2
++ 160*l
++ 10000*e1
++ 40000*e2);
+
+# OGRANICZENIA
+subject to
+ # Ogolne i Dostepne surowce
+ Ogr_1_3_4{i in N, j in N}:
+ f[i,j] <= u[i,j];
+ Ogr_2{k in Nzw}:
+ sum {i in Nz} f[k,i] = sum {j in Nw} f[j,k];
+ # Koszt zakupu surowcow
+ Ogr_9{z in Z, s1 in S1}:
+ a1 <= f[z,s1] - 2387;
+ Ogr_10{z in Z, s1 in S1}:
+ a2 <= f[z,s1] - 6659;
+ Ogr_11{z in Z, s2 in S2}:
+ b1 >= f[z,s2] - 2090;
+ Ogr_l2{z in Z, s2 in S2}:
+ b2 >= f[z,s2] - 4349;
+ # Transport surowca S1
+ Ogr_13{s1 in S1, g1 in G1}:
+ cp1 >= f[s1,g1] / 18;
+ # Transport surowca S2
+ Ogr_14{s2 in S2, p2 in P2}:
+ ep2 >= f[s2,p2] / 25;
+ # Praca przygotowalni
+ Ogr_15:
+ sum {i in N, p in P} f[i,p] <= 16000;
+ Ogr_16{p in P, d in D}:
+ (sum {i in N} f[i,p]) * m[p,d] = f[p,d];
+ # Koszt pracy przygotowalni
+ Ogr_17:
+ l >= (sum {i in N, p in P} f[i,p])/150;
+ # Transprot S2 do obrobki cieplnej
+ Ogr_18{s2 in S2, o2 in O2}:
+ eo2 >= f[s2,o2] / 25;
+ # Praca zakladu obrobki cieplnej
+ Ogr_19{s2 in S2, o2 in O2}:
+ f[s2,o2] <= 6000;
+ # Minimalna dostarczona ilosc wyrobow
+ Ogr_20{w in W}:
+ sum {i in N} f[i,w] >= 5000;
+ # Na jedna lokomotywe przypada co najwyzej 12 wagonow
+ Ogr_21:
+ 12 * wl >= cp1;
+
+solve;
+display {i in N, j in N: f[i,j] > 0}: f[i,j];
+display: a1; display: a2; display: b1; display: b2; display: wl;
+display: cp1; display: ep2; display: eo2; display:
+e1; display: l;
+\end{lstlisting}
+
+\begin{lstlisting}[caption= plik dat]
+data;
+set Z := z;
+set S := s1, s2;
+set S1 := s1;
+set S2 := s2;
+set G1 := g1;
+set P := p1, p2;
+set P2 := p2;
+set O2 := o2;
+set D := d1, d2;
+set W := w1, w2;
+set N := z, s1, s2, g1, p1, p2, o2, d1, d2, w1, w2;
+set Nz := s1, s2, g1, p1, p2, o2, d1, d2, w1, w2;
+set Nw := z, s1, s2, g1, p1, p2, o2, d1, d2;
+set Nzw := s1, s2, g1, p1, p2, o2, d1, d2;
+param r := w1 467 w2 480;
+param u :=
+z z 0 z s1 12000 z s2 8000 z g1 0 z p1 0
+z p2 0 z o2 0 z d1 0 z d2 0 z w1 0 z w2 0
+s1 z 0 s1 s1 0 s1 s2 0 s1 g1 99999 s1 p1 0
+s1 p2 0 s1 o2 0 s1 d1 0 s1 d2 0 s1 w1 0 s1 w2 0
+s2 z 0 s2 s1 0 s2 s2 0 s2 g1 0 s2 p1 0
+s2 p2 99999 s2 o2 99999 s2 d1 0 s2 d2 0 s2 w1 0 s2 w2 0
+g1 z 0 g1 s1 0 g1 s2 0 g1 g1 0 g1 p1 99999
+g1 p2 0 g1 o2 0 g1 d1 0 g1 d2 0 g1 w1 0 g1 w2 0
+p1 z 0 p1 s1 0 p1 s2 0 p1 g1 0 p1 p1 0
+p1 p2 0 p1 o2 0 p1 d1 99999 p1 d2 99999 p1 w1 0 p1 w2 0
+p2 z 0 p2 s1 0 p2 s2 0 p2 g1 0 p2 p1 0
+p2 p2 0 p2 o2 0 p2 d1 99999 p2 d2 99999 p2 w1 0 p2 w2 0
+o2 z 0 o2 s1 0 o2 s2 0 o2 g1 0 o2 p1 0
+o2 p2 0 o2 o2 0 o2 d1 0 o2 d2 0 o2 w1 0 o2 w2 99999
+d1 z 0 d1 s1 0 d1 s2 0 d1 g1 0 d1 p1 0
+d1 p2 0 d1 o2 0 d1 d1 0 d1 d2 0 d1 w1 99999 d1 w2 0
+d2 z 0 d2 s1 0 d2 s2 0 d2 g1 0 d2 p1 0
+d2 p2 0 d2 o2 0 d2 d1 0 d2 d2 0 d2 w1 0 d2 w2 99999
+w1 z 0 w1 s1 0 w1 s2 0 w1 g1 0 w1 p1 0
+w1 p2 0 w1 o2 0 w1 d1 0 w1 d2 0 w1 w1 0 w1 w2 0
+w2 z 0 w2 s1 0 w2 s2 0 w2 g1 0 w2 p1 0
+w2 p2 0 w2 o2 0 w2 d1 0 w2 d2 0 w2 w1 0 w2 w2 0;
+param m := p1 d1 0.1 p1 d2 0.9 p2 d1 0.1 p2 d2 0.9;
+end;
+\end{lstlisting}
+
diff --git a/NotProgramming/MOM/report_two/sections/08-wyniki.tex b/NotProgramming/MOM/report_two/sections/08-wyniki.tex
new file mode 100644
index 00000000..2937ca2c
--- /dev/null
+++ b/NotProgramming/MOM/report_two/sections/08-wyniki.tex
@@ -0,0 +1,53 @@
+\section{Wyniki}
+Model z takimi ograniczeniami \textbf{nie znajduje} rozwiązania \\
+Problemem jest tu ogranicznie mówiące o tym że należy dostaczyć co najmniej \textbf{5000} ton \textbf{każdego} produktu \\
+To ograniczenie jest niewykonywalne gdyż nawet zakładając dostarczenie maksymalnej liczby ton surowców (12000 + 8000 = 20000) ton, i ignorując ograniczenie przepustowośći przygotowalni 16000 ton, nie jesteśmy w stanie wytworzyć wystarczająco półproduktu D1 aby wytworzyć wystarczająco wyrobu W1 \\
+gdybyśmy całość dostępnych surowców (znowu, ignorując przepustowość przygotowalni), zużyli na wytwarzanie tylko i wyłącznie półproduktu D1 z którego potem uzyskujemy wyrób W1, otrzymalibyśmy:
+\[ (12000 + 8000) * 0.1 = 20000 * 0.1 = 2000 \]
+maksymalna liczba ton wyrobu W1 którą możemy uzyskać, ignorując przepustowość przygotowywalni oraz wymagania dotyczące W2 wynosi 2000 ton, czyli mniej niż 5000 wymaganych ton \\
+W związku z tym wyniki przedstawione niżej dotyczącą przypadku w którym \textbf{ignorujemy} ograniczenie związane z minimalną liczbą ton każdego produktu który musimy dostarczyć (ograniczenie 20) \\
+\begin{figure}[H]
+\caption{}
+\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
+\hline
+ & z & S1 & S2 & G1 & P1 & P2 & O2 & D1 & D2 & W1 & W2 \\
+\hline
+z & 0 & 12000 & 8000 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
+\hline
+S1 & 0 & 0 & 0 & 12000 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
+\hline
+S2 & 0 & 0 & 0 & 0 & 0 & 2000 & 6000 & 0 & 0 & 0 & 0 \\
+\hline
+G1 & 0 & 0 & 0 & 0 & 12000 & 0 & 0 & 0 & 0 & 0 & 0 \\
+\hline
+P1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1200 & 10800 & 0 & 0 \\
+\hline
+P2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 200 & 1800 & 0 & 0 \\
+\hline
+O2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 6000 \\
+\hline
+D1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1400 & 0 \\
+\hline
+D2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 12600 \\
+\hline
+W1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
+\hline
+W2 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
+\hline
+
+\end{tabular}
+\end{figure}
+
+\[ a_1 = 9613 \]
+\[ a_2 = 5341 \]
+\[ b_1 = 5910 \]
+\[ b_2 = 3651 \]
+\[ w_1 = 56 \]
+\[ c_{P1} = 667 \]
+\[ e_{P2} = 80 \]
+\[ e_{O2} = 240 \]
+\[ e_1 = 0 \]
+\[ e_2 = 0 \]
+\[ l = 94 \]
+Ponownie, wyniki powyżej są prawdziwe wyłącznie dla przypadku w którym \textbf{ignorujemy ograniczenie numer 20}
+
diff --git a/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa.tex b/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa.tex
new file mode 100644
index 00000000..99eff1eb
--- /dev/null
+++ b/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa.tex
@@ -0,0 +1,5 @@
+\section{Zadanie 1. Sieć przepływowa}
+
+ \input{sections/01-zadanie-1-siec-przeplywowa/01-model-sieciowy}
+ \input{sections/01-zadanie-1-siec-przeplywowa/02-rozwiazanie}
+ \input{sections/01-zadanie-1-siec-przeplywowa/03-waskie-gardlo}
diff --git a/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/01-model-sieciowy.tex b/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/01-model-sieciowy.tex
new file mode 100644
index 00000000..9d474580
--- /dev/null
+++ b/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/01-model-sieciowy.tex
@@ -0,0 +1,100 @@
+\subsection{Model sieciowy}
+\paragraph{Problem do rozwiązania}
+Należy rozwiązać problem najtańszego przepływu \\
+\begin{figure}[htb]
+\caption{Koszty transportowe i przepustowości na poszczególnych odcinkach}
+\begin{center}
+\begin{tabular}{ | c | c | c | c | c | c | }
+\hline
+ & D & E & F & G & H \\
+ \hline
+ A & 4, 15 & 2, 10 & - & - & -\\
+ \hline
+ B & 4, 4 & 3, 9 & - & 8, 9 & - \\
+ \hline
+ C & 2, 20 & 6, 10 & - & - & - \\
+ \hline
+ D & - & - & 3, 10 & 7, 3 & 2, 2 \\
+ \hline
+ E & 5, 20 & - & 7, 5 & 6, 5 & 3, 5 \\
+ \hline
+\end{tabular}
+\end{center}
+\end{figure}
+\begin{figure}[htb]
+\caption{Zdolności wydobywcze kopalń (w tys. ton)}
+\begin{center}
+\begin{tabular}{ | c | c |}
+\hline
+ $W_A$ & 10 \\
+ \hline
+$W_B$ & 13 \\
+ \hline
+ $W_C$ & 17 \\
+ \hline
+\end{tabular}
+\end{center}
+\end{figure}
+\begin{figure}[htb]
+\caption{Średnie zużycie dobowe węgla przez elektronie (w tys. ton)}
+\begin{center}
+\begin{tabular}{ | c | c |}
+\hline
+ $Z_F$ & 15 \\
+ \hline
+$Z_G$ & 13 \\
+ \hline
+ $Z_H$ & 7 \\
+ \hline
+\end{tabular}
+\end{center}
+\end{figure}
+\paragraph{Sformułowanie}
+Matematyczne sformułowanie zadania:
+\begin{enumerate}
+\item Parametry \\
+s - źródło \\
+B - Budynki (kopalnie, stacje, elektrownie) \\
+K - kopalnie \\
+$c_{ij}$ - koszt transportu z budynku i do budynku j ($c_{sk}$ = 0) \\
+$W_k$ - zdolność wydobywcza kopalni k [w tonach] \\
+$p_{ij}$ - przepustowość transportu z budynku i do budynku j [w tonach] ($u_{sk}$ = $W_k$) \\
+E - elektrownie \\
+$Z_e$ - średnie zużycie dobowe przez elektrownię e [w tonach] \\
+\item Zmienne decyzyjne
+$f_{ij}$ - przepływ transportu z budynku i do obiektu j \\
+\item Funkcja celu
+\begin{align*}
+ Q &= \min\left(\sum_{(i, j) \in B \backslash \{s\}} c_{ij} f_{ij}\right) \\
+ &= \min(4f_{AD} + 2f_{AE} + 4f_{BD} + 3f_{BE} + 8f_{BG} + 2f_{CD} \\
+ &\quad + 6f_{CE} + 3f_{DF} + 7f_{DG} + 2f_{DH} + 5f_{ED} + 7f_{EF} \\
+ &\quad + 6f_{EG} + 3f_{EH})
+\end{align*}
+
+\item Ograniczenia
+\begin{equation}
+ 0 \leq f_{sk} \leq W_k, \; k \in K = \{A, B, C\}
+\end{equation}
+\begin{equation}
+ f_{si} = 0, \; i \in B \backslash K
+\end{equation}
+\begin{equation}
+ f_{is} = 0, \; i \in B
+\end{equation}
+\begin{equation}
+ 0 \leq f_{ij} \leq p_{uj}, \; (i, j) \in B \backslash \{s\}
+\end{equation}
+\begin{equation}
+ f_{is} = 0, \; i \in B
+\end{equation}
+\begin{equation}
+ \sum_{b \in B} f_{be} \ge Z_e, \; e \in E = \{F, G, H\}
+\end{equation}
+\begin{equation}
+ \sum_{i \in B \backslash \{ s \} } f_{bi} \leq \sum_{j \in B} f_{bn}, \; b \in B \backslash \{s\}
+\end{equation}
+
+\end{enumerate}
+\paragraph{Narysowanie modelu}
+\includepdf[pages=-]{1flow.pdf}
+
diff --git a/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/02-rozwiazanie.tex b/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/02-rozwiazanie.tex
new file mode 100644
index 00000000..c4ee0dc3
--- /dev/null
+++ b/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/02-rozwiazanie.tex
@@ -0,0 +1,100 @@
+\subsection{Rozwiązanie}
+\paragraph{Zadanie programowania liniowego}
+
+\begin{lstlisting}[caption= plik dat]
+data;
+
+set BudynkiNaStart := s, A, B, C, D, E, F, G, H;
+set Budynki := A, B, C, D, E, F, G, H;
+set Elektrownie := F, G, H;
+
+param Z := F 15 G 13 H 7;
+
+param p :=
+s A 10 s B 13 s C 17 s D 0 s E 0 s F 0 s G 0 s H 0
+A A 0 A B 0 A C 0 A D 15 A E 10 A F 0 A G 0 A H 0
+B A 0 B B 0 B C 0 B D 4 B E 9 B F 0 B G 9 B H 0
+C A 0 C B 0 C C 0 C D 20 C E 10 C F 0 C G 0 C H 0
+D A 0 D B 0 D C 0 D D 0 D E 0 D F 10 D G 3 D H 2
+E A 0 E B 0 E C 0 E D 20 E E 0 E F 5 E G 5 E H 5
+F A 0 F B 0 F C 0 F D 0 F E 0 F F 0 F G 0 F H 0
+G A 0 G B 0 G C 0 G D 0 G E 0 G F 0 G G 0 G H 0
+H A 0 H B 0 H C 0 H D 0 H E 0 H F 0 H G 0 H H 0;
+
+param c :=
+s A 0 s B 0 s C 0 s D 0 s E 0 s F 0 s G 0 s H 0
+A A 0 A B 0 A C 0 A D 4 A E 2 A F 0 A G 0 A H 0
+B A 0 B B 0 B C 0 B D 4 B E 3 B F 0 B G 8 B H 0
+C A 0 C B 0 C C 0 C D 2 C E 6 C F 0 C G 0 C H 0
+D A 0 D B 0 D C 0 D D 0 D E 0 D F 3 D G 7 D H 2
+E A 0 E B 0 E C 0 E D 5 E E 0 E F 7 E G 6 E H 3
+F A 0 F B 0 F C 0 F D 0 F E 0 F F 0 F G 0 F H 0
+G A 0 G B 0 G C 0 G D 0 G E 0 G F 0 G G 0 G H 0
+H A 0 H B 0 H C 0 H D 0 H E 0 H F 0 H G 0 H H 0;
+
+end;
+\end{lstlisting}
+\begin{lstlisting}[caption= plik mod]
+set BudynkiNaStart;
+set Budynki;
+set Elektrownie;
+
+param Z{e in Elektrownie};
+param p{i in BudynkiNaStart, j in Budynki};
+param c{i in BudynkiNaStart, j in Budynki};
+
+var f{i in BudynkiNaStart, j in Budynki}, >= 0;
+
+minimize Q: sum {i in Budynki, j in Budynki} c[i,j] * f[i,j];
+
+subject to
+ Ograniczenie_jeden{i in BudynkiNaStart, j in Budynki}:
+ f[i,j] >= 0;
+ Ograniczenie_dwa{i in BudynkiNaStart, j in Budynki}:
+ f[i,j] <= p[i,j];
+ Ograniczenie_trzy{e in Elektrownie}:
+ sum {n in BudynkiNaStart} f[n,e] >= Z[e];
+ Ograniczenie_cztery{n in Budynki}:
+ sum {i in Budynki} f[n,i] <= sum {j in BudynkiNaStart} f[j,n];
+
+solve;
+display {i in Budynki, j in Budynki: f[i,j] > 0}: f[i,j];
+display: Q;
+\end{lstlisting}
+\paragraph{Wynik}
+\begin{lstlisting}[caption=Wynik z glpk]
+f[A,E].val = 10
+f[B,E].val = 4
+f[B,G].val = 9
+f[C,D].val = 12
+f[D,F].val = 10
+f[D,H].val = 2
+f[E,F].val = 5
+f[E,G].val = 4
+f[E,H].val = 5
+Q.val = 236
+\end{lstlisting}
+
+\begin{figure}[htb]
+\caption{Plan dostaw węgla}
+\begin{center}
+\begin{tabular}{ | c | c | c | c | c | c | }
+\hline
+ & D & E & F & G & H \\
+ \hline
+ A & 10 & - & - & - & -\\
+ \hline
+ B & 0 & 4 & - & 9 & - \\
+ \hline
+ C & 12 & - & - & - & - \\
+ \hline
+ D & - & - & 10 & - & 2 \\
+ \hline
+ E & - & - & 5 & 4 & 5 \\
+ \hline
+\end{tabular}
+\end{center}
+\end{figure}
+
+\[ Q = 236 \]
+
diff --git a/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/03-waskie-gardlo.tex b/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/03-waskie-gardlo.tex
new file mode 100644
index 00000000..231058cb
--- /dev/null
+++ b/NotProgramming/MOM/sections/01-zadanie-1-siec-przeplywowa/03-waskie-gardlo.tex
@@ -0,0 +1,99 @@
+\subsection{Wąskie gardło}
+Następny szukamy przekroju o jak najmniejszej przepustowości \\
+W tym celu usunęliśmy parametry dotyczące średniego zużycia dobowego oraz kosztów transportu i zostawiliśmy wyłącznie przepustowość
+\begin{lstlisting}[caption= plik dat]
+data;
+
+set BudynkiNaStart := s, A, B, C, D, E, F, G, H;
+set Budynki := A, B, C, D, E, F, G, H;
+set Elektrownie := F, G, H;
+
+param p :=
+s A 10 s B 13 s C 17 s D 0 s E 0 s F 0 s G 0 s H 0
+A A 0 A B 0 A C 0 A D 15 A E 10 A F 0 A G 0 A H 0
+B A 0 B B 0 B C 0 B D 4 B E 9 B F 0 B G 9 B H 0
+C A 0 C B 0 C C 0 C D 20 C E 10 C F 0 C G 0 C H 0
+D A 0 D B 0 D C 0 D D 0 D E 0 D F 10 D G 3 D H 2
+E A 0 E B 0 E C 0 E D 20 E E 0 E F 5 E G 5 E H 5
+F A 0 F B 0 F C 0 F D 0 F E 0 F F 0 F G 0 F H 0
+G A 0 G B 0 G C 0 G D 0 G E 0 G F 0 G G 0 G H 0
+H A 0 H B 0 H C 0 H D 0 H E 0 H F 0 H G 0 H H 0;
+
+end;
+\end{lstlisting}
+\begin{lstlisting}[caption= plik mod]
+set BudynkiNaStart;
+set Budynki;
+set Elektrownie;
+
+param p{i in BudynkiNaStart, j in Budynki};
+
+var f{i in BudynkiNaStart, j in Budynki}, >= 0;
+
+maximize Q: sum {i in Budynki, e in Elektrownie} f[i,e];
+
+subject to
+ Ograniczenie_jeden{i in BudynkiNaStart, j in Budynki}:
+ f[i,j] >= 0;
+ Ograniczenie_dwa{i in BudynkiNaStart, j in Budynki}:
+ f[i,j] <= p[i,j];
+ Ograniczenie_trzy{n in Budynki}:
+ sum {i in Budynki} f[n,i] <= sum {j in BudynkiNaStart} f[j,n];
+
+solve;
+display {i in Budynki, j in Budynki: f[i,j] > 0}: f[i,j];
+display: Q;
+\end{lstlisting}
+
+\paragraph{Wyniki}
+\begin{lstlisting}[caption=Wynik z glpk]
+f[A,D].val = 9
+f[A,E].val = 1
+f[B,E].val = 4
+f[B,G].val = 9
+f[C,D].val = 6
+f[C,E].val = 10
+f[D,F].val = 10
+f[D,G].val = 3
+f[D,H].val = 2
+f[E,F].val = 5
+f[E,G].val = 5
+f[E,H].val = 5
+Q.val = 39
+\end{lstlisting}
+
+\begin{figure}[htb]
+\caption{Wyniki poszukiwań wąskiego gardła}
+\begin{center}
+\begin{tabular}{ | c | c | c | c | c | c | }
+\hline
+ & D & E & F & G & H \\
+ \hline
+ A & 9 & 1 & - & - & -\\
+ \hline
+ B & - & 4 & - & 9 & - \\
+ \hline
+ C & 6 & 10 & - & - & - \\
+ \hline
+ D & - & - & 10 & 3 & 2 \\
+ \hline
+ E & - & - & 5 & 5 & 5 \\
+ \hline
+\end{tabular}
+\end{center}
+\end{figure}
+
+\[ Q = 39 \]
+
+\includepdf[pages=-]{flow12.pdf}
+
+\paragraph{Wnioski}
+Następujące przepływy są zbyt niskie w porównaniu do przepustowości:
+\[ p_{AD} = 9 \le 15 \]
+\[ p_{AE} = 1 \le 10 \]
+\[ p_{BE} = 4 \le 9 \]
+\[ p_{CD} = 6 \le 20 \]
+Zwiększenie przepływów do poziomu maksymalnej przepustowości zwiększyło by wydajność sieci
+
+
+
diff --git a/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu.tex b/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu.tex
new file mode 100644
index 00000000..9f4f56bb
--- /dev/null
+++ b/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu.tex
@@ -0,0 +1,4 @@
+\section{Zadanie 2. Zadanie przydziału}
+ \input{sections/02-zadanie-2-zadanie-przydzialu/01-zadanie-2-1-planowanie-realizacji-portfela}
+ \input{sections/02-zadanie-2-zadanie-przydzialu/02-zadanie-2-2-minimalizacja-kosztow-realizacji}
+ \input{sections/02-zadanie-2-zadanie-przydzialu/03-zadanie-2-3-minimalizacja-terminu-realizacji}
diff --git a/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/01-zadanie-2-1-planowanie-realizacji-portfela.tex b/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/01-zadanie-2-1-planowanie-realizacji-portfela.tex
new file mode 100644
index 00000000..cb02094f
--- /dev/null
+++ b/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/01-zadanie-2-1-planowanie-realizacji-portfela.tex
@@ -0,0 +1,152 @@
+\subsection{Zadanie 2.1 Planowanie realizacji portfela przy ograniczonych kompetencjach}
+\begin{figure}[htb]
+\caption{Kompetencje zespołów}
+\begin{center}
+\begin{tabular}{ | c | c | c | c | c | c | c | }
+\hline
+ & A & B & C & D & E & F \\
+ \hline
+ 1 & - & X & - & X & X & - \\
+ \hline
+ 2 & - & X & X & - & X & - \\
+ \hline
+ 3 & X & - & - & X & - & X \\
+ \hline
+ 4 & X & - & X & - & - & X \\
+ \hline
+ 5 & - & X & - & - & X & X \\
+ \hline
+ 6 & X & - & X & X & - & - \\
+ \hline
+\end{tabular}
+\end{center}
+\end{figure}
+\subsubsection{Problem do rozwiązania}
+\paragraph{Sformułowanie}
+Matematyczne sformułowanie zadania:
+\begin{enumerate}
+\item Parametry \\
+s - źródło \\
+w - wyjście \\
+N - węzły (N = {s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F})
+P - projekty (P = {1, 2, 3, 4, 5, 6} $\subseteq$ N)
+Z - zespoły (Z = {A, B, C, D, E, F} $\subseteq$ N)
+$u_{ij}$ - przepustowość pomiędzy węzłem i a węzłem j
+\item Zmienne decyzyjne
+$f_{ij}$ - przepływ między węzłem i a węzłem j
+\item Funkcja celu
+\begin{align*}
+ Q &= \max\left(\sum_{p \in P} f_{pt} \right) \\
+ &= \max(f_{1t} + f_{2t} + f_{3t} + f_{4t} + f{5t} + f_{6t})
+\end{align*}
+
+\item Ograniczenia
+\setcounter{equation}{0}
+\begin{equation}
+0 \leq f_{ij} \leq 1, (i, j) \in N
+\end{equation}
+\begin{equation}
+0 \leq f_{zp} \leq u_{zp}, z \in Z, p \in P
+\end{equation}
+\begin{equation}
+f_{si} = 0, i \in \{ s, t, 1, 2, 3, 4, 5, 6 \}
+\end{equation}
+\begin{equation}
+f_{is} = 0, i \in N
+\end{equation}
+\begin{equation}
+f_{ti} = 0, i \in N
+\end{equation}
+\begin{equation}
+f_{it} = 0, i \in \{s, t, A, B, C, D, E, F\}
+\end{equation}
+\begin{equation}
+\sum_{z \in Z} f_{zp} = 1, p \in P = \{ 1, 2, 3, 4, 5, 6 \}
+\end{equation}
+
+\begin{equation}
+\sum_{p \in P} f_{zp} = 1, z \in Z = \{ A, B, C, D, E, F \}
+\end{equation}
+
+\begin{equation}
+\sum_{i \in N \backslash \{s\}} f_{ni} = \sum_{j \in N \backslash \{t\}} f_{jn}, n \in N \backslash \{ s, t \}
+\end{equation}
+
+
+
+\end{enumerate}
+
+\paragraph{Model sieciowy rysunek}
+\includepdf[pages=-]{flowchart21.pdf}
+\paragraph{Rozwiazanie}
+\begin{lstlisting}[caption= plik dat]
+data;
+
+set Wyjscie := t;
+set Wezly := 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set StartWezly := s, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set WyjscieWezly := t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set StartWyjscieWezly := s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set Projekty := 1, 2, 3, 4, 5, 6;
+set Zespoly := A, B, C, D, E, F;
+
+param u :=
+A 1 0 A 2 0 A 3 1 A 4 1 A 5 0 A 6 1
+B 1 1 B 2 1 B 3 0 B 4 0 B 5 1 B 6 0
+C 1 1 C 2 0 C 3 1 C 4 0 C 5 0 C 6 1
+D 1 1 D 2 0 D 3 1 D 4 0 D 5 0 D 6 1
+E 1 1 E 2 1 E 3 0 E 4 0 E 5 1 E 6 0
+F 1 0 F 2 0 F 3 1 F 4 1 F 5 1 F 6 0;
+
+end;
+\end{lstlisting}
+\begin{lstlisting}[caption= plik mod]
+set Wyjscie;
+set Wezly;
+set StartWezly;
+set WyjscieWezly;
+set StartWyjscieWezly;
+set Projekty;
+set Zespoly;
+
+param u{z in Zespoly, p in Projekty};
+
+var f{i in StartWyjscieWezly, j in StartWyjscieWezly}, >= 0;
+
+maximize Q: sum {p in Projekty, t in Wyjscie} f[p,t];
+
+ Ograniczeni_jeden{i in StartWyjscieWezly, j in StartWyjscieWezly}:
+ f[i,j] >= 0;
+ Ograniczeni_dwa{i in StartWyjscieWezly, j in StartWyjscieWezly}:
+ f[i,j] <= 1;
+ Ograniczeni_trzy{p in Projekty, z in Zespoly}:
+ f[z,p] <= u[z,p];
+ Ograniczeni_cztery{p in Projekty}:
+ sum {z in Zespoly} f[z,p] = 1;
+ Ograniczeni_piec{z in Zespoly}:
+ sum {p in Projekty} f[z,p] = 1;
+ Ograniczeni_szesc{n in Wezly}:
+ sum {i in WyjscieWezly} f[n,i] = sum {j in StartWezly} f[j,n];
+ solve;
+display {i in Wezly, j in Wezly: f[i,j] > 0}: f[i,j];
+display: Q;
+
+
+\end{lstlisting}
+\paragraph{Przydział zespołów do projektów}
+\begin{lstlisting}[caption=wynik z glpk]
+f[A,6].val = 1
+f[B,5].val = 1
+f[C,1].val = 1
+f[D,3].val = 1
+f[E,2].val = 1
+f[F,4].val = 1
+Q.val = 6
+\end{lstlisting}
+Wyniki: \\
+Projekt numer \textbf{1} zostanie przydzielony zespołowi \textbf{C} \\
+Projekt numer \textbf{2} zostanie przydzielony zespołowi \textbf{E} \\
+Projekt numer \textbf{3} zostanie przydzielony zespołowi \textbf{D} \\
+Projekt numer \textbf{4} zostanie przydzielony zespołowi \textbf{F} \\
+Projekt numer \textbf{5} zostanie przydzielony zespołowi \textbf{B} \\
+Projekt numer \textbf{6} zostanie przydzielony zespołowi \textbf{A} \\
diff --git a/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/02-zadanie-2-2-minimalizacja-kosztow-realizacji.tex b/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/02-zadanie-2-2-minimalizacja-kosztow-realizacji.tex
new file mode 100644
index 00000000..050965b7
--- /dev/null
+++ b/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/02-zadanie-2-2-minimalizacja-kosztow-realizacji.tex
@@ -0,0 +1,146 @@
+\subsection{Zadanie 2.2 Minimalizacja kosztów realizacji projektów}
+\paragraph{Problem do rozwiązania}
+\begin{figure}[htb]
+\caption{Koszty wynajmu}
+\begin{center}
+\begin{tabular}{ | c | c | c | c | c | c | c | }
+\hline
+ & A & B & C & D & E & F \\
+ \hline
+ 1 & - & 13 & - & 14 & 18 & - \\
+ \hline
+ 2 & - & 4 & 2 & - & 3 & - \\
+ \hline
+ 3 & 2 & - & - & 10 & - & 13 \\
+ \hline
+ 4 & 10 & - & 5 & - & - & 15 \\
+ \hline
+ 5 & - & 10 & - & - & 17 & 12 \\
+ \hline
+ 6 & 20 & - & 6 & 16 & - & - \\
+ \hline
+\end{tabular}
+\end{center}
+\end{figure}
+
+\begin{enumerate}
+\item Parametry \\
+s - źródło \\
+w - wyjście \\
+N - węzły (N = {s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F})
+P - projekty (P = {1, 2, 3, 4, 5, 6} $\subseteq$ N)
+Z - zespoły (Z = {A, B, C, D, E, F} $\subseteq$ N)
+$k_{zp}$ - koszty przyporządkowania zespołu z do projektu p
+
+\item Zmienne decyzyjne:
+$f_{ij}$ - przeływ pomiędzy węzłem i oraz węzłem j
+\item Funkcja celu
+\begin{align*}
+ Q &= \min \left(\sum_{z \in Z, p \in P} c_{zp}f_{zp} \right) \\
+ &= \min \big( 13f_{B1} + 14f_{D1} + 18f_{E1} + 4f_{B2} + 2f_{C2} + 3f_{E2} \\
+ &\quad + 2f_{A3} + 10f_{D3} + 13f_{F3} + 10f_{A4} + 5f_{C4} + 15f_{F4} \\
+ &\quad + 10f_{B5} + 17f_{E5} + 12f_{F5} + 20f_{A6} + 6f_{C6} + 16f_{D6} \big)
+\end{align*}
+
+
+\item Ograniczenia
+\setcounter{equation}{0}
+\begin{equation}
+0 \leq f_{ij} \leq 1, (i, j) \in N
+\end{equation}
+\begin{equation}
+f_{si} = 0, i \in \{ s, t, 1, 2, 3, 4, 5, 6 \}
+\end{equation}
+\begin{equation}
+f_{is} = 0, i \in N
+\end{equation}
+\begin{equation}
+f_{ti} = 0, i \in N
+\end{equation}
+\begin{equation}
+f_{it} = 0, i \in \{s, t, A, B, C, D, E, F\}
+\end{equation}
+\begin{equation}
+\sum_{z \in Z} f_{zp} = 1, p \in P = \{ 1, 2, 3, 4, 5, 6 \}
+\end{equation}
+\begin{equation}
+\sum_{p \in P} f_{zp} = 1, z \in Z = \{ A, B, C, D, E, F \}
+\end{equation}
+\begin{equation}
+\sum_{i \in N \backslash \{s\}} f_{ni} = \sum_{j \in N \backslash \{t\}} f_{jn}, n \in N \backslash \{ s, t \}
+\end{equation}
+
+\end{enumerate}
+\paragraph{Model sieciowy rysunek}
+\includepdf[pages=-]{flowchart22.pdf}
+\paragraph{Rozwiazanie}
+\begin{lstlisting}[caption= plik dat]
+data;
+
+set Wyjscie := t;
+set Wezly := 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set StartWezly := s, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set WyjscieWezly := t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set StartWyjscieWezly := s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set Projekty := 1, 2, 3, 4, 5, 6;
+set Zespoly := A, B, C, D, E, F;
+
+param k :=
+A 1 1000 A 2 1000 A 3 2 A 4 10 A 5 1000 A 6 20
+B 1 13 B 2 4 B 3 1000 B 4 1000 B 5 10 B 6 1000
+C 1 1000 C 2 2 C 3 1000 C 4 5 C 5 1000 C 6 6
+D 1 14 D 2 1000 D 3 10 D 4 1000 D 5 1000 D 6 16
+E 1 18 E 2 3 E 3 1000 E 4 1000 E 5 17 E 6 1000
+F 1 1000 F 2 1000 F 3 13 F 4 15 F 5 12 F 6 1000;
+
+end;
+\end{lstlisting}
+\begin{lstlisting}[caption= plik mod]
+set Wyjscie;
+set Wezly;
+set StartWezly;
+set WyjscieWezly;
+set StartWyjscieWezly;
+set Projekty;
+set Zespoly;
+
+param k{z in Zespoly, p in Projekty};
+
+var f{i in StartWyjscieWezly, j in StartWyjscieWezly}, >= 0;
+
+minimize Q: sum {p in Projekty, z in Zespoly} k[z, p] * f[z, p];
+
+ Ograniczenie_jeden{i in StartWyjscieWezly, j in StartWyjscieWezly}:
+ f[i,j] >= 0;
+ Ograniczenie_dwa{i in StartWyjscieWezly, j in StartWyjscieWezly}:
+ f[i,j] <= 1;
+ Ograniczenie_trzy{p in Projekty}:
+ sum {z in Zespoly} f[z,p] = 1;
+ Ograniczenie_cztery{z in Zespoly}:
+ sum {p in Projekty} f[z,p] = 1;
+ Ograniczenie_piec{n in Wezly}:
+ sum {i in WyjscieWezly} f[n,i] = sum {j in StartWezly} f[j,n];
+ solve;
+display {i in Wezly, j in Wezly: f[i,j] > 0}: f[i,j];
+display: Q;
+
+
+
+\end{lstlisting}
+\paragraph{Przydział zespołów do projektów}
+\begin{lstlisting}[caption=wynik z glpk]
+f[A,3].val = 1
+f[B,5].val = 1
+f[C,6].val = 1
+f[D,1].val = 1
+f[E,2].val = 1
+f[F,4].val = 1
+Q.val = 50
+\end{lstlisting}
+Wyniki: \\
+Projekt numer \textbf{1} zostanie przydzielony zespołowi \textbf{D} \\
+Projekt numer \textbf{2} zostanie przydzielony zespołowi \textbf{E} \\
+Projekt numer \textbf{3} zostanie przydzielony zespołowi \textbf{A} \\
+Projekt numer \textbf{4} zostanie przydzielony zespołowi \textbf{F} \\
+Projekt numer \textbf{5} zostanie przydzielony zespołowi \textbf{B} \\
+Projekt numer \textbf{6} zostanie przydzielony zespołowi \textbf{C} \\
diff --git a/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/03-zadanie-2-3-minimalizacja-terminu-realizacji.tex b/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/03-zadanie-2-3-minimalizacja-terminu-realizacji.tex
new file mode 100644
index 00000000..e72a586b
--- /dev/null
+++ b/NotProgramming/MOM/sections/02-zadanie-2-zadanie-przydzialu/03-zadanie-2-3-minimalizacja-terminu-realizacji.tex
@@ -0,0 +1,146 @@
+\subsection{Zadanie 2.3 Minimalizacja terminu realizacji puli projektów}
+\begin{figure}[htb]
+\caption{Czas realizacji projektów}
+\begin{center}
+\begin{tabular}{ | c | c | c | c | c | c | c | }
+\hline
+ & A & B & C & D & E & F \\
+ \hline
+ 1 & - & 13 & - & 14 & 18 & - \\
+ \hline
+ 2 & - & 4 & 2 & - & 3 & - \\
+ \hline
+ 3 & 2 & - & - & 10 & - & 13 \\
+ \hline
+ 4 & 10 & - & 5 & - & - & 15 \\
+ \hline
+ 5 & - & 10 & - & - & 17 & 12 \\
+ \hline
+ 6 & 20 & - & 6 & 16 & - & - \\
+ \hline
+\end{tabular}
+\end{center}
+\end{figure}
+
+\begin{enumerate}
+\item Parametry \\
+s - źródło \\
+w - wyjście \\
+N - węzły (N = {s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F})
+P - projekty (P = {1, 2, 3, 4, 5, 6} $\subseteq$ N)
+Z - zespoły (Z = {A, B, C, D, E, F} $\subseteq$ N)
+$t_{zp}$ - czas realizacji projektu p przez zespół z [w miesiącach]
+
+\item Zmienne decyzyjne:
+$f_{ij}$ - przeływ pomiędzy węzłem i oraz węzłem j
+\item Funkcja celu
+\begin{align*}
+ Q &= \min \left( \max_{z \in Z, p \in P} c_{zp} f_{zp} \right) \\
+ &= \min \big\{13f_{B1}, 14f_{D1}, 18f_{E1}, 4f_{B2}, 2f_{C2}, 3f_{E2}, \\
+ &\quad 2f_{A3}, 10f_{D3},13f_{F3}, 10f_{A4}, 5f_{C4}, 15f_{F4} \\
+ &\quad 10f_{B5}, 17f_{E5}, 12f_{F5}, 20f_{A6}, 6f_{C6}, 16f_{D6} \big\}
+\end{align*}
+
+
+\item Ograniczenia
+\setcounter{equation}{0}
+\begin{equation}
+0 \leq f_{ij} \leq 1, \; (i, j) \in N
+\end{equation}
+\begin{equation}
+f_{si} = 0, \; i \in \{ s, t, 1, 2, 3, 4, 5, 6 \}
+\end{equation}
+\begin{equation}
+f_{is} = 0, \; i \in N
+\end{equation}
+\begin{equation}
+f_{ti} = 0, \; i \in N
+\end{equation}
+\begin{equation}
+f_{it} = 0, \; i \in \{s, t, A, B, C, D, E, F\}
+\end{equation}
+\begin{equation}
+\sum_{z \in Z} f_{zp} = 1, \; p \in P = \{ 1, 2, 3, 4, 5, 6 \}
+\end{equation}
+\begin{equation}
+\sum_{p \in P} f_{zp} = 1, \; z \in Z = \{ A, B, C, D, E, F \}
+\end{equation}
+\begin{equation}
+\sum_{i \in N \backslash \{s\}} f_{ni} = \sum_{j \in N \backslash \{t\}} f_{jn}, \; n \in N \backslash \{ s, t \}
+\end{equation}
+
+\end{enumerate}
+\paragraph{Model sieciowy rysunek}
+\includepdf[pages=-]{flowchart22.pdf}
+\paragraph{Model programowania liniowego}
+\begin{lstlisting}[caption= plik dat]
+data;
+
+set Wyjscie := t;
+set Wezly := 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set StartWezly := s, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set WyjscieWezly := t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set StartWyjscieWezly := s, t, 1, 2, 3, 4, 5, 6, A, B, C, D, E, F;
+set Projekty := 1, 2, 3, 4, 5, 6;
+set Zespoly := A, B, C, D, E, F;
+
+param c :=
+A 1 1000 A 2 1000 A 3 2 A 4 10 A 5 1000 A 6 20
+B 1 13 B 2 4 B 3 1000 B 4 1000 B 5 10 B 6 1000
+C 1 1000 C 2 2 C 3 1000 C 4 5 C 5 1000 C 6 6
+D 1 14 D 2 1000 D 3 10 D 4 1000 D 5 1000 D 6 16
+E 1 18 E 2 3 E 3 1000 E 4 1000 E 5 17 E 6 1000
+F 1 1000 F 2 1000 F 3 13 F 4 15 F 5 12 F 6 1000;
+
+end;
+\end{lstlisting}
+\begin{lstlisting}[caption= plik mod]
+set Wyjscie;
+set Wezly;
+set StartWezly;
+set WyjscieWezly;
+set StartWyjscieWezly;
+set Projekty;
+set Zespoly;
+
+param c{z in Zespoly, p in Projekty};
+
+var f{i in StartWyjscieWezly, j in StartWyjscieWezly}, >= 0, integer;
+var cmax, >= 0;
+
+minimize Q: cmax;
+
+subject to
+ Ograniczenie_jeden{i in StartWyjscieWezly, j in StartWyjscieWezly}:
+ f[i,j] >= 0;
+ Ograniczenie_dwa{i in StartWyjscieWezly, j in StartWyjscieWezly}:
+ f[i,j] <= 1;
+ Ograniczenie_trzy{p in Projekty}:
+ sum {z in Zespoly} f[z,p] = 1;
+ Ograniczenie_cztery{z in Zespoly}:
+ sum {p in Projekty} f[z,p] = 1;
+ Ograniczenie_piec{n in Wezly}:
+ sum {i in WyjscieWezly} f[n,i] = sum {j in StartWezly} f[j,n];
+ Ograniczenie_szesc{z in Zespoly, p in Projekty}:
+ c[z,p] * f[z,p] <= cmax;
+solve;
+display {i in Wezly, j in Wezly: f[i,j] > 0}: f[i,j];
+display: Q;
+\end{lstlisting}
+
+\begin{lstlisting}[caption=wynik z glpk]
+f[A,4].val = 1
+f[B,1].val = 1
+f[C,6].val = 1
+f[D,3].val = 1
+f[E,2].val = 1
+f[F,5].val = 1
+Q.val = 13
+\end{lstlisting}
+Wyniki: \\
+Projekt numer \textbf{1} zostanie przydzielony zespołowi \textbf{B} \\
+Projekt numer \textbf{2} zostanie przydzielony zespołowi \textbf{E} \\
+Projekt numer \textbf{3} zostanie przydzielony zespołowi \textbf{D} \\
+Projekt numer \textbf{4} zostanie przydzielony zespołowi \textbf{A} \\
+Projekt numer \textbf{5} zostanie przydzielony zespołowi \textbf{F} \\
+Projekt numer \textbf{6} zostanie przydzielony zespołowi \textbf{C} \\
diff --git a/NotProgramming/MOM/sections/03-zadanie-3.tex b/NotProgramming/MOM/sections/03-zadanie-3.tex
new file mode 100644
index 00000000..8f46c4a3
--- /dev/null
+++ b/NotProgramming/MOM/sections/03-zadanie-3.tex
@@ -0,0 +1,42 @@
+\section{Zadanie 3}
+\paragraph{Model programowania liniowego}
+\begin{enumerate}
+\item Parametry \\
+m - liczba różnych zasobów, i $\in$ N \\
+n - liczba różnych produktów, j $\in$ N \\
+$c_{i}^{max}$ - Maksymalna przepustowość dla zasobu i \\
+$A_{ij}$ - Użycie zasobu i przez produkt j \\
+$q_j$ - Limit produkcji dla produktu j, po którym zmniejsza się przychód na jednostce \\
+$p_j$ - Normalny przychód na pojedyńczej sztuce produktu j \\
+$p_j^{disc}$ - Pomniejszony przychód na sztuce produktu j
+
+\item Zmienne decyzyjne
+$x_j$ - Wolumin produkcji produktu j
+\item Zmienne pomocnicze
+$r_j(u)$ - Funkcja wyliczająca przychód dla produktu j bazując na poziomie produkcji u \\
+$c_i$ - Całkowite zużycie zasobu typu i
+
+\item Funkcja celu
+\[ \max Z = \sum_{j=1}^n r_j u_j \]
+\[ r_j(u) = \{ \]
+\[ p_{j} u \qquad \qquad \qquad \qquad u <= q_j \]
+\[ p_j q_j + p_{j}^{disc}(u-q_j), \qquad u => q_j \]
+\[ \} \]
+
+\item Ograniczenia
+\setcounter{equation}{0}
+Całkowite zużycie zasobów nie może przekraczać dostępnośli dla żadnego zasobu
+\begin{equation}
+\sum_{j=1}^n A_{ij} \cdot x_j \leq c_i^{max}, \qquad i \in N
+\end{equation}
+Produkcja każdego produktu j, jest powiżana z właściwym $u_j$
+\begin{equation}
+u_j = x_j, \qquad j \in N
+\end{equation}
+Wolumin produkcji nie może być mniejszy od zera
+\begin{equation}
+x_j \geq 0, \qquad j \in N
+\end{equation}
+
+
+\end{enumerate}
diff --git a/NotProgramming/SDM/presentations/my_thesis/main.tex b/NotProgramming/SDM/presentations/my_thesis/main.tex
index 9bb3066c..2c4e5460 100644
--- a/NotProgramming/SDM/presentations/my_thesis/main.tex
+++ b/NotProgramming/SDM/presentations/my_thesis/main.tex
@@ -52,284 +52,7 @@
\tableofcontents
\end{frame}
-\section{Teoria}
-\begin{frame}
- \frametitle{Gra komputerowa}
- \large Aplikacja dostępna na platformie "Steam" oznaczona typem "Game"
-\end{frame}
-\begin{frame}
-\frametitle{Silnik do gier}
-\large Oprogramowanie zaprojektowane i stworzone do kreacji gier komputerowych
-\end{frame}
-
-\begin{frame}
- \frametitle{Nowoczesne}
- \large Ponad 1000 gier w tej dekadzie na platformie "Steam"
-\end{frame}
-
-
-{
- \setbeamercolor{footline}{fg=white}
-\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{steamdb_main.png}}
-\begin{frame}
-\end{frame}
-}
-
-
-{
-\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{steamdb_filter.drawio.pdf}}
-\begin{frame}
-\end{frame}
-}
-
-\begin{frame}
- \frametitle{Wybrane silniki - start}
- \begin{center}
- \includegraphics[width=0.8\paperwidth, height=0.8\paperheight]{usedEngines.pdf}
-\end{center}
-\end{frame}
-
-\begin{frame}
- \frametitle{Wybrane silniki}
- \begin{itemize}
- \item Wyeliminowanie nie generycznych - Ren'Py, RPGMaker
- \item Wybór najpopularniejszych - Unity, Unreal
- % Prawie 25k i ponad 7.5k
- \end{itemize}
-\end{frame}
-
-\begin{frame}
- \frametitle{Wydajność silnika}
- \begin{itemize}
- \item Klatki na sekundę (FPS)
- \item Zużycie CPU, GPU, RAM i VRAM
- \item Liczba draw calls
- \item Czas ładowania assetów
- \item Czas odpowiedzi na interakcję gracza
- \end{itemize}
-\end{frame}
-\begin{frame}
- \frametitle{Możliwości Silnika}
- \begin{itemize}
- \item Renderowanie grafiki
- % Ray tracing, HDR lighting, dynamic shadows, particle systems, animacja
- \item Silnik Fizyczny
- \item Multiplatformowość (VR)
- % Linux, Windows, MacOS, Android, IOs, Xbox, PlayStation, Nintendo, VR
- \item Skryptowanie logiki gier (AI)
- \item Gry online
- \item Sklepy z assetami
- \end{itemize}
- \end{frame}
- \section{Narzędzia}
- \frametitle{Unity Profiler}
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {unity_profiler.png}}
- \begin{frame}
- \end{frame}
- }
-
- \frametitle{Unreal Profiler}
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {unreal_profiler.jpg}}
- \begin{frame}
- \end{frame}
- }
-
- \frametitle{Nvidia nsight}
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {nvida_nsighty.jpg}}
- \begin{frame}
- \end{frame}
- }
-
-
- \begin{frame}
- \frametitle{Nsight - Analiza FPS}
- \center
- \includegraphics[width=1\textwidth]{fps_overview.png}
- % Ile klatek pokazaliśmy na ile
- % ile trwała średnio klatka
- % Ile trwała najkrótsza klatka
- % Ile trwała najdłuższa klatka
- % Przeciętne klatki na sekundę dla pokazanego wycinka
- % Tyle lub mniej czasu trwało 99% klatek
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Analiza FPS}
- \center
- \includegraphics[width=1\textwidth]{stutter_row.png}
- % Wykrywanie "zawieszek"
- % Wykrywamy klatki których długość
- % jest znacznie dłuższa od długości mediany pobliskich 19 klatek
- % zawieszka musi być dłuższa niż 4 milisekundy
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Analiza FPS}
- \center
- \includegraphics[width=1\textwidth]{dx12_frame_health.png}
- % Możemy sprawdzić jaka klatka miała zawieszkę
- % I jaka metoda w api tę zawieszkę spowodowała
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Zużycie VRAM}
- \center
- \includegraphics[width=1\textwidth]{memory_utilization.png}
- % Zielony -> ile pamięci mamy dostępnej
- % Pomarańczowy -> ile pamięci zużyliśmy
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Zużycie VRAM}
- \center
- \includegraphics[width=1\textwidth]{memory_utilization_gpu_vram.png}
- % VidMm Device Suspension -> okresy czasku kiedy przetransferowano
- % Jeden duży zasób pamięci
- % Demoted Memory -> w GPU mamy local memory (szybsze) i global memory
- % (wolniejsze) to może nam mówić o "wyciekach" pamięci
- % źle zooptymalizowanej pamięci itd.
- % Allokacja pamięci -> zielone aplikacja, szare -> system
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Zużycie VRAM}
- \center
- \includegraphics[width=1\textwidth]{memory_utilization_resource_migrations.png}
- % W kolejności co najwięcej zużyło zasobów
- % Konkretnie ile i kiedy
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Zużycie VRAM}
- \center
- \includegraphics[width=1\textwidth]{memory_utilization_memory_transfer.png}
- % W kolejności co najwięcej zużyło zasobów
- % Konkretnie ile i kiedy
- \end{frame}
-
- \begin{frame}
- \frametitle{Jak porównywać?}
- \begin{itemize}
- \item Stworzenie gry na obu
- \item Porównywanie istniejących gier
- \item Porównanie samych edytorów
- \end{itemize}
- \end{frame}
-
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {maxresdefault (1).jpg}}
- \begin{frame}
- \end{frame}
- }
-
- \begin{frame}
- \frametitle{Wybór gatunku}
- FPS:
- \begin{itemize}
- \item Wystarczająco skomplikowany
- \item Grafika
- \item Fizyka
- \item Klasyczny benchmark
- % Wolfenstein, Doom, Quake, Crysis
- \end{itemize}
- \end{frame}
- \begin{frame}
- \frametitle{Problem}
- Inklinacja Silnika \\
- \begin{itemize}
- \item $ \frac{2478}{39713} \approx 6\% $ gier Unity to FPS \\
- \item $ \frac{1765}{11158} \approx 15\% $ gier Unreal to FPS \\
- \end{itemize}
- Źródło: steamdb.info
- \end{frame}
-
- \begin{frame}
- \frametitle{Wybór gatunku}
- Bullet hell:
- \begin{itemize}
- \item Wystarczająco skomplikowany
- \item Grafika
- \item Czas jest ważny
- % W Bullet hell czas jest ważny, gra musi być płynna
- \end{itemize}
- \end{frame}
-
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {maxresdefault.jpg}}
- \begin{frame}
- \end{frame}
- }
- \begin{frame}
- \frametitle{Wyzwania}
- \begin{itemize}
- \item Sprzęt
- % Ten sam, jeden i ten sam komputer użyty w procesie kreacji obu
- \item Umiejętności
- % Nie mam
- \item Podobne wersje silnika
- % Użyje ostatniego LTS
- \item Inklinacja Silnika \\ (3\% Unity, 2.4\% Unreal)
- % ??? Ch
- % 1577 FPS UNITY, 271 FPS UNREAL
- % 39713 Total Unity, 11158 Total Unreal (proporcjonalnie 2 razy więcej :<)
- \end{itemize}
- \end{frame}
-
- \begin{frame}
- \frametitle{Ocena łatwości użycia}
- \begin{itemize}
- \item Dokumentacja
- \item Intuicyjność
- \item Materiały
- \item Zasoby (Assety)
- \item Dostępne funkcje
- \item ChatGPT
- \end{itemize}
- \end{frame}
-
-
-
- \begin{frame}
- \frametitle{Po stworzeniu}
- Przejść obie gry, monitorując używając Nvidia Nsight i porównać wyniki
- \end{frame}
-
-
- \section{Źródła}
-\begin{frame}
- \frametitle{Źródła}
- \begin{itemize}
- \item \href{https://steamdb.info/}{https://steamdb.info/}
- \item \href{https://docs.nvidia.com/nsight-systems}{https://docs.nvidia.com/nsight-systems}
- \item An Overview Study of Game Engines, Faizi Noor Ahmad
- \item Game Engine Architecture, Jason Gregory
- \end{itemize}
- \end{frame}
-
- \begin{frame}
- \frametitle{Źródła obrazów}
- \begin{itemize}
- \item Crysis - kanał youtube \href{https://www.youtube.com/watch?v=vGjOALIrL_U}{Thronefull}
- \item BulletHell - kanał youtube \href{https://www.youtube.com/watch?app=desktop&v=h-wr6LoETA0}{Beat that boss}
- \end{itemize}
- \end{frame}
-
+ \input{sections/01-teoria}
+ \input{sections/02-narzedzia}
+ \input{sections/03-zrodla}
\end{document}
diff --git a/NotProgramming/SDM/presentations/my_thesis/sections/01-teoria.tex b/NotProgramming/SDM/presentations/my_thesis/sections/01-teoria.tex
new file mode 100644
index 00000000..5716d7fe
--- /dev/null
+++ b/NotProgramming/SDM/presentations/my_thesis/sections/01-teoria.tex
@@ -0,0 +1,69 @@
+\section{Teoria}
+\begin{frame}
+ \frametitle{Gra komputerowa}
+ \large Aplikacja dostępna na platformie "Steam" oznaczona typem "Game"
+\end{frame}
+\begin{frame}
+\frametitle{Silnik do gier}
+\large Oprogramowanie zaprojektowane i stworzone do kreacji gier komputerowych
+\end{frame}
+
+\begin{frame}
+ \frametitle{Nowoczesne}
+ \large Ponad 1000 gier w tej dekadzie na platformie "Steam"
+\end{frame}
+
+
+{
+ \setbeamercolor{footline}{fg=white}
+\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{steamdb_main.png}}
+\begin{frame}
+\end{frame}
+}
+
+
+{
+\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{steamdb_filter.drawio.pdf}}
+\begin{frame}
+\end{frame}
+}
+
+\begin{frame}
+ \frametitle{Wybrane silniki - start}
+ \begin{center}
+ \includegraphics[width=0.8\paperwidth, height=0.8\paperheight]{usedEngines.pdf}
+\end{center}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Wybrane silniki}
+ \begin{itemize}
+ \item Wyeliminowanie nie generycznych - Ren'Py, RPGMaker
+ \item Wybór najpopularniejszych - Unity, Unreal
+ % Prawie 25k i ponad 7.5k
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Wydajność silnika}
+ \begin{itemize}
+ \item Klatki na sekundę (FPS)
+ \item Zużycie CPU, GPU, RAM i VRAM
+ \item Liczba draw calls
+ \item Czas ładowania assetów
+ \item Czas odpowiedzi na interakcję gracza
+ \end{itemize}
+\end{frame}
+\begin{frame}
+ \frametitle{Możliwości Silnika}
+ \begin{itemize}
+ \item Renderowanie grafiki
+ % Ray tracing, HDR lighting, dynamic shadows, particle systems, animacja
+ \item Silnik Fizyczny
+ \item Multiplatformowość (VR)
+ % Linux, Windows, MacOS, Android, IOs, Xbox, PlayStation, Nintendo, VR
+ \item Skryptowanie logiki gier (AI)
+ \item Gry online
+ \item Sklepy z assetami
+ \end{itemize}
+ \end{frame}
diff --git a/NotProgramming/SDM/presentations/my_thesis/sections/02-narzedzia.tex b/NotProgramming/SDM/presentations/my_thesis/sections/02-narzedzia.tex
new file mode 100644
index 00000000..95372fd9
--- /dev/null
+++ b/NotProgramming/SDM/presentations/my_thesis/sections/02-narzedzia.tex
@@ -0,0 +1,192 @@
+ \section{Narzędzia}
+ \frametitle{Unity Profiler}
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {unity_profiler.png}}
+ \begin{frame}
+ \end{frame}
+ }
+
+ \frametitle{Unreal Profiler}
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {unreal_profiler.jpg}}
+ \begin{frame}
+ \end{frame}
+ }
+
+ \frametitle{Nvidia nsight}
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {nvida_nsighty.jpg}}
+ \begin{frame}
+ \end{frame}
+ }
+
+
+ \begin{frame}
+ \frametitle{Nsight - Analiza FPS}
+ \center
+ \includegraphics[width=1\textwidth]{fps_overview.png}
+ % Ile klatek pokazaliśmy na ile
+ % ile trwała średnio klatka
+ % Ile trwała najkrótsza klatka
+ % Ile trwała najdłuższa klatka
+ % Przeciętne klatki na sekundę dla pokazanego wycinka
+ % Tyle lub mniej czasu trwało 99% klatek
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Analiza FPS}
+ \center
+ \includegraphics[width=1\textwidth]{stutter_row.png}
+ % Wykrywanie "zawieszek"
+ % Wykrywamy klatki których długość
+ % jest znacznie dłuższa od długości mediany pobliskich 19 klatek
+ % zawieszka musi być dłuższa niż 4 milisekundy
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Analiza FPS}
+ \center
+ \includegraphics[width=1\textwidth]{dx12_frame_health.png}
+ % Możemy sprawdzić jaka klatka miała zawieszkę
+ % I jaka metoda w api tę zawieszkę spowodowała
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Zużycie VRAM}
+ \center
+ \includegraphics[width=1\textwidth]{memory_utilization.png}
+ % Zielony -> ile pamięci mamy dostępnej
+ % Pomarańczowy -> ile pamięci zużyliśmy
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Zużycie VRAM}
+ \center
+ \includegraphics[width=1\textwidth]{memory_utilization_gpu_vram.png}
+ % VidMm Device Suspension -> okresy czasku kiedy przetransferowano
+ % Jeden duży zasób pamięci
+ % Demoted Memory -> w GPU mamy local memory (szybsze) i global memory
+ % (wolniejsze) to może nam mówić o "wyciekach" pamięci
+ % źle zooptymalizowanej pamięci itd.
+ % Allokacja pamięci -> zielone aplikacja, szare -> system
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Zużycie VRAM}
+ \center
+ \includegraphics[width=1\textwidth]{memory_utilization_resource_migrations.png}
+ % W kolejności co najwięcej zużyło zasobów
+ % Konkretnie ile i kiedy
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Zużycie VRAM}
+ \center
+ \includegraphics[width=1\textwidth]{memory_utilization_memory_transfer.png}
+ % W kolejności co najwięcej zużyło zasobów
+ % Konkretnie ile i kiedy
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Jak porównywać?}
+ \begin{itemize}
+ \item Stworzenie gry na obu
+ \item Porównywanie istniejących gier
+ \item Porównanie samych edytorów
+ \end{itemize}
+ \end{frame}
+
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {maxresdefault (1).jpg}}
+ \begin{frame}
+ \end{frame}
+ }
+
+ \begin{frame}
+ \frametitle{Wybór gatunku}
+ FPS:
+ \begin{itemize}
+ \item Wystarczająco skomplikowany
+ \item Grafika
+ \item Fizyka
+ \item Klasyczny benchmark
+ % Wolfenstein, Doom, Quake, Crysis
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{Problem}
+ Inklinacja Silnika \\
+ \begin{itemize}
+ \item $ \frac{2478}{39713} \approx 6\% $ gier Unity to FPS \\
+ \item $ \frac{1765}{11158} \approx 15\% $ gier Unreal to FPS \\
+ \end{itemize}
+ Źródło: steamdb.info
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Wybór gatunku}
+ Bullet hell:
+ \begin{itemize}
+ \item Wystarczająco skomplikowany
+ \item Grafika
+ \item Czas jest ważny
+ % W Bullet hell czas jest ważny, gra musi być płynna
+ \end{itemize}
+ \end{frame}
+
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {maxresdefault.jpg}}
+ \begin{frame}
+ \end{frame}
+ }
+ \begin{frame}
+ \frametitle{Wyzwania}
+ \begin{itemize}
+ \item Sprzęt
+ % Ten sam, jeden i ten sam komputer użyty w procesie kreacji obu
+ \item Umiejętności
+ % Nie mam
+ \item Podobne wersje silnika
+ % Użyje ostatniego LTS
+ \item Inklinacja Silnika \\ (3\% Unity, 2.4\% Unreal)
+ % ??? Ch
+ % 1577 FPS UNITY, 271 FPS UNREAL
+ % 39713 Total Unity, 11158 Total Unreal (proporcjonalnie 2 razy więcej :<)
+ \end{itemize}
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Ocena łatwości użycia}
+ \begin{itemize}
+ \item Dokumentacja
+ \item Intuicyjność
+ \item Materiały
+ \item Zasoby (Assety)
+ \item Dostępne funkcje
+ \item ChatGPT
+ \end{itemize}
+ \end{frame}
+
+
+
+ \begin{frame}
+ \frametitle{Po stworzeniu}
+ Przejść obie gry, monitorując używając Nvidia Nsight i porównać wyniki
+ \end{frame}
+
+
diff --git a/NotProgramming/SDM/presentations/my_thesis/sections/03-zrodla.tex b/NotProgramming/SDM/presentations/my_thesis/sections/03-zrodla.tex
new file mode 100644
index 00000000..2d857191
--- /dev/null
+++ b/NotProgramming/SDM/presentations/my_thesis/sections/03-zrodla.tex
@@ -0,0 +1,19 @@
+ \section{Źródła}
+\begin{frame}
+ \frametitle{Źródła}
+ \begin{itemize}
+ \item \href{https://steamdb.info/}{https://steamdb.info/}
+ \item \href{https://docs.nvidia.com/nsight-systems}{https://docs.nvidia.com/nsight-systems}
+ \item An Overview Study of Game Engines, Faizi Noor Ahmad
+ \item Game Engine Architecture, Jason Gregory
+ \end{itemize}
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Źródła obrazów}
+ \begin{itemize}
+ \item Crysis - kanał youtube \href{https://www.youtube.com/watch?v=vGjOALIrL_U}{Thronefull}
+ \item BulletHell - kanał youtube \href{https://www.youtube.com/watch?app=desktop&v=h-wr6LoETA0}{Beat that boss}
+ \end{itemize}
+ \end{frame}
+
diff --git a/NotProgramming/SDM2/presentations/my_thesis/main.tex b/NotProgramming/SDM2/presentations/my_thesis/main.tex
index 04ec5a27..1b0fe908 100644
--- a/NotProgramming/SDM2/presentations/my_thesis/main.tex
+++ b/NotProgramming/SDM2/presentations/my_thesis/main.tex
@@ -60,277 +60,7 @@
\tableofcontents
\end{frame}
-\section{Definicje}
-\begin{frame}
- \frametitle{Gra komputerowa}
- \large Aplikacja dostępna na platformie "Steam" oznaczona typem "Game"
-\end{frame}
-\begin{frame}
-\frametitle{Silnik do gier}
-\large Oprogramowanie zaprojektowane i stworzone do kreacji gier komputerowych
-\end{frame}
-
-\begin{frame}
- \frametitle{Nowoczesne}
- \large Ponad 1000 gier w tej dekadzie na platformie "Steam"
-\end{frame}
-
-
-{
- \setbeamercolor{footline}{fg=white}
-\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{steamdb_main.png}}
-\begin{frame}
-\end{frame}
-}
-
-
-{
-\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{steamdb_filter.drawio.pdf}}
-\begin{frame}
-\end{frame}
-}
-
-\begin{frame}
- \frametitle{Wybrane silniki - start}
- \begin{center}
- \includegraphics[width=0.8\paperwidth, height=0.8\paperheight]{usedEngines.pdf}
-\end{center}
-\end{frame}
-
-\begin{frame}
- \frametitle{Wybrane silniki}
- \begin{itemize}
- \item Wyeliminowanie nie generycznych - Ren'Py, RPGMaker
- \item Wybór najpopularniejszych - Unity, Unreal
- % Prawie 25k i ponad 7.5k
- \end{itemize}
-\end{frame}
-
-\begin{frame}
- \frametitle{Wydajność silnika}
- \begin{itemize}
- \item Klatki na sekundę (FPS)
- \item Zużycie CPU, GPU, RAM i VRAM
- \item Liczba draw calls
- \item Czas ładowania assetów
- \item Czas odpowiedzi na interakcję gracza
- \end{itemize}
-\end{frame}
-\begin{frame}
- \frametitle{Możliwości Silnika}
- \begin{itemize}
- \item Renderowanie grafiki
- % Ray tracing, HDR lighting, dynamic shadows, particle systems, animacja
- \item Silnik Fizyczny
- \item Multiplatformowość (VR)
- % Linux, Windows, MacOS, Android, IOs, Xbox, PlayStation, Nintendo, VR
- \item Skryptowanie logiki gier (AI)
- \item Gry online
- \item Sklepy z assetami
- \end{itemize}
- \end{frame}
- \section{Narzędzia}
- \frametitle{Unity Profiler}
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {unity_profiler.png}}
- \begin{frame}
- \end{frame}
- }
-
- \frametitle{Unreal Profiler}
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {unreal_profiler.jpg}}
- \begin{frame}
- \end{frame}
- }
-
- \frametitle{Nvidia nsight}
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {nvida_nsighty.jpg}}
- \begin{frame}
- \end{frame}
- }
-
- \begin{frame}
- \frametitle{Nsight - Analiza FPS}
- \center
- \includegraphics[width=1\textwidth]{fps_overview.png}
- % Ile klatek pokazaliśmy na ile
- % ile trwała średnio klatka
- % Ile trwała najkrótsza klatka
- % Ile trwała najdłuższa klatka
- % Przeciętne klatki na sekundę dla pokazanego wycinka
- % Tyle lub mniej czasu trwało 99% klatek
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Analiza FPS}
- \center
- \includegraphics[width=1\textwidth]{stutter_row.png}
- % Wykrywanie "zawieszek"
- % Wykrywamy klatki których długość
- % jest znacznie dłuższa od długości mediany pobliskich 19 klatek
- % zawieszka musi być dłuższa niż 4 milisekundy
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Analiza FPS}
- \center
- \includegraphics[width=1\textwidth]{dx12_frame_health.png}
- % Możemy sprawdzić jaka klatka miała zawieszkę
- % I jaka metoda w api tę zawieszkę spowodowała
- \end{frame}
-
-
- \begin{frame}
- \frametitle{Nsight - Zużycie VRAM}
- \center
- \includegraphics[width=1\textwidth]{memory_utilization_gpu_vram.png}
- % Zielony -> ile pamięci mamy dostępnej
- % Pomarańczowy -> ile pamięci zużyliśmy
- % VidMm Device Suspension -> okresy czasku kiedy przetransferowano
- % Jeden duży zasób pamięci
- % Demoted Memory -> w GPU mamy local memory (szybsze) i global memory
- % (wolniejsze) to może nam mówić o "wyciekach" pamięci
- % źle zooptymalizowanej pamięci itd.
- % Allokacja pamięci -> zielone aplikacja, szare -> system
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Zużycie VRAM}
- \center
- \includegraphics[width=1\textwidth]{memory_utilization_resource_migrations.png}
- % W kolejności co najwięcej zużyło zasobów
- % Konkretnie ile i kiedy
- \end{frame}
-
- \begin{frame}
- \frametitle{Nsight - Zużycie VRAM}
- \center
- \includegraphics[width=1\textwidth]{memory_utilization_memory_transfer.png}
- % W kolejności co najwięcej zużyło zasobów
- % Konkretnie ile i kiedy
- \end{frame}
-
- \begin{frame}
- \frametitle{Jak porównywać?}
- \begin{itemize}
- \item Stworzenie gry na obu
- \item Porównywanie istniejących gier
- \item Porównanie samych edytorów
- \end{itemize}
- \end{frame}
-
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {maxresdefault (1).jpg}}
- \begin{frame}
- \end{frame}
- }
-
- \begin{frame}
- \frametitle{Wybór gatunku}
- FPS:
- \begin{itemize}
- \item Wystarczająco skomplikowany
- \item Grafika
- \item Fizyka
- \item Klasyczny benchmark
- % Wolfenstein, Doom, Quake, Crysis
- \end{itemize}
- \end{frame}
- \begin{frame}
- \frametitle{Problem}
- Inklinacja Silnika \\
- \begin{itemize}
- \item $ \frac{2478}{39713} \approx 6\% $ gier Unity to FPS \\
- \item $ \frac{1765}{11158} \approx 15\% $ gier Unreal to FPS \\
- \end{itemize}
- Źródło: steamdb.info
- \end{frame}
-
- \begin{frame}
- \frametitle{Wybór gatunku}
- Bullet hell:
- \begin{itemize}
- \item Wystarczająco skomplikowany
- \item Grafika
- \item Czas jest ważny
- % W Bullet hell czas jest ważny, gra musi być płynna
- \end{itemize}
- \end{frame}
-
- {
- \setbeamercolor{footline}{fg=white}
- \usebackgroundtemplate{
- \includegraphics[width=\paperwidth, height=\paperheight]
- {maxresdefault.jpg}}
- \begin{frame}
- \end{frame}
- }
- \begin{frame}
- \frametitle{Wyzwania}
- \begin{itemize}
- \item Sprzęt
- % Ten sam, jeden i ten sam komputer użyty w procesie kreacji obu
- \item Umiejętności
- % Nie mam
- \item Podobne wersje silnika
- % Użyje ostatniego LTS
- \item Inklinacja Silnika \\ (3\% Unity, 2.4\% Unreal)
- % ??? Ch
- % 1577 FPS UNITY, 271 FPS UNREAL
- % 39713 Total Unity, 11158 Total Unreal (proporcjonalnie 2 razy więcej :<)
- \end{itemize}
- \end{frame}
-
- \begin{frame}
- \frametitle{Ocena łatwości użycia}
- \begin{itemize}
- \item Dokumentacja
- \item Intuicyjność
- \item Materiały
- \item Zasoby (Assety)
- \item Dostępne funkcje
- \end{itemize}
- \end{frame}
-
-
-
- \begin{frame}
- \frametitle{Po stworzeniu}
- Przejść obie gry, monitorując przy użyciu Nvidia Nsight i porównać wyniki
- \end{frame}
-
-
- \section{Źródła}
-\begin{frame}
- \frametitle{Źródła}
- \begin{itemize}
- \item \href{https://steamdb.info/}{https://steamdb.info/}
- \item \href{https://docs.nvidia.com/nsight-systems}{https://docs.nvidia.com/nsight-systems}
- \item An Overview Study of Game Engines, Faizi Noor Ahmad
- \item Game Engine Architecture, Jason Gregory
- \end{itemize}
- \end{frame}
-
- \begin{frame}
- \frametitle{Źródła obrazów}
- \begin{itemize}
- \item Crysis - kanał youtube \href{https://www.youtube.com/watch?v=vGjOALIrL_U}{Thronefull}
- \item BulletHell - kanał youtube \href{https://www.youtube.com/watch?app=desktop&v=h-wr6LoETA0}{Beat that boss}
- \end{itemize}
- \end{frame}
-
+ \input{sections/01-definicje}
+ \input{sections/02-narzedzia}
+ \input{sections/03-zrodla}
\end{document}
\ No newline at end of file
diff --git a/NotProgramming/SDM2/presentations/my_thesis/sections/01-definicje.tex b/NotProgramming/SDM2/presentations/my_thesis/sections/01-definicje.tex
new file mode 100644
index 00000000..672c329a
--- /dev/null
+++ b/NotProgramming/SDM2/presentations/my_thesis/sections/01-definicje.tex
@@ -0,0 +1,69 @@
+\section{Definicje}
+\begin{frame}
+ \frametitle{Gra komputerowa}
+ \large Aplikacja dostępna na platformie "Steam" oznaczona typem "Game"
+\end{frame}
+\begin{frame}
+\frametitle{Silnik do gier}
+\large Oprogramowanie zaprojektowane i stworzone do kreacji gier komputerowych
+\end{frame}
+
+\begin{frame}
+ \frametitle{Nowoczesne}
+ \large Ponad 1000 gier w tej dekadzie na platformie "Steam"
+\end{frame}
+
+
+{
+ \setbeamercolor{footline}{fg=white}
+\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{steamdb_main.png}}
+\begin{frame}
+\end{frame}
+}
+
+
+{
+\usebackgroundtemplate{\includegraphics[width=\paperwidth, height=\paperheight]{steamdb_filter.drawio.pdf}}
+\begin{frame}
+\end{frame}
+}
+
+\begin{frame}
+ \frametitle{Wybrane silniki - start}
+ \begin{center}
+ \includegraphics[width=0.8\paperwidth, height=0.8\paperheight]{usedEngines.pdf}
+\end{center}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Wybrane silniki}
+ \begin{itemize}
+ \item Wyeliminowanie nie generycznych - Ren'Py, RPGMaker
+ \item Wybór najpopularniejszych - Unity, Unreal
+ % Prawie 25k i ponad 7.5k
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Wydajność silnika}
+ \begin{itemize}
+ \item Klatki na sekundę (FPS)
+ \item Zużycie CPU, GPU, RAM i VRAM
+ \item Liczba draw calls
+ \item Czas ładowania assetów
+ \item Czas odpowiedzi na interakcję gracza
+ \end{itemize}
+\end{frame}
+\begin{frame}
+ \frametitle{Możliwości Silnika}
+ \begin{itemize}
+ \item Renderowanie grafiki
+ % Ray tracing, HDR lighting, dynamic shadows, particle systems, animacja
+ \item Silnik Fizyczny
+ \item Multiplatformowość (VR)
+ % Linux, Windows, MacOS, Android, IOs, Xbox, PlayStation, Nintendo, VR
+ \item Skryptowanie logiki gier (AI)
+ \item Gry online
+ \item Sklepy z assetami
+ \end{itemize}
+ \end{frame}
diff --git a/NotProgramming/SDM2/presentations/my_thesis/sections/02-narzedzia.tex b/NotProgramming/SDM2/presentations/my_thesis/sections/02-narzedzia.tex
new file mode 100644
index 00000000..a0f23870
--- /dev/null
+++ b/NotProgramming/SDM2/presentations/my_thesis/sections/02-narzedzia.tex
@@ -0,0 +1,185 @@
+ \section{Narzędzia}
+ \frametitle{Unity Profiler}
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {unity_profiler.png}}
+ \begin{frame}
+ \end{frame}
+ }
+
+ \frametitle{Unreal Profiler}
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {unreal_profiler.jpg}}
+ \begin{frame}
+ \end{frame}
+ }
+
+ \frametitle{Nvidia nsight}
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {nvida_nsighty.jpg}}
+ \begin{frame}
+ \end{frame}
+ }
+
+ \begin{frame}
+ \frametitle{Nsight - Analiza FPS}
+ \center
+ \includegraphics[width=1\textwidth]{fps_overview.png}
+ % Ile klatek pokazaliśmy na ile
+ % ile trwała średnio klatka
+ % Ile trwała najkrótsza klatka
+ % Ile trwała najdłuższa klatka
+ % Przeciętne klatki na sekundę dla pokazanego wycinka
+ % Tyle lub mniej czasu trwało 99% klatek
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Analiza FPS}
+ \center
+ \includegraphics[width=1\textwidth]{stutter_row.png}
+ % Wykrywanie "zawieszek"
+ % Wykrywamy klatki których długość
+ % jest znacznie dłuższa od długości mediany pobliskich 19 klatek
+ % zawieszka musi być dłuższa niż 4 milisekundy
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Analiza FPS}
+ \center
+ \includegraphics[width=1\textwidth]{dx12_frame_health.png}
+ % Możemy sprawdzić jaka klatka miała zawieszkę
+ % I jaka metoda w api tę zawieszkę spowodowała
+ \end{frame}
+
+
+ \begin{frame}
+ \frametitle{Nsight - Zużycie VRAM}
+ \center
+ \includegraphics[width=1\textwidth]{memory_utilization_gpu_vram.png}
+ % Zielony -> ile pamięci mamy dostępnej
+ % Pomarańczowy -> ile pamięci zużyliśmy
+ % VidMm Device Suspension -> okresy czasku kiedy przetransferowano
+ % Jeden duży zasób pamięci
+ % Demoted Memory -> w GPU mamy local memory (szybsze) i global memory
+ % (wolniejsze) to może nam mówić o "wyciekach" pamięci
+ % źle zooptymalizowanej pamięci itd.
+ % Allokacja pamięci -> zielone aplikacja, szare -> system
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Zużycie VRAM}
+ \center
+ \includegraphics[width=1\textwidth]{memory_utilization_resource_migrations.png}
+ % W kolejności co najwięcej zużyło zasobów
+ % Konkretnie ile i kiedy
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Nsight - Zużycie VRAM}
+ \center
+ \includegraphics[width=1\textwidth]{memory_utilization_memory_transfer.png}
+ % W kolejności co najwięcej zużyło zasobów
+ % Konkretnie ile i kiedy
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Jak porównywać?}
+ \begin{itemize}
+ \item Stworzenie gry na obu
+ \item Porównywanie istniejących gier
+ \item Porównanie samych edytorów
+ \end{itemize}
+ \end{frame}
+
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {maxresdefault (1).jpg}}
+ \begin{frame}
+ \end{frame}
+ }
+
+ \begin{frame}
+ \frametitle{Wybór gatunku}
+ FPS:
+ \begin{itemize}
+ \item Wystarczająco skomplikowany
+ \item Grafika
+ \item Fizyka
+ \item Klasyczny benchmark
+ % Wolfenstein, Doom, Quake, Crysis
+ \end{itemize}
+ \end{frame}
+ \begin{frame}
+ \frametitle{Problem}
+ Inklinacja Silnika \\
+ \begin{itemize}
+ \item $ \frac{2478}{39713} \approx 6\% $ gier Unity to FPS \\
+ \item $ \frac{1765}{11158} \approx 15\% $ gier Unreal to FPS \\
+ \end{itemize}
+ Źródło: steamdb.info
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Wybór gatunku}
+ Bullet hell:
+ \begin{itemize}
+ \item Wystarczająco skomplikowany
+ \item Grafika
+ \item Czas jest ważny
+ % W Bullet hell czas jest ważny, gra musi być płynna
+ \end{itemize}
+ \end{frame}
+
+ {
+ \setbeamercolor{footline}{fg=white}
+ \usebackgroundtemplate{
+ \includegraphics[width=\paperwidth, height=\paperheight]
+ {maxresdefault.jpg}}
+ \begin{frame}
+ \end{frame}
+ }
+ \begin{frame}
+ \frametitle{Wyzwania}
+ \begin{itemize}
+ \item Sprzęt
+ % Ten sam, jeden i ten sam komputer użyty w procesie kreacji obu
+ \item Umiejętności
+ % Nie mam
+ \item Podobne wersje silnika
+ % Użyje ostatniego LTS
+ \item Inklinacja Silnika \\ (3\% Unity, 2.4\% Unreal)
+ % ??? Ch
+ % 1577 FPS UNITY, 271 FPS UNREAL
+ % 39713 Total Unity, 11158 Total Unreal (proporcjonalnie 2 razy więcej :<)
+ \end{itemize}
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Ocena łatwości użycia}
+ \begin{itemize}
+ \item Dokumentacja
+ \item Intuicyjność
+ \item Materiały
+ \item Zasoby (Assety)
+ \item Dostępne funkcje
+ \end{itemize}
+ \end{frame}
+
+
+
+ \begin{frame}
+ \frametitle{Po stworzeniu}
+ Przejść obie gry, monitorując przy użyciu Nvidia Nsight i porównać wyniki
+ \end{frame}
+
+
diff --git a/NotProgramming/SDM2/presentations/my_thesis/sections/03-zrodla.tex b/NotProgramming/SDM2/presentations/my_thesis/sections/03-zrodla.tex
new file mode 100644
index 00000000..2d857191
--- /dev/null
+++ b/NotProgramming/SDM2/presentations/my_thesis/sections/03-zrodla.tex
@@ -0,0 +1,19 @@
+ \section{Źródła}
+\begin{frame}
+ \frametitle{Źródła}
+ \begin{itemize}
+ \item \href{https://steamdb.info/}{https://steamdb.info/}
+ \item \href{https://docs.nvidia.com/nsight-systems}{https://docs.nvidia.com/nsight-systems}
+ \item An Overview Study of Game Engines, Faizi Noor Ahmad
+ \item Game Engine Architecture, Jason Gregory
+ \end{itemize}
+ \end{frame}
+
+ \begin{frame}
+ \frametitle{Źródła obrazów}
+ \begin{itemize}
+ \item Crysis - kanał youtube \href{https://www.youtube.com/watch?v=vGjOALIrL_U}{Thronefull}
+ \item BulletHell - kanał youtube \href{https://www.youtube.com/watch?app=desktop&v=h-wr6LoETA0}{Beat that boss}
+ \end{itemize}
+ \end{frame}
+
diff --git a/Programming/AIS/report/final/ver2/etoll.tex b/Programming/AIS/report/final/ver2/etoll.tex
index c0e8ae93..ffec6168 100644
--- a/Programming/AIS/report/final/ver2/etoll.tex
+++ b/Programming/AIS/report/final/ver2/etoll.tex
@@ -38,364 +38,8 @@
\maketitle
-\section{Wymagania funkcjonalne}
-
-\subsection{Kluczowy proces biznesowy: Naliczanie i pobieranie opłat za przejazd}
-
-\subsubsection{Cel procesu}
-\begin{enumerate}
- \item Wykrywanie pojazdów na płatnych odcinkach dróg
- \item Naliczanie należności zgodnie z taryfami
- \item Pobieranie opłat od użytkowników
-\end{enumerate}
-
-\subsubsection{Stan początkowy}
-Pojazd niezarejestrowany w systemie jako znajdujący się na płatnym odcinku drogi, z kontem użytkownika posiadającym określony stan środków (prepaid) lub limitem kredytowym (postpaid).
-
-\subsubsection{Stan końcowy}
-Prawidłowo naliczona i pobrana opłata za przejazd, zaksięgowana w systemie finansowym, z wygenerowanym potwierdzeniem dla użytkownika oraz aktualizacją stanu konta.
-
-\subsubsection{Kroki procesu}
-\begin{enumerate}
- \item Identyfikacja pojazdu wjeżdżającego na płatny odcinek (poprzez urządzenie OBU, aplikację mobilną lub kamery ANPR) [Dla redundancji, im więcej systemów tym większa szansa na identyfikację]
- \item Zebranie danych o pojeździe (kategoria, klasa emisji spalin, masa)
- \item Rozpoczęcie śledzenia przejazdu i rejestracja czasu wjazdu
- \item Monitorowanie trasy przejazdu przez punkty kontrolne
- \item Identyfikacja zjazdu z płatnego odcinka
- \item Obliczenie należności na podstawie przebytej trasy i charakterystyki pojazdu
- \item Weryfikacja dostępności środków na koncie użytkownika
- \item Pobranie opłaty z konta użytkownika
- \item Wygenerowanie potwierdzenia transakcji
- \item Aktualizacja salda konta użytkownika
-\end{enumerate}
-
-\paragraph{Obsługa sytuacji wyjątkowych:}
-\begin{itemize}
- \item Jeśli identyfikacja pojazdu nie jest możliwa: uruchomienie procedury rejestracji incydentu z dokumentacją wizualną (zdjęcia niezidentyfikowanego pojazdu)
-
- \item W przypadku niewystarczających środków na koncie:
- \begin{enumerate}
- \item Zablokowanie konta do momentu zapłacenia
- \item W przypadku braku zapłaty w określonym czasie, uruchomienie procedury windykacyjnej
- \end{enumerate}
-
- \item Przy awarii urządzenia OBU: automatyczne przełączenie na identyfikację przez system kamer ANPR
-
- \item W razie przerwy w komunikacji: lokalne buforowanie danych i synchronizacja po przywróceniu łączności
-
- \item Jeśli zidentyfikowano omijanie bramek:
- \begin{enumerate}
- \item Poinformowanie użytkownika
- \item Uruchomienie procedury kontrolnej
- \item Naliczenie kary
- \end{enumerate}
-\end{itemize}
-
-\subsection{Lista wymagań funkcjonalnych}
-
-\begin{enumerate}
- \item \textbf{System rejestracji użytkowników} - System musi umożliwiać rejestrację nowych użytkowników z weryfikacją tożsamości, zbieraniem danych o pojazdach (w tym masa, klasa emisji, kategoria) oraz wyborem metody płatności (prepaid lub postpaid).
-
- \item \textbf{Moduł geolokalizacji pojazdów} - System musi określać pozycję pojazdów z dokładnością do 10 metrów, wykorzystując dane GPS z urządzeń OBU lub aplikacji mobilnej, aktualizowane nie rzadziej niż co 30 sekund podczas przejazdu.
-
- \item \textbf{System rozpoznawania tablic rejestracyjnych (ANPR)} - System musi identyfikować pojazdy poprzez kamery ANPR z dokładnością co najmniej 98\% w różnych warunkach pogodowych i oświetleniowych, jako dopełnienie jeśli wszystkie systemy działają poprawnie lub alternatywa dla urządzeń OBU w razie awarii.
-
- \item \textbf{Elastyczny system taryfowy} - System musi obsługiwać zróżnicowane taryfy opłat w zależności od: typu pojazdu, masy całkowitej, klasy emisji spalin, pory dnia, dnia tygodnia oraz stopnia zatłoczenia drogi.
-
- \item \textbf{Moduł rozliczeń i płatności} - System musi obsługiwać różne metody płatności (karty płatnicze, przelewy, płatności mobilne, blik) z możliwością automatycznego doładowania konta prepaid oraz wystawiania faktur elektronicznych zgodnych z przepisami prawa.
-
- \item \textbf{System powiadomień dla użytkowników} - System musi wysyłać automatyczne powiadomienia do użytkowników (aplikacja, mail + sms) o: niskim stanie konta, zbliżającym się terminie płatności, dokonanych transakcjach oraz zmianach w taryfach i regulaminie.
-
- \item \textbf{Moduł raportowania i analityki} - System musi generować raporty dotyczące natężenia ruchu, generowanych przychodów, incydentów oraz efektywności egzekwowania opłat, z możliwością eksportu danych w formatach CSV i PDF.
-
- \item \textbf{System wykrywania naruszeń} - System musi identyfikować próby obejścia opłat (np. manipulacja urządzeniem OBU, podawanie fałszywych danych o pojeździe) i automatycznie uruchamiać procedury weryfikacyjne.
-
- \item \textbf{Portal samoobsługowy dla użytkowników} - System musi udostępniać portal internetowy oraz aplikację mobilną umożliwiającą użytkownikom zarządzanie kontem, przeglądanie historii przejazdów i opłat, generowanie raportów oraz aktualizację danych pojazdu.
-
- \item \textbf{System korekty opłat} - System musi umożliwiać ręczną korektę naliczonej opłaty przez operatora w przypadku zgłoszenia błędu przez użytkownika. Zakładając, że system źle naliczył opłatę np. Użytkownik został obciążony za trasę, której nie przejechał lub przypisano niewłaściwą kategorię pojazdu. Użytkownik zgłasza błąd do obsługi systemu. W takim przypadku operator musi mieć możliwość ręcznej korekty naliczonej opłaty np. Anulowanie opłaty, zmniejszenie jej lub ponowne przeliczenie, jeżeli zgłoszenie użytkownika okaże się zasadne. Zasadność zgłoszenia musi być weryfikowalna poprzez fizyczne zdjęcia pojazdu.
-\end{enumerate}
-
-\section{Wymagania niefunkcjonalne}
-
-\begin{enumerate}
- \item \textbf{Wydajność systemu} - System musi obsługiwać jednoczesne przetwarzanie danych z co najmniej 200,000 pojazdów w godzinach szczytu\footnote{\url{https://forsal.pl/transport/drogi/artykuly/8295957,najbardziej-obciazone-drogi-w-polsce-s8-s2-a4-s86-mapa.html}}, z czasem odpowiedzi dla transakcji poniżej 1s oraz przetwarzaniem danych geolokalizacyjnych w czasie rzeczywistym.
-
- \item \textbf{Dostępność systemu} - System musi zapewniać dostępność na poziomie 99,9\% (maksymalny czas niedostępności: $\sim$9 godzin rocznie), z planowanymi oknami serwisowymi w godzinach nocnych (1:00-4:00) i z odpowiednim wyprzedzeniem komunikowanym użytkownikom.
-
- \item \textbf{Bezpieczeństwo danych} - System musi zapewniać:
- \begin{enumerate}
- \item Szyfrowanie danych w spoczynku i podczas transmisji (minimum AES-256)
- \item Zgodność z normą ISO/IEC 27001
- \item Wielopoziomową autoryzację użytkowników (hasło + kod sms)
- \item Pełną zgodność z RODO, włączając automatyczne mechanizmy anonimizacji danych historycznych starszych niż 5 lat.
- \end{enumerate}
-
- \item \textbf{Skalowalność} - System musi posiadać architekturę umożliwiającą skalowanie w celu obsługi wzrostu liczby użytkowników o 30\% rocznie bez pogorszenia wydajności\footnote{\url{https://kpmg.com/pl/pl/home/media/press-releases/2024/02/liczba-rejestracji-nowych-samochodow-osobowych-wzrosla-o-13-2-procent-w-2023-roku.html}}, z automatycznym zwiększeniem zasobów w odpowiedzi na zwiększone obciążenie w ciągu dnia.
-
- \item \textbf{Niezawodność i odporność na awarie} - System musi zawierać rozwiązania wysokiej dostępności z nadmiarowością komponentów krytycznych, automatycznym przełączaniem awaryjnym poniżej 10 sekund oraz mechanizmem ciągłej replikacji danych między geograficznie odległymi centrami danych, zapewniając RPO (Recovery Point Objective) poniżej 5 minut i RTO (Recovery Time Objective) poniżej 30 minut.
-
- \item \textbf{Interoperacyjność} - System musi obsługiwać standardy interoperacyjności z europejskimi systemami elektronicznego poboru opłat (zgodnie z dyrektywą EETS\footnote{\url{https://eur-lex.europa.eu/legal-content/PL/TXT/?uri=CELEX\%3A32019L0520}}), zapewniając pełną wymianę danych poprzez standardowe API (REST/SOAP) z minimum 99,5\% dostępnością interfejsów integracyjnych.
-
- \item \textbf{Użyteczność i dostępność interfejsów} - Interfejsy użytkownika (portal i aplikacja mobilna) muszą spełniać standardy WCAG 2.1 na poziomie AA, obsługiwać minimum 5 języków (polski, angielski, niemiecki, ukraiński, rosyjski), zapewniać responsywność na urządzeniach mobilnych oraz wykazywać wskaźnik satysfakcji użytkowników (CSAT) na poziomie minimum 85\%.
-
- \item \textbf{Audytowanie i śledzenie aktywności} - System musi rejestrować wszystkie operacje w niezmienialne logi z zachowaniem zgodności z wymogami prawnymi dotyczącymi dowodów elektronicznych, umożliwiać niemodyfikowalny ślad audytu dla wszystkich transakcji finansowych oraz zapewniać przechowywanie logów przez minimum 5 lat z możliwością szybkiego wyszukiwania.
-
- \item \textbf{Efektywność zarządzania danymi} - System musi umożliwiać archiwizację i zarządzanie cyklem życia danych zgodnie z polityką retencji, zapewniać kompresję danych historycznych na poziomie minimum 80\% oraz optymalizację zapytań do bazy danych z czasem odpowiedzi poniżej 10 sekund dla 90\% zapytań raportowych.
-
- \item \textbf{Utrzymywalność i modyfikowalność} - System musi być zaprojektowany z wykorzystaniem architektury modułowej i mikroserwisowej, umożliwiającej niezależną aktualizację poszczególnych komponentów bez przerywania działania całości systemu, z automatycznymi testami regresji pokrywającymi minimum 90\% kodu oraz pełną dokumentacją techniczną aktualizowaną przy każdej \textbf{dużej} (takiej która sprawia że system nie jest kompatybilny z poprzednią wersją) zmianie.
-
- \item \textbf{System integracji z zewnętrznymi bazami danych} - System musi komunikować się z zewnętrznymi bazami danych (np. CEPiK, rejestry pojazdów innych krajów) w celu weryfikacji danych pojazdów oraz wymiany informacji o użytkownikach z zagranicznymi systemami poboru opłat.
-
- \item \textbf{Zgodność prawna i regulacyjna} - System musi spełniać wszystkie obowiązujące przepisy prawa krajowego oraz unijnego dotyczące elektronicznego poboru opłat. Ustawę o drogach publicznych, dyrektywę EETS, przepisy podatkowe oraz przepisy dotyczące ochrony konkurencji i konsumentów.
-
- \item \textbf{Czas wdrożenia poprawek krytycznych} - w przypadku wykrycia krytycznego błędu (np. Uniemożliwiającego naliczenie opłaty lub przetwarzanie przejazdów) poprawka musi zostać wdrożona w ciągu maksymalnie 24 godzin od momentu potwierdzenia błędu.
-
- \item \textbf{Transparentność naliczanych opłat} - system musi umożliwiać użytkownikom końcowym wgląd w szczegółowe informacje dotyczące każdej naliczonej opłaty. Czas przejazdu, odcinki dróg, taryfy oraz podstawy naliczenia.
-
- \item \textbf{Elastyczność taryf} - system musi obsługiwać dynamiczne taryfy drogowe (np. Zmienne w zależności od natężenia ruchu czy poziomu emisji pojazdu) z możliwoścą wdrażania nowych taryf bez konieczności przerywania działania systemu.
-
- \item \textbf{Personalizacja powiadomień dla użytkowników} - system musi umożliwić użytkownikom wybór otrzymywania powiadomień np. (sms, e-mail, powiadomienie push w aplikacji) z opcją definiowania progów powiadomień (np. Przekroczenie salda, opłata powyżej X zł etc.)
-\end{enumerate}
-
-\section{Decyzje architektoniczne}
-
-\subsection{Podział na warstwy}
-\begin{figure}[H]
-\centering
-\includegraphics[width=0.8\textwidth]{wybor_architektury.png}
-\caption{Diagram podziału na warstwy}
-\label{fig:layers}
-\end{figure}
-
-\begin{itemize}
-\item Warstwa prezentacji: trzy różne aplikacje klienckie — aplikacja webowa, mobilna i aplikacja na urządzenia embedded.
-\item Warstwa logiki biznesowej: centralna aplikacja serwerowa (serverApp), w której znajdują się komponenty takie jak UserService, PaymentService, PositionService itd.
-\item Warstwa dostępu do danych: komponenty UserRepository, PaymentRepository.
-\item Warstwa danych: baza danych Oracle z mechanizmem failover.
-\end{itemize}
-
-\textbf{Decyzja:} Rozdzielenie odpowiedzialności na warstwy zwiększa modularność i ułatwia zarządzanie kodem oraz jego testowanie.
-
-\textbf{Alternatywa:} Architektura mikroserwisowa
-
-\textbf{Zalety alternatywy:}
-\begin{itemize}
-\item Lepsza skalowalność poszczególnych komponentów
-\item Możliwość niezależnego wdrażania i rozwijania usług
-\item Lepsza odporność na awarie (awaria jednego serwisu $\neq$ awaria całego systemu)
-\end{itemize}
-
-\textbf{Wady alternatywy:}
-\begin{itemize}
-\item Większa złożoność wdrożeniowa (DevOps, CI/CD, monitoring)
-\item Konieczność rozwiązywania problemów związanych z komunikacją między serwisami
-\item Trudniejsze debugowanie i testowanie end-to-end
-\end{itemize}
-
-\subsection{Modularność i komponenty (Component-based Design)}
-\begin{figure}[H]
-\centering
-\includegraphics[width=0.8\textwidth]{organizacja_aplikacji_serwerowej.png}
-\caption{Diagram komponentów}
-\label{fig:components}
-\end{figure}
-
-\begin{itemize}
-\item Serwerowa aplikacja została podzielona na komponenty pełniące konkretne role (SigninController, TollController, MainComponent, itd.).
-\item Każdy komponent ma jasno zdefiniowaną odpowiedzialność, zgodnie z zasadą Single Responsibility Principle.
-\end{itemize}
-
-\textbf{Decyzja:} Wprowadzenie komponentów umożliwia łatwe rozszerzanie i testowanie poszczególnych fragmentów systemu.
-
-\textbf{Alternatywa:} Monolityczna aplikacja serwerowa
-
-\textbf{Zalety alternatywy:}
-\begin{itemize}
-\item Prostsza implementacja i wdrożenie
-\item Mniejsza liczba zależności i konfiguracji
-\item Mniej złożone środowisko developerskie
-\end{itemize}
-
-\textbf{Wady alternatywy:}
-\begin{itemize}
-\item Trudniejsza skalowalność i refaktoryzacja
-\item Każda zmiana wymaga redeploy całej aplikacji
-\item Trudniejsze testowanie izolowanych funkcji
-\end{itemize}
-
-\subsection{Wielokanałowy dostęp (Multi-Platform Clients)}
-\begin{figure}[H]
-\centering
-\includegraphics[width=0.8\textwidth]{dostep_do_systemu.png}
-\caption{Diagram wielokanałowego dostępu}
-\label{fig:multichannel}
-\end{figure}
-
-\begin{itemize}
-\item Użytkownicy mogą korzystać z systemu za pomocą aplikacji mobilnej, webowej lub urządzeń embedded.
-\end{itemize}
-
-\textbf{Decyzja:} Umożliwienie różnym grupom użytkowników (np. administratorzy vs kierowcy) dostępu do funkcji systemu w najbardziej dogodny sposób.
-
-\textbf{Alternatywa:} Tylko aplikacja mobilna (np. PWA lub natywna)
-
-\textbf{Zalety alternatywy:}
-\begin{itemize}
-\item Uproszczony interfejs użytkownika
-\item Jedna platforma do utrzymania
-\item Lepsze dopasowanie do kontekstu użytkownika (kierowcy)
-\end{itemize}
-
-\textbf{Wady alternatywy:}
-\begin{itemize}
-\item Brak wygodnego interfejsu dla administratorów lub analityków
-\item Mniejsza elastyczność użytkowania
-\item Trudności z dostępem do systemu z urządzeń stacjonarnych
-\end{itemize}
-
-\subsection{Rozdzielenie ról i uprawnień}
-\begin{figure}[H]
-\centering
-\includegraphics[width=0.8\textwidth]{uprawnienia_dla_uzytkownikow.png}
-\caption{Diagram ról i uprawnień}
-\label{fig:roles}
-\end{figure}
-
-\begin{itemize}
-\item Administrator ma dostęp tylko przez aplikację webową.
-\item Kierowca może korzystać z trzech różnych interfejsów — w zależności od potrzeb.
-\end{itemize}
-
-\textbf{Decyzja:} Jasny podział ról zwiększa bezpieczeństwo i ergonomię systemu.
-
-\textbf{Alternatywa:} Jeden zunifikowany interfejs z uprawnieniami na poziomie konta
-
-\textbf{Zalety alternatywy:}
-\begin{itemize}
-\item Mniejsze zróżnicowanie UI
-\item Mniej kodu i testów związanych z różnymi platformami
-\end{itemize}
-
-\textbf{Wady alternatywy:}
-\begin{itemize}
-\item Mniejsza przejrzystość
-\item Możliwość przypadkowego ujawnienia funkcji nieprzeznaczonych dla danego typu użytkownika
-\end{itemize}
-
-\subsection{Integracja z zewnętrznymi systemami}
-\begin{figure}[H]
-\centering
-\includegraphics[width=0.8\textwidth]{realizacja_obslugi_platnosci_i_archiwizacji_danych.png}
-\caption{Diagram integracji z systemami zewnętrznymi}
-\label{fig:integration}
-\end{figure}
-
-\begin{itemize}
-\item System płatności (systemPlatnosci) oraz system archiwizacji danych (archiwum) są zewnętrznymi systemami zintegrowanymi z systemem e-Toll.
-\end{itemize}
-
-\textbf{Decyzja:} Wydzielenie tych odpowiedzialności do zewnętrznych systemów pozwala na lepsze skalowanie oraz wykorzystanie istniejących rozwiązań.
-
-\textbf{Alternatywa:} Wszystko w ramach jednej aplikacji (np. własny moduł płatności i archiwizacji)
-
-\textbf{Zalety alternatywy:}
-\begin{itemize}
-\item Większa kontrola nad logiką
-\item Mniejsze zależności zewnętrzne
-\end{itemize}
-
-\textbf{Wady alternatywy:}
-\begin{itemize}
-\item Większe ryzyko błędów w obszarach regulowanych prawnie (np. płatności)
-\item Większe koszty utrzymania i certyfikacji
-\item Brak skalowalności i elastyczności
-\end{itemize}
-
-\subsection{Wysoka dostępność i odporność na awarie}
-\begin{figure}[H]
-\centering
-\includegraphics[width=0.8\textwidth]{zapewnienie_dostepnosci_i_odpornosci_na_awarie.png}
-\caption{Diagram wysokiej dostępności}
-\label{fig:high-availability}
-\end{figure}
-
-\begin{itemize}
-\item Baza danych jest replikowana (primary–secondary).
-\item Oddzielne deployment node'y dla różnych typów urządzeń oraz dla aplikacji serwerowej i bazy danych.
-\item Failover serwera bazy danych — Oracle - Secondary.
-\end{itemize}
-
-\textbf{Decyzja:} Architektura uwzględnia mechanizmy zapewniające ciągłość działania systemu nawet w przypadku awarii.
-
-\textbf{Alternatywa:} Deployment w chmurze
-
-\textbf{Zalety alternatywy:}
-\begin{itemize}
-\item Duża skalowalność
-\item Bezpieczeństwo i redundancja
-\end{itemize}
-
-\textbf{Wady alternatywy:}
-\begin{itemize}
-\item Wyższe koszty
-\item Przetwarzanie danych przez inne podmioty
-\end{itemize}
-
-\subsection{Wybór technologii wdrożeniowych}
-\begin{figure}[H]
-\centering
-\includegraphics[width=0.8\textwidth]{wybor_technologii_wdrozeniowej.png}
-\caption{Diagram technologii wdrożeniowych}
-\label{fig:deployment-tech}
-\end{figure}
-
-\begin{itemize}
-\item System hostowany na serwerach z Ubuntu 24.04 LTS.
-\item Serwer aplikacji oparty o Apache Tomcat 8.x.
-\item Baza danych Oracle 12c.
-\end{itemize}
-
-\textbf{Decyzja:} Użycie sprawdzonych technologii o długoterminowym wsparciu i wysokiej wydajności.
-
-\textbf{Alternatywa:} Cloud-native stack – np. AWS/GCP
-
-\textbf{Zalety alternatywy:}
-\begin{itemize}
-\item Automatyczne skalowanie, monitoring, CI/CD
-\item Niższe koszty utrzymania fizycznej infrastruktury
-\item Łatwiejsze zarządzanie kontenerami i usługami
-\end{itemize}
-
-\textbf{Wady alternatywy:}
-\begin{itemize}
-\item Uzależnienie od chmury (vendor lock-in)
-\item Potrzeba opanowania nowych technologii
-\item Potencjalne wyższe koszty początkowe
-\end{itemize}
-
-\section{Projekt systemu w postaci modelu C4}
- \begin{figure}[H]
- \centering
- \includegraphics[width=1\textwidth]{c4/etoll.png}
- \caption{Poziom context}
- \label{fig:deployment-tech}
- \end{figure}
- \begin{figure}[H]
- \centering
- \includegraphics[width=1\textwidth]{c4/component_server_app.png}
- \caption{Poziom component}
- \label{fig:deployment-tech}
- \end{figure}
- \begin{figure}[H]
- \centering
- \includegraphics[width=1\textwidth]{c4/etool_glebiej.png}
- \caption{Diagram dynamiczny}
- \label{fig:deployment-tech}
- \end{figure}
- \begin{figure}[H]
- \centering
- \includegraphics[width=1\textwidth]{c4/deployment.png}
- \caption{Diagram technologii wdrożeniowych}
- \label{fig:deployment-tech}
- \end{figure}
+ \input{sections/01-wymagania-funkcjonalne}
+ \input{sections/02-wymagania-niefunkcjonalne}
+ \input{sections/03-decyzje-architektoniczne}
+ \input{sections/04-projekt-systemu-w-postaci-modelu-c4}
\end{document}
diff --git a/Programming/AIS/report/final/ver2/sections/01-wymagania-funkcjonalne.tex b/Programming/AIS/report/final/ver2/sections/01-wymagania-funkcjonalne.tex
new file mode 100644
index 00000000..f4efc805
--- /dev/null
+++ b/Programming/AIS/report/final/ver2/sections/01-wymagania-funkcjonalne.tex
@@ -0,0 +1,77 @@
+\section{Wymagania funkcjonalne}
+
+\subsection{Kluczowy proces biznesowy: Naliczanie i pobieranie opłat za przejazd}
+
+\subsubsection{Cel procesu}
+\begin{enumerate}
+ \item Wykrywanie pojazdów na płatnych odcinkach dróg
+ \item Naliczanie należności zgodnie z taryfami
+ \item Pobieranie opłat od użytkowników
+\end{enumerate}
+
+\subsubsection{Stan początkowy}
+Pojazd niezarejestrowany w systemie jako znajdujący się na płatnym odcinku drogi, z kontem użytkownika posiadającym określony stan środków (prepaid) lub limitem kredytowym (postpaid).
+
+\subsubsection{Stan końcowy}
+Prawidłowo naliczona i pobrana opłata za przejazd, zaksięgowana w systemie finansowym, z wygenerowanym potwierdzeniem dla użytkownika oraz aktualizacją stanu konta.
+
+\subsubsection{Kroki procesu}
+\begin{enumerate}
+ \item Identyfikacja pojazdu wjeżdżającego na płatny odcinek (poprzez urządzenie OBU, aplikację mobilną lub kamery ANPR) [Dla redundancji, im więcej systemów tym większa szansa na identyfikację]
+ \item Zebranie danych o pojeździe (kategoria, klasa emisji spalin, masa)
+ \item Rozpoczęcie śledzenia przejazdu i rejestracja czasu wjazdu
+ \item Monitorowanie trasy przejazdu przez punkty kontrolne
+ \item Identyfikacja zjazdu z płatnego odcinka
+ \item Obliczenie należności na podstawie przebytej trasy i charakterystyki pojazdu
+ \item Weryfikacja dostępności środków na koncie użytkownika
+ \item Pobranie opłaty z konta użytkownika
+ \item Wygenerowanie potwierdzenia transakcji
+ \item Aktualizacja salda konta użytkownika
+\end{enumerate}
+
+\paragraph{Obsługa sytuacji wyjątkowych:}
+\begin{itemize}
+ \item Jeśli identyfikacja pojazdu nie jest możliwa: uruchomienie procedury rejestracji incydentu z dokumentacją wizualną (zdjęcia niezidentyfikowanego pojazdu)
+
+ \item W przypadku niewystarczających środków na koncie:
+ \begin{enumerate}
+ \item Zablokowanie konta do momentu zapłacenia
+ \item W przypadku braku zapłaty w określonym czasie, uruchomienie procedury windykacyjnej
+ \end{enumerate}
+
+ \item Przy awarii urządzenia OBU: automatyczne przełączenie na identyfikację przez system kamer ANPR
+
+ \item W razie przerwy w komunikacji: lokalne buforowanie danych i synchronizacja po przywróceniu łączności
+
+ \item Jeśli zidentyfikowano omijanie bramek:
+ \begin{enumerate}
+ \item Poinformowanie użytkownika
+ \item Uruchomienie procedury kontrolnej
+ \item Naliczenie kary
+ \end{enumerate}
+\end{itemize}
+
+\subsection{Lista wymagań funkcjonalnych}
+
+\begin{enumerate}
+ \item \textbf{System rejestracji użytkowników} - System musi umożliwiać rejestrację nowych użytkowników z weryfikacją tożsamości, zbieraniem danych o pojazdach (w tym masa, klasa emisji, kategoria) oraz wyborem metody płatności (prepaid lub postpaid).
+
+ \item \textbf{Moduł geolokalizacji pojazdów} - System musi określać pozycję pojazdów z dokładnością do 10 metrów, wykorzystując dane GPS z urządzeń OBU lub aplikacji mobilnej, aktualizowane nie rzadziej niż co 30 sekund podczas przejazdu.
+
+ \item \textbf{System rozpoznawania tablic rejestracyjnych (ANPR)} - System musi identyfikować pojazdy poprzez kamery ANPR z dokładnością co najmniej 98\% w różnych warunkach pogodowych i oświetleniowych, jako dopełnienie jeśli wszystkie systemy działają poprawnie lub alternatywa dla urządzeń OBU w razie awarii.
+
+ \item \textbf{Elastyczny system taryfowy} - System musi obsługiwać zróżnicowane taryfy opłat w zależności od: typu pojazdu, masy całkowitej, klasy emisji spalin, pory dnia, dnia tygodnia oraz stopnia zatłoczenia drogi.
+
+ \item \textbf{Moduł rozliczeń i płatności} - System musi obsługiwać różne metody płatności (karty płatnicze, przelewy, płatności mobilne, blik) z możliwością automatycznego doładowania konta prepaid oraz wystawiania faktur elektronicznych zgodnych z przepisami prawa.
+
+ \item \textbf{System powiadomień dla użytkowników} - System musi wysyłać automatyczne powiadomienia do użytkowników (aplikacja, mail + sms) o: niskim stanie konta, zbliżającym się terminie płatności, dokonanych transakcjach oraz zmianach w taryfach i regulaminie.
+
+ \item \textbf{Moduł raportowania i analityki} - System musi generować raporty dotyczące natężenia ruchu, generowanych przychodów, incydentów oraz efektywności egzekwowania opłat, z możliwością eksportu danych w formatach CSV i PDF.
+
+ \item \textbf{System wykrywania naruszeń} - System musi identyfikować próby obejścia opłat (np. manipulacja urządzeniem OBU, podawanie fałszywych danych o pojeździe) i automatycznie uruchamiać procedury weryfikacyjne.
+
+ \item \textbf{Portal samoobsługowy dla użytkowników} - System musi udostępniać portal internetowy oraz aplikację mobilną umożliwiającą użytkownikom zarządzanie kontem, przeglądanie historii przejazdów i opłat, generowanie raportów oraz aktualizację danych pojazdu.
+
+ \item \textbf{System korekty opłat} - System musi umożliwiać ręczną korektę naliczonej opłaty przez operatora w przypadku zgłoszenia błędu przez użytkownika. Zakładając, że system źle naliczył opłatę np. Użytkownik został obciążony za trasę, której nie przejechał lub przypisano niewłaściwą kategorię pojazdu. Użytkownik zgłasza błąd do obsługi systemu. W takim przypadku operator musi mieć możliwość ręcznej korekty naliczonej opłaty np. Anulowanie opłaty, zmniejszenie jej lub ponowne przeliczenie, jeżeli zgłoszenie użytkownika okaże się zasadne. Zasadność zgłoszenia musi być weryfikowalna poprzez fizyczne zdjęcia pojazdu.
+\end{enumerate}
+
diff --git a/Programming/AIS/report/final/ver2/sections/02-wymagania-niefunkcjonalne.tex b/Programming/AIS/report/final/ver2/sections/02-wymagania-niefunkcjonalne.tex
new file mode 100644
index 00000000..b13f9cad
--- /dev/null
+++ b/Programming/AIS/report/final/ver2/sections/02-wymagania-niefunkcjonalne.tex
@@ -0,0 +1,42 @@
+\section{Wymagania niefunkcjonalne}
+
+\begin{enumerate}
+ \item \textbf{Wydajność systemu} - System musi obsługiwać jednoczesne przetwarzanie danych z co najmniej 200,000 pojazdów w godzinach szczytu\footnote{\url{https://forsal.pl/transport/drogi/artykuly/8295957,najbardziej-obciazone-drogi-w-polsce-s8-s2-a4-s86-mapa.html}}, z czasem odpowiedzi dla transakcji poniżej 1s oraz przetwarzaniem danych geolokalizacyjnych w czasie rzeczywistym.
+
+ \item \textbf{Dostępność systemu} - System musi zapewniać dostępność na poziomie 99,9\% (maksymalny czas niedostępności: $\sim$9 godzin rocznie), z planowanymi oknami serwisowymi w godzinach nocnych (1:00-4:00) i z odpowiednim wyprzedzeniem komunikowanym użytkownikom.
+
+ \item \textbf{Bezpieczeństwo danych} - System musi zapewniać:
+ \begin{enumerate}
+ \item Szyfrowanie danych w spoczynku i podczas transmisji (minimum AES-256)
+ \item Zgodność z normą ISO/IEC 27001
+ \item Wielopoziomową autoryzację użytkowników (hasło + kod sms)
+ \item Pełną zgodność z RODO, włączając automatyczne mechanizmy anonimizacji danych historycznych starszych niż 5 lat.
+ \end{enumerate}
+
+ \item \textbf{Skalowalność} - System musi posiadać architekturę umożliwiającą skalowanie w celu obsługi wzrostu liczby użytkowników o 30\% rocznie bez pogorszenia wydajności\footnote{\url{https://kpmg.com/pl/pl/home/media/press-releases/2024/02/liczba-rejestracji-nowych-samochodow-osobowych-wzrosla-o-13-2-procent-w-2023-roku.html}}, z automatycznym zwiększeniem zasobów w odpowiedzi na zwiększone obciążenie w ciągu dnia.
+
+ \item \textbf{Niezawodność i odporność na awarie} - System musi zawierać rozwiązania wysokiej dostępności z nadmiarowością komponentów krytycznych, automatycznym przełączaniem awaryjnym poniżej 10 sekund oraz mechanizmem ciągłej replikacji danych między geograficznie odległymi centrami danych, zapewniając RPO (Recovery Point Objective) poniżej 5 minut i RTO (Recovery Time Objective) poniżej 30 minut.
+
+ \item \textbf{Interoperacyjność} - System musi obsługiwać standardy interoperacyjności z europejskimi systemami elektronicznego poboru opłat (zgodnie z dyrektywą EETS\footnote{\url{https://eur-lex.europa.eu/legal-content/PL/TXT/?uri=CELEX\%3A32019L0520}}), zapewniając pełną wymianę danych poprzez standardowe API (REST/SOAP) z minimum 99,5\% dostępnością interfejsów integracyjnych.
+
+ \item \textbf{Użyteczność i dostępność interfejsów} - Interfejsy użytkownika (portal i aplikacja mobilna) muszą spełniać standardy WCAG 2.1 na poziomie AA, obsługiwać minimum 5 języków (polski, angielski, niemiecki, ukraiński, rosyjski), zapewniać responsywność na urządzeniach mobilnych oraz wykazywać wskaźnik satysfakcji użytkowników (CSAT) na poziomie minimum 85\%.
+
+ \item \textbf{Audytowanie i śledzenie aktywności} - System musi rejestrować wszystkie operacje w niezmienialne logi z zachowaniem zgodności z wymogami prawnymi dotyczącymi dowodów elektronicznych, umożliwiać niemodyfikowalny ślad audytu dla wszystkich transakcji finansowych oraz zapewniać przechowywanie logów przez minimum 5 lat z możliwością szybkiego wyszukiwania.
+
+ \item \textbf{Efektywność zarządzania danymi} - System musi umożliwiać archiwizację i zarządzanie cyklem życia danych zgodnie z polityką retencji, zapewniać kompresję danych historycznych na poziomie minimum 80\% oraz optymalizację zapytań do bazy danych z czasem odpowiedzi poniżej 10 sekund dla 90\% zapytań raportowych.
+
+ \item \textbf{Utrzymywalność i modyfikowalność} - System musi być zaprojektowany z wykorzystaniem architektury modułowej i mikroserwisowej, umożliwiającej niezależną aktualizację poszczególnych komponentów bez przerywania działania całości systemu, z automatycznymi testami regresji pokrywającymi minimum 90\% kodu oraz pełną dokumentacją techniczną aktualizowaną przy każdej \textbf{dużej} (takiej która sprawia że system nie jest kompatybilny z poprzednią wersją) zmianie.
+
+ \item \textbf{System integracji z zewnętrznymi bazami danych} - System musi komunikować się z zewnętrznymi bazami danych (np. CEPiK, rejestry pojazdów innych krajów) w celu weryfikacji danych pojazdów oraz wymiany informacji o użytkownikach z zagranicznymi systemami poboru opłat.
+
+ \item \textbf{Zgodność prawna i regulacyjna} - System musi spełniać wszystkie obowiązujące przepisy prawa krajowego oraz unijnego dotyczące elektronicznego poboru opłat. Ustawę o drogach publicznych, dyrektywę EETS, przepisy podatkowe oraz przepisy dotyczące ochrony konkurencji i konsumentów.
+
+ \item \textbf{Czas wdrożenia poprawek krytycznych} - w przypadku wykrycia krytycznego błędu (np. Uniemożliwiającego naliczenie opłaty lub przetwarzanie przejazdów) poprawka musi zostać wdrożona w ciągu maksymalnie 24 godzin od momentu potwierdzenia błędu.
+
+ \item \textbf{Transparentność naliczanych opłat} - system musi umożliwiać użytkownikom końcowym wgląd w szczegółowe informacje dotyczące każdej naliczonej opłaty. Czas przejazdu, odcinki dróg, taryfy oraz podstawy naliczenia.
+
+ \item \textbf{Elastyczność taryf} - system musi obsługiwać dynamiczne taryfy drogowe (np. Zmienne w zależności od natężenia ruchu czy poziomu emisji pojazdu) z możliwoścą wdrażania nowych taryf bez konieczności przerywania działania systemu.
+
+ \item \textbf{Personalizacja powiadomień dla użytkowników} - system musi umożliwić użytkownikom wybór otrzymywania powiadomień np. (sms, e-mail, powiadomienie push w aplikacji) z opcją definiowania progów powiadomień (np. Przekroczenie salda, opłata powyżej X zł etc.)
+\end{enumerate}
+
diff --git a/Programming/AIS/report/final/ver2/sections/03-decyzje-architektoniczne.tex b/Programming/AIS/report/final/ver2/sections/03-decyzje-architektoniczne.tex
new file mode 100644
index 00000000..c89eb8e1
--- /dev/null
+++ b/Programming/AIS/report/final/ver2/sections/03-decyzje-architektoniczne.tex
@@ -0,0 +1,216 @@
+\section{Decyzje architektoniczne}
+
+\subsection{Podział na warstwy}
+\begin{figure}[H]
+\centering
+\includegraphics[width=0.8\textwidth]{wybor_architektury.png}
+\caption{Diagram podziału na warstwy}
+\label{fig:layers}
+\end{figure}
+
+\begin{itemize}
+\item Warstwa prezentacji: trzy różne aplikacje klienckie — aplikacja webowa, mobilna i aplikacja na urządzenia embedded.
+\item Warstwa logiki biznesowej: centralna aplikacja serwerowa (serverApp), w której znajdują się komponenty takie jak UserService, PaymentService, PositionService itd.
+\item Warstwa dostępu do danych: komponenty UserRepository, PaymentRepository.
+\item Warstwa danych: baza danych Oracle z mechanizmem failover.
+\end{itemize}
+
+\textbf{Decyzja:} Rozdzielenie odpowiedzialności na warstwy zwiększa modularność i ułatwia zarządzanie kodem oraz jego testowanie.
+
+\textbf{Alternatywa:} Architektura mikroserwisowa
+
+\textbf{Zalety alternatywy:}
+\begin{itemize}
+\item Lepsza skalowalność poszczególnych komponentów
+\item Możliwość niezależnego wdrażania i rozwijania usług
+\item Lepsza odporność na awarie (awaria jednego serwisu $\neq$ awaria całego systemu)
+\end{itemize}
+
+\textbf{Wady alternatywy:}
+\begin{itemize}
+\item Większa złożoność wdrożeniowa (DevOps, CI/CD, monitoring)
+\item Konieczność rozwiązywania problemów związanych z komunikacją między serwisami
+\item Trudniejsze debugowanie i testowanie end-to-end
+\end{itemize}
+
+\subsection{Modularność i komponenty (Component-based Design)}
+\begin{figure}[H]
+\centering
+\includegraphics[width=0.8\textwidth]{organizacja_aplikacji_serwerowej.png}
+\caption{Diagram komponentów}
+\label{fig:components}
+\end{figure}
+
+\begin{itemize}
+\item Serwerowa aplikacja została podzielona na komponenty pełniące konkretne role (SigninController, TollController, MainComponent, itd.).
+\item Każdy komponent ma jasno zdefiniowaną odpowiedzialność, zgodnie z zasadą Single Responsibility Principle.
+\end{itemize}
+
+\textbf{Decyzja:} Wprowadzenie komponentów umożliwia łatwe rozszerzanie i testowanie poszczególnych fragmentów systemu.
+
+\textbf{Alternatywa:} Monolityczna aplikacja serwerowa
+
+\textbf{Zalety alternatywy:}
+\begin{itemize}
+\item Prostsza implementacja i wdrożenie
+\item Mniejsza liczba zależności i konfiguracji
+\item Mniej złożone środowisko developerskie
+\end{itemize}
+
+\textbf{Wady alternatywy:}
+\begin{itemize}
+\item Trudniejsza skalowalność i refaktoryzacja
+\item Każda zmiana wymaga redeploy całej aplikacji
+\item Trudniejsze testowanie izolowanych funkcji
+\end{itemize}
+
+\subsection{Wielokanałowy dostęp (Multi-Platform Clients)}
+\begin{figure}[H]
+\centering
+\includegraphics[width=0.8\textwidth]{dostep_do_systemu.png}
+\caption{Diagram wielokanałowego dostępu}
+\label{fig:multichannel}
+\end{figure}
+
+\begin{itemize}
+\item Użytkownicy mogą korzystać z systemu za pomocą aplikacji mobilnej, webowej lub urządzeń embedded.
+\end{itemize}
+
+\textbf{Decyzja:} Umożliwienie różnym grupom użytkowników (np. administratorzy vs kierowcy) dostępu do funkcji systemu w najbardziej dogodny sposób.
+
+\textbf{Alternatywa:} Tylko aplikacja mobilna (np. PWA lub natywna)
+
+\textbf{Zalety alternatywy:}
+\begin{itemize}
+\item Uproszczony interfejs użytkownika
+\item Jedna platforma do utrzymania
+\item Lepsze dopasowanie do kontekstu użytkownika (kierowcy)
+\end{itemize}
+
+\textbf{Wady alternatywy:}
+\begin{itemize}
+\item Brak wygodnego interfejsu dla administratorów lub analityków
+\item Mniejsza elastyczność użytkowania
+\item Trudności z dostępem do systemu z urządzeń stacjonarnych
+\end{itemize}
+
+\subsection{Rozdzielenie ról i uprawnień}
+\begin{figure}[H]
+\centering
+\includegraphics[width=0.8\textwidth]{uprawnienia_dla_uzytkownikow.png}
+\caption{Diagram ról i uprawnień}
+\label{fig:roles}
+\end{figure}
+
+\begin{itemize}
+\item Administrator ma dostęp tylko przez aplikację webową.
+\item Kierowca może korzystać z trzech różnych interfejsów — w zależności od potrzeb.
+\end{itemize}
+
+\textbf{Decyzja:} Jasny podział ról zwiększa bezpieczeństwo i ergonomię systemu.
+
+\textbf{Alternatywa:} Jeden zunifikowany interfejs z uprawnieniami na poziomie konta
+
+\textbf{Zalety alternatywy:}
+\begin{itemize}
+\item Mniejsze zróżnicowanie UI
+\item Mniej kodu i testów związanych z różnymi platformami
+\end{itemize}
+
+\textbf{Wady alternatywy:}
+\begin{itemize}
+\item Mniejsza przejrzystość
+\item Możliwość przypadkowego ujawnienia funkcji nieprzeznaczonych dla danego typu użytkownika
+\end{itemize}
+
+\subsection{Integracja z zewnętrznymi systemami}
+\begin{figure}[H]
+\centering
+\includegraphics[width=0.8\textwidth]{realizacja_obslugi_platnosci_i_archiwizacji_danych.png}
+\caption{Diagram integracji z systemami zewnętrznymi}
+\label{fig:integration}
+\end{figure}
+
+\begin{itemize}
+\item System płatności (systemPlatnosci) oraz system archiwizacji danych (archiwum) są zewnętrznymi systemami zintegrowanymi z systemem e-Toll.
+\end{itemize}
+
+\textbf{Decyzja:} Wydzielenie tych odpowiedzialności do zewnętrznych systemów pozwala na lepsze skalowanie oraz wykorzystanie istniejących rozwiązań.
+
+\textbf{Alternatywa:} Wszystko w ramach jednej aplikacji (np. własny moduł płatności i archiwizacji)
+
+\textbf{Zalety alternatywy:}
+\begin{itemize}
+\item Większa kontrola nad logiką
+\item Mniejsze zależności zewnętrzne
+\end{itemize}
+
+\textbf{Wady alternatywy:}
+\begin{itemize}
+\item Większe ryzyko błędów w obszarach regulowanych prawnie (np. płatności)
+\item Większe koszty utrzymania i certyfikacji
+\item Brak skalowalności i elastyczności
+\end{itemize}
+
+\subsection{Wysoka dostępność i odporność na awarie}
+\begin{figure}[H]
+\centering
+\includegraphics[width=0.8\textwidth]{zapewnienie_dostepnosci_i_odpornosci_na_awarie.png}
+\caption{Diagram wysokiej dostępności}
+\label{fig:high-availability}
+\end{figure}
+
+\begin{itemize}
+\item Baza danych jest replikowana (primary–secondary).
+\item Oddzielne deployment node'y dla różnych typów urządzeń oraz dla aplikacji serwerowej i bazy danych.
+\item Failover serwera bazy danych — Oracle - Secondary.
+\end{itemize}
+
+\textbf{Decyzja:} Architektura uwzględnia mechanizmy zapewniające ciągłość działania systemu nawet w przypadku awarii.
+
+\textbf{Alternatywa:} Deployment w chmurze
+
+\textbf{Zalety alternatywy:}
+\begin{itemize}
+\item Duża skalowalność
+\item Bezpieczeństwo i redundancja
+\end{itemize}
+
+\textbf{Wady alternatywy:}
+\begin{itemize}
+\item Wyższe koszty
+\item Przetwarzanie danych przez inne podmioty
+\end{itemize}
+
+\subsection{Wybór technologii wdrożeniowych}
+\begin{figure}[H]
+\centering
+\includegraphics[width=0.8\textwidth]{wybor_technologii_wdrozeniowej.png}
+\caption{Diagram technologii wdrożeniowych}
+\label{fig:deployment-tech}
+\end{figure}
+
+\begin{itemize}
+\item System hostowany na serwerach z Ubuntu 24.04 LTS.
+\item Serwer aplikacji oparty o Apache Tomcat 8.x.
+\item Baza danych Oracle 12c.
+\end{itemize}
+
+\textbf{Decyzja:} Użycie sprawdzonych technologii o długoterminowym wsparciu i wysokiej wydajności.
+
+\textbf{Alternatywa:} Cloud-native stack – np. AWS/GCP
+
+\textbf{Zalety alternatywy:}
+\begin{itemize}
+\item Automatyczne skalowanie, monitoring, CI/CD
+\item Niższe koszty utrzymania fizycznej infrastruktury
+\item Łatwiejsze zarządzanie kontenerami i usługami
+\end{itemize}
+
+\textbf{Wady alternatywy:}
+\begin{itemize}
+\item Uzależnienie od chmury (vendor lock-in)
+\item Potrzeba opanowania nowych technologii
+\item Potencjalne wyższe koszty początkowe
+\end{itemize}
+
diff --git a/Programming/AIS/report/final/ver2/sections/04-projekt-systemu-w-postaci-modelu-c4.tex b/Programming/AIS/report/final/ver2/sections/04-projekt-systemu-w-postaci-modelu-c4.tex
new file mode 100644
index 00000000..902d7582
--- /dev/null
+++ b/Programming/AIS/report/final/ver2/sections/04-projekt-systemu-w-postaci-modelu-c4.tex
@@ -0,0 +1,25 @@
+\section{Projekt systemu w postaci modelu C4}
+ \begin{figure}[H]
+ \centering
+ \includegraphics[width=1\textwidth]{c4/etoll.png}
+ \caption{Poziom context}
+ \label{fig:deployment-tech}
+ \end{figure}
+ \begin{figure}[H]
+ \centering
+ \includegraphics[width=1\textwidth]{c4/component_server_app.png}
+ \caption{Poziom component}
+ \label{fig:deployment-tech}
+ \end{figure}
+ \begin{figure}[H]
+ \centering
+ \includegraphics[width=1\textwidth]{c4/etool_glebiej.png}
+ \caption{Diagram dynamiczny}
+ \label{fig:deployment-tech}
+ \end{figure}
+ \begin{figure}[H]
+ \centering
+ \includegraphics[width=1\textwidth]{c4/deployment.png}
+ \caption{Diagram technologii wdrożeniowych}
+ \label{fig:deployment-tech}
+ \end{figure}
diff --git a/Programming/EARIN/lab5/report/EARIN_LAB_5_RUDNICKI_KLISZKO.tex b/Programming/EARIN/lab5/report/EARIN_LAB_5_RUDNICKI_KLISZKO.tex
index 9c00139b..609f22df 100644
--- a/Programming/EARIN/lab5/report/EARIN_LAB_5_RUDNICKI_KLISZKO.tex
+++ b/Programming/EARIN/lab5/report/EARIN_LAB_5_RUDNICKI_KLISZKO.tex
@@ -15,523 +15,7 @@
\maketitle
-\section{Exercise Variant 2}
-Use \href{https://pytorch.org/vision/stable/generated/torchvision.datasets.MNIST.html#torchvision.datasets.MNIST}{MIST} dataset. Evaluate at least 3 different numbers/values/types of:
-\begin{itemize}
- \item learning rate
- \item mini-batch size (including batch containing only 1 example)
- \item number of hidden layers (including 0 hidden layers - linear model)
- \item width (number of neurons in hidden layers)
- \item optimizer type (e.g., SGD, SGD with momentum, Adam)
-\end{itemize}
-
-\section{Implementation}
-Program can be ran by installing python, moving to project directory and issuing command:
-\begin{lstlisting}[language=bash]
-python main.py
-\end{lstlisting}
-Results will be displayed on three 2d scatter plots. \\
-Plots Title is filled with parameters used abbreviated for space sake \\
-Abbreviatons meaning:
-\begin{itemize}
- \item lr - Learning Rate
- \item bs - Batch Size
- \item hl - Number of Hidden Layers
- \item w - Width
- \item Adam or SGD or SGD\_Momentum - Optimizer type
-\end{itemize}
-Plot types:
-\begin{itemize}
- \item Loss value for learning step
- \item Train Accuracy for epoch
- \item Validation Accuracy for epoch
-\end{itemize}
-
-\begin{figure}[H]
- \caption{Exemplary plot of loss for learning Step \\ lr0.001-bs64-hl1-w128-Adam }
- \includegraphics[width=\textwidth]{testsResults/loss/def.png}
- \centering
- \end{figure}
-\begin{figure}[H]
- \caption{Exemplary plot of Validation Accuracy for epoch \\ lr0.001-bs64-hl1-w128-Adam }
- \includegraphics[width=\textwidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w64-Adam.png}
- \centering
- \end{figure}
-\begin{figure}[H]
-\caption{Exemplary plot of Train Accuracy for epoch \\ lr0.001-bs64-hl1-w128-Adam }
-\includegraphics[width=\textwidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w64-Adam.png}
-\centering
-\end{figure}
-Results will be displayed and saved in the same folder as code directory for further inspection, with file name containing information about input parameters \\
-Additionaly speed it took for neural network to run will be saved to results.txt along with what parameters were used \\
-We decided to run 19 tests in total:
-\begin{enumerate}
- \item learning rate [0.1, 0.01, 0.001] (3 tests)
- \item mini-batch size [1, 64, 128, 256] (4 tests)
- \item number of hidden layers [0, 1, 2, 3] (4 tests)
- \item width [64, 128, 256, 512, 1024] (5 tests)
- \item optimizer type [SGD, SGD\_Momentum, Adam] (3 tests)
-\end{enumerate}
-\section{Results}
-We have successfully implemented network analyzing MNIST dataset \\
-\subsection{Loss Graphs}
-
-\subsubsection{Learning Rate}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/lr/def.png}
- \caption{Default settings + learning rate = 0.001}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/lr/loss-lr0.01-bs64-hl2-w128-Adam.png}
- \caption{Default settings + learning rate = 0.01}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/lr/loss-lr0.1-bs64-hl2-w128-Adam.png}
- \caption{Default settings + learning rate = 0.1}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Smaller learning rate causes losses to drop near zero level faster (notice how there is a vertical drop for lower learning step for leaerning rate 0.001, later for learning rate 0.01 and never for learnig rate 0.1)
-
-\subsubsection{Mini-Batch size}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/bs/def.png}
- \caption{Default settings + batching size = 64}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/bs/loss-1batch.png}
- \caption{Default settings + batching size = 1}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/bs/loss-lr0.001-bs128-hl2-w128-Adam.png}
- \caption{Default settings + batching size = 128}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/bs/loss-lr0.001-bs256-hl2-w128-Adam.png}
- \caption{Default settings + batching size = 256}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Batching size equal to 1 makes losses seem pretty much random, increasing batch sizes increases 'flat' (smaller) loss periods between local peaks
-
-\subsubsection{Number of Hidden Layers}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/hl/hl0loss.png}
- \caption{Default settings + hidden layers = 0}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/hl/loss-lr0.001-bs64-hl1-w128-Adam.png}
- \caption{Default settings + hidden layers = 1}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/hl/def.png}
- \caption{Default settings + hidden layers = 2}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/hl/loss-lr0.001-bs64-hl3-w128-Adam.png}
- \caption{Default settings + hidden layers = 3}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Setting hidden layers to 0 again makes losses value seem random, hidden layer set to 1 provides us with later drop but longer flat periods, number of hidden layers set to 2 offeres the opposite and number of layers set to 3 seems to be a compromise between those two
-\subsubsection{Width}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/w/def.png}
- \caption{Default settings + width = 128}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/w/loss-lr0.001-bs64-hl2-w64-Adam.png}
- \caption{Default settings + width = 64}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/w/loss-lr0.001-bs64-hl2-w256-Adam.png}
- \caption{Default settings + width = 256}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/w/loss-lr0.001-bs64-hl2-w512-Adam.png}
- \caption{Default settings + width = 512}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/w/loss-lr0.001-bs64-hl2-w1024-Adam.png}
- \caption{Default settings + width = 1024}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Changing width does not seem to affect loss greatly
-
-
-\subsubsection{Optimizer Type}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/optimizer/def.png}
- \caption{Default settings + Adam optimizer}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/loss/optimizer/loss-lr0.001-bs64-hl2-w128-SGD.png}
- \caption{Default settings + learning rate = 0.01}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/loss/optimizer/loss-lr0.001-bs64-hl2-w128-SGD_Momentum.png}
- \caption{Default settings + SGD\_Momentum optimizer}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Changing optimizers does not seem to affect loss greatly
-
-
-\subsection{Train Accuracy Graphs}
-
-\subsubsection{Learning Rate}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
- \caption{Default settings + learning rate = 0.001}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.01-bs64-hl2-w128-Adam.png}
- \caption{Default settings + learning rate = 0.01}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.1-bs64-hl2-w128-Adam.png}
- \caption{Default settings + learning rate = 0.1}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Making training accuracy smaller than 0.01 seems to be unnecessary for this dataset as it offers little to no improve in accuracy. Setting it to 0.1 on the other hand provides very low accuracy of neural network
-
-\subsubsection{Mini-Batch size}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
- \caption{Default settings + batching size = 64}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy1batch.png}
- \caption{Default settings + batching size = 1}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs128-hl2-w128-Adam.png}
- \caption{Default settings + batching size = 128}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs256-hl2-w128-Adam.png}
- \caption{Default settings + batching size = 256}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Increasing batching size does not seem to make drastic change for train accuracy, even setting batching size to 1 offers very good (over 95 \%) accuracy
-
-
-
-
-\subsubsection{Number of Hidden Layers}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl0-w128-Adam.png}
- \caption{Default settings + hidden layers = 0}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl1-w128-Adam.png}
- \caption{Default settings + hidden layers = 1}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
- \caption{Default settings + hidden layers = 2}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl3-w128-Adam.png}
- \caption{Default settings + hidden layers = 3}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Increasing hidden layers number reduces variety of train accuracy results, with hidden layers set to 0 having accuracy vary between 91 and 98 and with hidden layers equal to 3 showing much smoother graph
-\subsubsection{Width}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
- \caption{Default settings + width = 128}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w64-Adam.png}
- \caption{Default settings + width = 64}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w256-Adam.png}
- \caption{Default settings + width = 256}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w512-Adam.png}
- \caption{Default settings + width = 512}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w1024-Adam.png}
- \caption{Default settings + width = 1024}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Changing width does not seem to influence accuracy much
-
-\subsubsection{Optimizer Type}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
- \caption{Default settings + Adam optimizer}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w128-SGD.png}
- \caption{Default settings + learning rate = 0.01}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w128-SGD_Momentum.png}
- \caption{Default settings + SGD\_Momentum optimizer}
- \endminipage
- \end{figure}
-
- \paragraph{Analysis} Changing optimizer type does not seem to influence accuracy much
-
-\subsection{Validation Accuracy Graphs}
-Validation Accuracy Graphs look similar to Train accuracy so in order not to repeat ourselves we ommited analysis of them
-
-
-\subsubsection{Learning Rate}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
- \caption{Default settings + learning rate = 0.001}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.01-bs64-hl2-w128-Adam.png}
- \caption{Default settings + learning rate = 0.01}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
- \caption{Default settings + learning rate = 0.1}
- \endminipage
- \end{figure}
-
-\subsubsection{Mini-Batch size}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
- \caption{Default settings + batching size = 64}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy1batch.png}
- \caption{Default settings + batching size = 1}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs128-hl2-w128-Adam.png}
- \caption{Default settings + batching size = 128}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs256-hl2-w128-Adam.png}
- \caption{Default settings + batching size = 256}
- \endminipage
- \end{figure}
-
-\subsubsection{Number of Hidden Layers}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracyhl0.png}
- \caption{Default settings + hidden layers = 0}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl1-w128-Adam.png}
- \caption{Default settings + hidden layers = 1}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
- \caption{Default settings + hidden layers = 2}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl3-w128-Adam.png}
- \caption{Default settings + hidden layers = 3}
- \endminipage
- \end{figure}
- \newpage
-\subsubsection{Width}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
- \caption{Default settings + width = 128}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w64-Adam.png}
- \caption{Default settings + width = 64}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w256-Adam.png}
- \caption{Default settings + width = 256}
- \endminipage
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w512-Adam.png}
- \caption{Default settings + width = 512}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w1024-Adam.png}
- \caption{Default settings + width = 1024}
- \endminipage
- \end{figure}
-
-\subsubsection{Optimizer Type}
-
- \begin{figure}[H]
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
- \caption{Default settings + Adam optimizer}
- \endminipage\hfill
- \minipage{0.5\textwidth}
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w128-SGD.png}
- \caption{Default settings + learning rate = 0.01}
- \endminipage
- \end{figure}
- \begin{figure}[H]
- \minipage{0.5\textwidth}%
- \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w128-SGD_Momentum.png}
- \caption{Default settings + SGD\_Momentum optimizer}
- \endminipage
- \end{figure}
-
- \subsection{Speed}
- We also checked how different parameters impact speed of the neural network learning
-
- \paragraph{Changing learning rate}
- \begin{center}
- \begin{tabular}{ | c | c | }
- \hline
- Learning rate & Execution Time [s] \\
- \hline
- 0.001 (default) & 49.3 \\
- \hline
- 0.01 & 53.9 \\
- \hline
- 0.1 & 50.1 \\
- \hline
- \end{tabular}
- \end{center}
-
- \paragraph{Changing batch size}
- \begin{center}
- \begin{tabular}{ | c | c | }
- \hline
- Batch Size & Execution Time [s] \\
- \hline
- 1 & 567.2 (!) \\
- \hline
- 64 (default) & 49.3 \\
- \hline
- 128 & 48.1 \\
- \hline
- 256 & 42.8 \\
- \hline
-
- \end{tabular}
- \end{center}
-
- \paragraph{Changing number of hidden layers}
- \begin{center}
- \begin{tabular}{ | c | c | }
- \hline
- Hidden layers & Execution Time [s] \\
- \hline
- 0 & 44.5 \\
- \hline
- 1 & 48.8 \\
- \hline
- 2 (default) & 49.3 \\
- \hline
- 3 & 48.7 \\
- \hline
- \end{tabular}
- \end{center}
-
- \paragraph{Changing width}
- \begin{center}
- \begin{tabular}{ | c | c | }
- \hline
- Width & Execution Time [s] \\
- \hline
- 64 & 46.7 \\
- \hline
- 128 (default) & 49.3 \\
- \hline
- 256 & 49.0 \\
- \hline
- 512 & 52.1 \\
- \hline
- 1024 & 73.9 \\
- \hline
- \end{tabular}
- \end{center}
-
- \paragraph{Changing optimizer type}
- \begin{center}
- \begin{tabular}{ | c | c | }
- \hline
- Learning rate & Execution Time [s] \\
- \hline
- Adam (default) & 49.3 \\
- \hline
- SGD & 45.1 \\
- \hline
- SGD Momentum & 45.5 \\
- \hline
- \end{tabular}
- \end{center}
-
- \paragraph{Analysis}
- Two parameters that had the biggest impact on execution time was setting batch size to extremely low value (1) and increasing width (jump between 512 width and 1024 is equal to 20 seconds more execution time)
-
+ \input{sections/01-exercise-variant-2}
+ \input{sections/02-implementation}
+ \input{sections/03-results}
\end{document}
diff --git a/Programming/EARIN/lab5/report/sections/01-exercise-variant-2.tex b/Programming/EARIN/lab5/report/sections/01-exercise-variant-2.tex
new file mode 100644
index 00000000..806cd6b6
--- /dev/null
+++ b/Programming/EARIN/lab5/report/sections/01-exercise-variant-2.tex
@@ -0,0 +1,10 @@
+\section{Exercise Variant 2}
+Use \href{https://pytorch.org/vision/stable/generated/torchvision.datasets.MNIST.html#torchvision.datasets.MNIST}{MIST} dataset. Evaluate at least 3 different numbers/values/types of:
+\begin{itemize}
+ \item learning rate
+ \item mini-batch size (including batch containing only 1 example)
+ \item number of hidden layers (including 0 hidden layers - linear model)
+ \item width (number of neurons in hidden layers)
+ \item optimizer type (e.g., SGD, SGD with momentum, Adam)
+\end{itemize}
+
diff --git a/Programming/EARIN/lab5/report/sections/02-implementation.tex b/Programming/EARIN/lab5/report/sections/02-implementation.tex
new file mode 100644
index 00000000..f1526a4d
--- /dev/null
+++ b/Programming/EARIN/lab5/report/sections/02-implementation.tex
@@ -0,0 +1,47 @@
+\section{Implementation}
+Program can be ran by installing python, moving to project directory and issuing command:
+\begin{lstlisting}[language=bash]
+python main.py
+\end{lstlisting}
+Results will be displayed on three 2d scatter plots. \\
+Plots Title is filled with parameters used abbreviated for space sake \\
+Abbreviatons meaning:
+\begin{itemize}
+ \item lr - Learning Rate
+ \item bs - Batch Size
+ \item hl - Number of Hidden Layers
+ \item w - Width
+ \item Adam or SGD or SGD\_Momentum - Optimizer type
+\end{itemize}
+Plot types:
+\begin{itemize}
+ \item Loss value for learning step
+ \item Train Accuracy for epoch
+ \item Validation Accuracy for epoch
+\end{itemize}
+
+\begin{figure}[H]
+ \caption{Exemplary plot of loss for learning Step \\ lr0.001-bs64-hl1-w128-Adam }
+ \includegraphics[width=\textwidth]{testsResults/loss/def.png}
+ \centering
+ \end{figure}
+\begin{figure}[H]
+ \caption{Exemplary plot of Validation Accuracy for epoch \\ lr0.001-bs64-hl1-w128-Adam }
+ \includegraphics[width=\textwidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w64-Adam.png}
+ \centering
+ \end{figure}
+\begin{figure}[H]
+\caption{Exemplary plot of Train Accuracy for epoch \\ lr0.001-bs64-hl1-w128-Adam }
+\includegraphics[width=\textwidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w64-Adam.png}
+\centering
+\end{figure}
+Results will be displayed and saved in the same folder as code directory for further inspection, with file name containing information about input parameters \\
+Additionaly speed it took for neural network to run will be saved to results.txt along with what parameters were used \\
+We decided to run 19 tests in total:
+\begin{enumerate}
+ \item learning rate [0.1, 0.01, 0.001] (3 tests)
+ \item mini-batch size [1, 64, 128, 256] (4 tests)
+ \item number of hidden layers [0, 1, 2, 3] (4 tests)
+ \item width [64, 128, 256, 512, 1024] (5 tests)
+ \item optimizer type [SGD, SGD\_Momentum, Adam] (3 tests)
+\end{enumerate}
diff --git a/Programming/EARIN/lab5/report/sections/03-results.tex b/Programming/EARIN/lab5/report/sections/03-results.tex
new file mode 100644
index 00000000..aed7ab1a
--- /dev/null
+++ b/Programming/EARIN/lab5/report/sections/03-results.tex
@@ -0,0 +1,6 @@
+\section{Results}
+We have successfully implemented network analyzing MNIST dataset \\
+ \input{sections/03-results/01-loss-graphs}
+ \input{sections/03-results/02-train-accuracy-graphs}
+ \input{sections/03-results/03-validation-accuracy-graphs}
+ \input{sections/03-results/04-speed}
diff --git a/Programming/EARIN/lab5/report/sections/03-results/01-loss-graphs.tex b/Programming/EARIN/lab5/report/sections/03-results/01-loss-graphs.tex
new file mode 100644
index 00000000..bbb50937
--- /dev/null
+++ b/Programming/EARIN/lab5/report/sections/03-results/01-loss-graphs.tex
@@ -0,0 +1,126 @@
+\subsection{Loss Graphs}
+
+\subsubsection{Learning Rate}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/lr/def.png}
+ \caption{Default settings + learning rate = 0.001}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/lr/loss-lr0.01-bs64-hl2-w128-Adam.png}
+ \caption{Default settings + learning rate = 0.01}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/lr/loss-lr0.1-bs64-hl2-w128-Adam.png}
+ \caption{Default settings + learning rate = 0.1}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Smaller learning rate causes losses to drop near zero level faster (notice how there is a vertical drop for lower learning step for leaerning rate 0.001, later for learning rate 0.01 and never for learnig rate 0.1)
+
+\subsubsection{Mini-Batch size}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/bs/def.png}
+ \caption{Default settings + batching size = 64}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/bs/loss-1batch.png}
+ \caption{Default settings + batching size = 1}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/bs/loss-lr0.001-bs128-hl2-w128-Adam.png}
+ \caption{Default settings + batching size = 128}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/bs/loss-lr0.001-bs256-hl2-w128-Adam.png}
+ \caption{Default settings + batching size = 256}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Batching size equal to 1 makes losses seem pretty much random, increasing batch sizes increases 'flat' (smaller) loss periods between local peaks
+
+\subsubsection{Number of Hidden Layers}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/hl/hl0loss.png}
+ \caption{Default settings + hidden layers = 0}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/hl/loss-lr0.001-bs64-hl1-w128-Adam.png}
+ \caption{Default settings + hidden layers = 1}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/hl/def.png}
+ \caption{Default settings + hidden layers = 2}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/hl/loss-lr0.001-bs64-hl3-w128-Adam.png}
+ \caption{Default settings + hidden layers = 3}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Setting hidden layers to 0 again makes losses value seem random, hidden layer set to 1 provides us with later drop but longer flat periods, number of hidden layers set to 2 offeres the opposite and number of layers set to 3 seems to be a compromise between those two
+\subsubsection{Width}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/w/def.png}
+ \caption{Default settings + width = 128}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/w/loss-lr0.001-bs64-hl2-w64-Adam.png}
+ \caption{Default settings + width = 64}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/w/loss-lr0.001-bs64-hl2-w256-Adam.png}
+ \caption{Default settings + width = 256}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/w/loss-lr0.001-bs64-hl2-w512-Adam.png}
+ \caption{Default settings + width = 512}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/w/loss-lr0.001-bs64-hl2-w1024-Adam.png}
+ \caption{Default settings + width = 1024}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Changing width does not seem to affect loss greatly
+
+
+\subsubsection{Optimizer Type}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/optimizer/def.png}
+ \caption{Default settings + Adam optimizer}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/loss/optimizer/loss-lr0.001-bs64-hl2-w128-SGD.png}
+ \caption{Default settings + learning rate = 0.01}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/loss/optimizer/loss-lr0.001-bs64-hl2-w128-SGD_Momentum.png}
+ \caption{Default settings + SGD\_Momentum optimizer}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Changing optimizers does not seem to affect loss greatly
+
+
diff --git a/Programming/EARIN/lab5/report/sections/03-results/02-train-accuracy-graphs.tex b/Programming/EARIN/lab5/report/sections/03-results/02-train-accuracy-graphs.tex
new file mode 100644
index 00000000..367632e0
--- /dev/null
+++ b/Programming/EARIN/lab5/report/sections/03-results/02-train-accuracy-graphs.tex
@@ -0,0 +1,127 @@
+\subsection{Train Accuracy Graphs}
+
+\subsubsection{Learning Rate}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
+ \caption{Default settings + learning rate = 0.001}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.01-bs64-hl2-w128-Adam.png}
+ \caption{Default settings + learning rate = 0.01}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.1-bs64-hl2-w128-Adam.png}
+ \caption{Default settings + learning rate = 0.1}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Making training accuracy smaller than 0.01 seems to be unnecessary for this dataset as it offers little to no improve in accuracy. Setting it to 0.1 on the other hand provides very low accuracy of neural network
+
+\subsubsection{Mini-Batch size}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
+ \caption{Default settings + batching size = 64}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy1batch.png}
+ \caption{Default settings + batching size = 1}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs128-hl2-w128-Adam.png}
+ \caption{Default settings + batching size = 128}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs256-hl2-w128-Adam.png}
+ \caption{Default settings + batching size = 256}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Increasing batching size does not seem to make drastic change for train accuracy, even setting batching size to 1 offers very good (over 95 \%) accuracy
+
+
+
+
+\subsubsection{Number of Hidden Layers}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl0-w128-Adam.png}
+ \caption{Default settings + hidden layers = 0}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl1-w128-Adam.png}
+ \caption{Default settings + hidden layers = 1}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
+ \caption{Default settings + hidden layers = 2}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl3-w128-Adam.png}
+ \caption{Default settings + hidden layers = 3}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Increasing hidden layers number reduces variety of train accuracy results, with hidden layers set to 0 having accuracy vary between 91 and 98 and with hidden layers equal to 3 showing much smoother graph
+\subsubsection{Width}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
+ \caption{Default settings + width = 128}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w64-Adam.png}
+ \caption{Default settings + width = 64}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w256-Adam.png}
+ \caption{Default settings + width = 256}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w512-Adam.png}
+ \caption{Default settings + width = 512}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w1024-Adam.png}
+ \caption{Default settings + width = 1024}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Changing width does not seem to influence accuracy much
+
+\subsubsection{Optimizer Type}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/def.png}
+ \caption{Default settings + Adam optimizer}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w128-SGD.png}
+ \caption{Default settings + learning rate = 0.01}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/trainAccuracy/trainAccuracy-lr0.001-bs64-hl2-w128-SGD_Momentum.png}
+ \caption{Default settings + SGD\_Momentum optimizer}
+ \endminipage
+ \end{figure}
+
+ \paragraph{Analysis} Changing optimizer type does not seem to influence accuracy much
+
diff --git a/Programming/EARIN/lab5/report/sections/03-results/03-validation-accuracy-graphs.tex b/Programming/EARIN/lab5/report/sections/03-results/03-validation-accuracy-graphs.tex
new file mode 100644
index 00000000..5df70af2
--- /dev/null
+++ b/Programming/EARIN/lab5/report/sections/03-results/03-validation-accuracy-graphs.tex
@@ -0,0 +1,117 @@
+\subsection{Validation Accuracy Graphs}
+Validation Accuracy Graphs look similar to Train accuracy so in order not to repeat ourselves we ommited analysis of them
+
+
+\subsubsection{Learning Rate}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
+ \caption{Default settings + learning rate = 0.001}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.01-bs64-hl2-w128-Adam.png}
+ \caption{Default settings + learning rate = 0.01}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
+ \caption{Default settings + learning rate = 0.1}
+ \endminipage
+ \end{figure}
+
+\subsubsection{Mini-Batch size}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
+ \caption{Default settings + batching size = 64}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy1batch.png}
+ \caption{Default settings + batching size = 1}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs128-hl2-w128-Adam.png}
+ \caption{Default settings + batching size = 128}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs256-hl2-w128-Adam.png}
+ \caption{Default settings + batching size = 256}
+ \endminipage
+ \end{figure}
+
+\subsubsection{Number of Hidden Layers}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracyhl0.png}
+ \caption{Default settings + hidden layers = 0}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl1-w128-Adam.png}
+ \caption{Default settings + hidden layers = 1}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
+ \caption{Default settings + hidden layers = 2}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl3-w128-Adam.png}
+ \caption{Default settings + hidden layers = 3}
+ \endminipage
+ \end{figure}
+ \newpage
+\subsubsection{Width}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
+ \caption{Default settings + width = 128}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w64-Adam.png}
+ \caption{Default settings + width = 64}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w256-Adam.png}
+ \caption{Default settings + width = 256}
+ \endminipage
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w512-Adam.png}
+ \caption{Default settings + width = 512}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w1024-Adam.png}
+ \caption{Default settings + width = 1024}
+ \endminipage
+ \end{figure}
+
+\subsubsection{Optimizer Type}
+
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/def.png}
+ \caption{Default settings + Adam optimizer}
+ \endminipage\hfill
+ \minipage{0.5\textwidth}
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w128-SGD.png}
+ \caption{Default settings + learning rate = 0.01}
+ \endminipage
+ \end{figure}
+ \begin{figure}[H]
+ \minipage{0.5\textwidth}%
+ \includegraphics[width=\linewidth]{testsResults/validationAccuracy/validationAccuracy-lr0.001-bs64-hl2-w128-SGD_Momentum.png}
+ \caption{Default settings + SGD\_Momentum optimizer}
+ \endminipage
+ \end{figure}
+
diff --git a/Programming/EARIN/lab5/report/sections/03-results/04-speed.tex b/Programming/EARIN/lab5/report/sections/03-results/04-speed.tex
new file mode 100644
index 00000000..5bcff388
--- /dev/null
+++ b/Programming/EARIN/lab5/report/sections/03-results/04-speed.tex
@@ -0,0 +1,90 @@
+ \subsection{Speed}
+ We also checked how different parameters impact speed of the neural network learning
+
+ \paragraph{Changing learning rate}
+ \begin{center}
+ \begin{tabular}{ | c | c | }
+ \hline
+ Learning rate & Execution Time [s] \\
+ \hline
+ 0.001 (default) & 49.3 \\
+ \hline
+ 0.01 & 53.9 \\
+ \hline
+ 0.1 & 50.1 \\
+ \hline
+ \end{tabular}
+ \end{center}
+
+ \paragraph{Changing batch size}
+ \begin{center}
+ \begin{tabular}{ | c | c | }
+ \hline
+ Batch Size & Execution Time [s] \\
+ \hline
+ 1 & 567.2 (!) \\
+ \hline
+ 64 (default) & 49.3 \\
+ \hline
+ 128 & 48.1 \\
+ \hline
+ 256 & 42.8 \\
+ \hline
+
+ \end{tabular}
+ \end{center}
+
+ \paragraph{Changing number of hidden layers}
+ \begin{center}
+ \begin{tabular}{ | c | c | }
+ \hline
+ Hidden layers & Execution Time [s] \\
+ \hline
+ 0 & 44.5 \\
+ \hline
+ 1 & 48.8 \\
+ \hline
+ 2 (default) & 49.3 \\
+ \hline
+ 3 & 48.7 \\
+ \hline
+ \end{tabular}
+ \end{center}
+
+ \paragraph{Changing width}
+ \begin{center}
+ \begin{tabular}{ | c | c | }
+ \hline
+ Width & Execution Time [s] \\
+ \hline
+ 64 & 46.7 \\
+ \hline
+ 128 (default) & 49.3 \\
+ \hline
+ 256 & 49.0 \\
+ \hline
+ 512 & 52.1 \\
+ \hline
+ 1024 & 73.9 \\
+ \hline
+ \end{tabular}
+ \end{center}
+
+ \paragraph{Changing optimizer type}
+ \begin{center}
+ \begin{tabular}{ | c | c | }
+ \hline
+ Learning rate & Execution Time [s] \\
+ \hline
+ Adam (default) & 49.3 \\
+ \hline
+ SGD & 45.1 \\
+ \hline
+ SGD Momentum & 45.5 \\
+ \hline
+ \end{tabular}
+ \end{center}
+
+ \paragraph{Analysis}
+ Two parameters that had the biggest impact on execution time was setting batch size to extremely low value (1) and increasing width (jump between 512 width and 1024 is equal to 20 seconds more execution time)
+
diff --git a/Programming/EARIN/project/preliminary/report.tex b/Programming/EARIN/project/preliminary/report.tex
index 9b8f1d0d..85323d3a 100644
--- a/Programming/EARIN/project/preliminary/report.tex
+++ b/Programming/EARIN/project/preliminary/report.tex
@@ -17,269 +17,9 @@
The goal of this project is to develop a model for anime recommendation, which takes an anime name as an input and recommends a list of related anime's based on this name. \\
-\section{Algorithm description and examples}
-
-We will be using the collaborative filtering approach to develop our model. \\
-Collaborative filtering is a popular method for making personalized recommendations based on the preferences of other users with similar tastes. In this approach, the recommendation system analyzes a large data-set of user-item ratings to identify patterns and similarities between users and anime's, and uses this information to make recommendations to new users.
-
-We will represent users and anime's data-sets as embedding vectors. Embeddings provide a way to transform high-dimensional data into a lower-dimensional space while preserving relevant relationships.
-
-We have decided to use and test multiple metrics such as
-\begin{itemize}
- \item Cosine similarity
- \item Mahalanobis Distance
- \item Euclidean Distance
-\end{itemize}
-together with K-nearest neighbors algorithm. \\
-
-\subsection{Embedding users and anime}
-In order to embed users and anime we must choose which features of the user/anime are the most important for our model \\
-For the user we are restricted to what database offers, database pretty much only offers us what ratings the user gave to an anime, we will compare the performance of our algorithm when:
-\begin{itemize}
-\item Given ratings of the user for all anime that they gave rating to (no matter the watching status)
-\item Given ratings of the user for all anime that they have \emph{completed}
-\end{itemize}
-
-For anime we will use data:
-\begin{itemize}
- \item User score
- \item Popularity (this includes popularity itself, number of members and favourites)
- \item Controversy (Whether the anime gets a lot of 1s and 10s or just 6s)
-\end{itemize}
-
-We have decided to use two different methods to combine data and compare the results \\
-First method is dot product which gives a single number after multiplying two vectors \\
-The second is concatenation which returns a new vector combining first and second vector \\
-As an input for all our metrics (like cosine similarity) we will use vectors of anime and users
-
-
-\subsection{Metrics}
-%\emph{Cosine similarity} is a metric used to compute the similarity between two users based on their ratings or preferences for anime. In our case, we will use cosine similarity to compute the similarity between each pair of users in our data-set based on their anime ratings. This will result in a similarity matrix, where each entry (i,j) represents the cosine similarity between users i and j.
-\paragraph{Cosine similarity} is a measure used to calculate the similarity between two vectors representing items or users. It evaluates the cosine of the angle between the two vectors, indicating their directional similarity. In our use case, cosine similarity can help identify items or users with similar preferences or characteristics by comparing their embedding vectors. Higher cosine similarity values (closer to 1) indicate a stronger similarity between the vectors, suggesting that the items or users are more likely to have similar features or preferences.
-\paragraph{Mahalanobis distance} is a metric that takes into account the correlations between variables when measuring the distance between two vectors. In our recommendation system, we can leverage Mahalanobis distance to quantify the dissimilarity between the embedding vectors of items or users. By considering the correlations within the embedding dimensions, Mahalanobis distance provides a more accurate measure of dissimilarity. It helps identify items or users that are dissimilar based on their characteristics or preferences, accounting for the relationships between different features.
-
-\paragraph{Euclidean distance} is a widely used metric to calculate the straight-line distance between two points in a multi-dimensional space. In our use case, we can apply Euclidean distance to measure the dissimilarity between the embedding vectors of items or users. By comparing the corresponding dimensions of the vectors and calculating the square root of the sum of squared differences, Euclidean distance provides a simple and intuitive measure of dissimilarity. It helps identify items or users that are relatively far apart in terms of their characteristics or preferences, based on the geometric distance in the embedding space.
-
-%\subsubsection{Cosine similarity input}
-%TUTAJ MA BYĆ INNY TEKST A NIE KNN
-
-\paragraph{KNN} is a machine learning algorithm that we will use to find the K most similar users to a target user in the similarity matrix. The K most similar users will be our nearest neighbors, and we will use their ratings to generate recommendations for the target user. The number of nearest neighbors (K) that we choose will depend on the performance of our recommendation system on the validation set. We will experiment with different values of K and different weighting schemes for the ratings of the nearest neighbors to optimize the performance of our recommendation system. \\
-
-%\paragraph{Euclidean distance} measures distance between two points in a straight line. It is used to measure similarity between points. Points that are closer to each other are considered to be similar. We can use it for finding nearest neighbors and clusters.
-
-%\paragraph{Mahalonobis distance} again measures distance between two points but this time it takes into consideration how different elements of data-set relate to each other. This should be an advantage over Euclidean distance which assumes that all inputs are independent of each other.
-\subsection{Data used for recommendation}
-In addition to users and their rating for anime, we will also use measures of:
-\begin{itemize}
-\item Controversy - Anime with lots of ’1’ and ’10 might have the exact same rating as anime with mostly ’6’ but it is much more
-controversial (hit or miss) and it can be a good recommendation even though its rating might seem low
-\item Combined data about popularity - Number of favorites, number of members which are in the group for fans of a given anime and overall popularity on the site
-\item Ranked - How good the anime is in comparison with other anime's on the site
-\end{itemize}
-
-
-
-
-%Collaborative filtering is a technique that recommends items based on the preferences of similar users or items. \\
-%In our case, we will use the item-based collaborative filtering approach where we will recommend anime's based on their similarity to the input anime. \\
-%Our model will use the cosine similarity metric to measure the similarity between anime's. \\
-%We will also use a neighborhood-based approach to find the most similar anime's. \\
-%Specifically, we will use the K-nearest neighbors (KNN) algorithm to identify the most similar anime's to the input anime.
-
-\section{Selection and description of the data-sets}
-The quality and size of the dataset may greatly affect the performance of the collaborative filtering algorithm. This is why we decided to choose a dataset that was newer and bigger than the one provided in the task.
-We will be using the Anime Recommendations Database from Kaggle \href{https://www.kaggle.com/datasets/hernan4444/anime-recommendation-database-2020}{LINK}. The data-set contains information about over 17,000 anime's and over 300,000 users. \\
-\subsection{Why this data set}
-There are multiple reasons to use this specific data set over different ones available on Kaggle (including the one proposed in task description) \\
-\begin{itemize}
-\item It is considered to have 100 \% usability by Kaggle
-\begin{itemize}
-\item It is tagged, has subtitle, description and cover image
-\item It has a source, is public and was updated recently (2020)
-\item It has the most permissive (CC0) license, good file format, and all files and columns are described
-\end{itemize}
-\item It is one of the biggest anime databases on kaggle (605 MB)
-\item It has over 60 code examples of use
-\end{itemize}
-\subsection{Data-set description}
-
-The data-set contains:
-\begin{itemize}
- \item The anime list per user (dropped, complete, plan to watch, currently watching and on hold)
- \item Ratings given by users to the anime's that they has watched completely.
- \item Information about anime (exactly 35 columns!), most importantly:
- \begin{itemize}
- \item Name
- \item User score
- \item Popularity
- \item Members
- \item Favourites
- \item Number of each particular score (from 1 to 10)
- \end{itemize}
- \item HTML files containing reviews, synopsis, staff info etc.
-\end{itemize}
-There are 5 csv files in total and one HTML folder
-\subsection{anime.csv}
-It contains information about all anime scraped \\
-In total it contains \textbf{35} columns \\
-Information's that might be in our opinion use-full and are not contained within rest of the files are:
-Information's that might be use full for our algorithm:
-\begin{itemize}
-\item Number of episodes - Some users might prefer shorter/longer anime's
-\item When it was aired - Some users might prefer older/newer anime styled
-\item When it was premiered - Same as above
-\item Studios - Some users might favourite specific Studios style
-\item Duration - Some users might prefer anime's with shorter single episode length
-\item Ranked - Anime that might not be a hit with a certain user but is still considered to be very good can still be a good recommendation
-\item Popularity - Anime that might not be a hit with a certain user but is very popular can still be a good recommendation
-\item Members - Same as above
-\item Favorites - Same as above
-\item Number of exact amount of scores from 1 to 10 - This can tell how "controversial" the anime is, anime with lots of '1' and '10 might have the exact same rating as anime with mostly '6' but it is much more controversial (hit or miss)
-\end{itemize}
-
-In formations that might be use-full to display:
-\begin{itemize}
-\item Type - Usually whether it is a series (TV or OVA) or movie
-\item Number of episodes - How much time does it take to watch it
-\item When it was aired - Start of anime being shown and end of it
-\item When it was premiered - When the anime started
-\item Studios - What studio produced it
-\item Duration - How much time does it take to watch single episode
-\item Ranked - How good it is in relation to all other anime's on my anime list
-\end{itemize}
-\subsection{anime\_with\_synopsis.csv}
-CSV file containing anime info for humans \\
-It contains 5 columns:
-\begin{itemize}
- \item (key) mal\_id - used to identify the anime
- \item name - either English or R\=omaji version of the title
- \item score - average anime score
- \item genres - list of genres associated with this anime
- \item synopsis - description of anime
-\end{itemize}
-This file will be use-full for displaying the recommendation to user with additional info
-\subsection{animelist.csv}
-This file contains information about all users anime lists, no matter their watching status \\
-In total it contains over 105 million rows \\
-There are over 60 million ratings given by users (compared with over 55 for only completed series)
-It contains 5 columns:
-\begin{itemize}
- \item (key) user\_id - random (but persistent through database) user id
- \item (key) anime\_id - used to identify the anime
- \item rating - what score this user set for this anime (zero is set if user did not set any score)
- \item watching\_status - state ID for this anime in the anime list of the user (see \ref{watchingStatus} watching\_status.csv)
- \item watched\_episodes - how many episodes have been watched by the user
-\end{itemize}
-This file can be potentially use full especially to determine what users with similar interest are planning to watch
-\subsection{rating\_complete.csv}
-This file contains information about all ratings given to animes by users who selected watching\_status 2 option (complete) \\
-In total it contains over 55 million ratings \\
-It contains 3 columns:
-\begin{itemize}
- \item (key) user\_id - random (but persistent through database) user id
- \item (key) anime\_id - used to identify the anime
- \item rating - what score this user set for this anime (1-10 scale)
-\end{itemize}
-This is probably the most important file regarding our project
-\subsection{watching\_status.csv}
-\label{watchingStatus}
-\begin{figure}[h]
-\caption{Entire contents of watching\_status.csv file}
-\centering
-\begin{tabular}{| c | c |}
-\hline
-status & description \\
-\hline
-1 & Currently Watching \\
-\hline
-2 & Completed \\
-\hline
-3 & On Hold \\
-\hline
-4 & Dropped \\
-\hline
-6 & Plan to Watch \\
-\hline
-\end{tabular}
-\end{figure}
-
-Watching status file is used to relate numerical id of watching status to actual textual description of this status \\
-Status number 5 is missing, possibly referring to "re-watching" status? \\
-Meaning of particular descriptions:
-\begin{itemize}
- \item Currently Watching - Actively keeping up with the series
- \item Completed - Watched the entire series/film
- \item On Hold - Stopped watching it but possibly wanting to return to it
- \item Dropped - Stopped watching it and decided not to return it
- \item Plan to Watch - Not watched it yet but plan to
-\end{itemize}
-For most purposes we will be only interested in status 2 (completed) which tells us that the user checked the anime as already watched \\
-Plan to watch is also interesting since it can be used to recommend anime based on what similar users are interested in
-\subsection{HTML folder}
-HTML folder contains HTML scraped info about specific anime's, we will ignore this folder as parsing HTML is a much bigger challenge and outside of the scope of our project
-\subsection{Summary}
-There are two most important files, for program inner workings: rating\_complete.csv and anime\_with\_synopsis.csv for showing the recommended anime to user
-
-\section{General plan of tests/experiments}
-
-To evaluate and compare the performance of our collaborative filtering model with different parameter configurations, we will use grid search and 5-fold cross-validation.
-
-Grid search will allow us to systematically test different combinations of hyperparameters, such as the number of nearest neighbors in KNN and the regularization strength in the matrix factorization algorithm, to find the best combination that maximizes the model's performance.
-
-Cross-validation will help us to estimate the model's generalization performance and reduce the risk of overfitting to the training data.
-% Notka dla nas: Hyperparameters: Parameters that are set before training a machine learning model and cannot be learned from the data. Examples of hyperparameters include the learning rate, the number of hidden layers in a neural network, and the regularization strength.
-% Notka dla nas: Overfitting is a common problem in machine learning where a model is trained too well on the training data and performs poorly on the testing or validation data. In other words, the model learns the patterns and noise in the training data to such a degree that it loses the ability to generalize and predict accurately on new data.
-
-To measure the quality of our model's recommendations, we will use precision, recall, and F1-score metrics. Precision measures the proportion of relevant items among the recommended items, recall measures the proportion of relevant items that are recommended, and F1-score is the harmonic mean of precision and recall, providing a balanced measure of the model's performance. We will compute these metrics on the test set and report the average scores across the 5-fold cross-validation.
-
-%Our main goal is to evaluate the performance of the recommendation model. We will perform a 5-fold cross-validation to estimate the generalization performance of the model. We will also use precision, recall, and F1-score metrics to evaluate the model's performance. We will experiment with different values of K (number of neighbors) to find the optimal value.
-
-\section{Methods of result visualization}
-
-For the visualization, we chose three methods:
-\begin{itemize}
-\item Heatmaps: They are useful for visualizing the similarity between users or animes based on their ratings. They will allow us to identify clusters of similar users or animes and explore how their preferences are related to one another.
-
-% https://rpubs.com/jeknov/movieRec
-\begin{figure}
-\centering
- \caption{An exemplary heatmap}
- \label{fig:heatmap}
-\end{figure}
-
-\item Histograms: They will be used to visualize the distribution of ratings and identifying any biases or patterns in the data. They can help us identify whether the ratings are normally distributed or skewed.
-
-\begin{figure}
-\centering
- \caption{An exemplary histogram}
- \label{fig:precission-recall}
-\end{figure}
-
-\item Precision-recall curves: They show the tradeoff between precision and recall at different thresholds, allowing us to identify the optimal threshold for making recommendations. By visualizing the performance of the algorithm in this way, we can identify areas for improvement and generate new hypotheses for increasing the accuracy of the recommendations.
-\end{itemize}
-
-\begin{figure}
-\centering
- \caption{An exemplary precision-recall graph}
- \label{fig:histogram}
-\end{figure}
-
-\section{Definition of quality measures that will be used}
-In order to evaluate the quality of our recommendation system, we will use a combination of precision, recall, F1 score, and MAP. Precision measures the proportion of relevant items among the recommended items, while recall measures the proportion of relevant items that were actually recommended. F1 score is the harmonic mean of precision and recall, providing a balanced measure of the system's performance.
-
-MAP is calculated by taking the average of the average precision (AP) for each user. AP is calculated as the mean of the precision values obtained at each relevant item position in the ranked list of recommended items.
-
-To calculate MAP, we need to define a threshold for relevance, which can be either binary (relevant or not relevant) or graded (assigning a relevance score to each anime). In our case, we will use a binary threshold, where an anime is considered relevant if has been rated 8 or higher. We will also calculate MAP for different values of K (number of recommended items), as the quality of the recommendations may vary depending on the number of items displayed to the user.
-
-%Quality Measures:
-
-%We will use the following quality measures to evaluate the performance of the model:
-
-% Precision: the ratio of true positive predictions to the total number of predicted positives.
-% Recall: the ratio of true positive predictions to the total number of actual positives.
-% F1-score: the harmonic mean of precision and recall.
-
-%We will also use the mean average precision (MAP) as an additional quality measure to evaluate the model's performance.
-
-
+ \input{sections/01-algorithm-description-and-examples}
+ \input{sections/02-selection-and-description-of-the-data}
+ \input{sections/03-general-plan-of-tests-experiments}
+ \input{sections/04-methods-of-result-visualization}
+ \input{sections/05-definition-of-quality-measures-that-will}
\end{document}
diff --git a/Programming/EARIN/project/preliminary/sections/01-algorithm-description-and-examples.tex b/Programming/EARIN/project/preliminary/sections/01-algorithm-description-and-examples.tex
new file mode 100644
index 00000000..c6a3b227
--- /dev/null
+++ b/Programming/EARIN/project/preliminary/sections/01-algorithm-description-and-examples.tex
@@ -0,0 +1,69 @@
+\section{Algorithm description and examples}
+
+We will be using the collaborative filtering approach to develop our model. \\
+Collaborative filtering is a popular method for making personalized recommendations based on the preferences of other users with similar tastes. In this approach, the recommendation system analyzes a large data-set of user-item ratings to identify patterns and similarities between users and anime's, and uses this information to make recommendations to new users.
+
+We will represent users and anime's data-sets as embedding vectors. Embeddings provide a way to transform high-dimensional data into a lower-dimensional space while preserving relevant relationships.
+
+We have decided to use and test multiple metrics such as
+\begin{itemize}
+ \item Cosine similarity
+ \item Mahalanobis Distance
+ \item Euclidean Distance
+\end{itemize}
+together with K-nearest neighbors algorithm. \\
+
+\subsection{Embedding users and anime}
+In order to embed users and anime we must choose which features of the user/anime are the most important for our model \\
+For the user we are restricted to what database offers, database pretty much only offers us what ratings the user gave to an anime, we will compare the performance of our algorithm when:
+\begin{itemize}
+\item Given ratings of the user for all anime that they gave rating to (no matter the watching status)
+\item Given ratings of the user for all anime that they have \emph{completed}
+\end{itemize}
+
+For anime we will use data:
+\begin{itemize}
+ \item User score
+ \item Popularity (this includes popularity itself, number of members and favourites)
+ \item Controversy (Whether the anime gets a lot of 1s and 10s or just 6s)
+\end{itemize}
+
+We have decided to use two different methods to combine data and compare the results \\
+First method is dot product which gives a single number after multiplying two vectors \\
+The second is concatenation which returns a new vector combining first and second vector \\
+As an input for all our metrics (like cosine similarity) we will use vectors of anime and users
+
+
+\subsection{Metrics}
+%\emph{Cosine similarity} is a metric used to compute the similarity between two users based on their ratings or preferences for anime. In our case, we will use cosine similarity to compute the similarity between each pair of users in our data-set based on their anime ratings. This will result in a similarity matrix, where each entry (i,j) represents the cosine similarity between users i and j.
+\paragraph{Cosine similarity} is a measure used to calculate the similarity between two vectors representing items or users. It evaluates the cosine of the angle between the two vectors, indicating their directional similarity. In our use case, cosine similarity can help identify items or users with similar preferences or characteristics by comparing their embedding vectors. Higher cosine similarity values (closer to 1) indicate a stronger similarity between the vectors, suggesting that the items or users are more likely to have similar features or preferences.
+\paragraph{Mahalanobis distance} is a metric that takes into account the correlations between variables when measuring the distance between two vectors. In our recommendation system, we can leverage Mahalanobis distance to quantify the dissimilarity between the embedding vectors of items or users. By considering the correlations within the embedding dimensions, Mahalanobis distance provides a more accurate measure of dissimilarity. It helps identify items or users that are dissimilar based on their characteristics or preferences, accounting for the relationships between different features.
+
+\paragraph{Euclidean distance} is a widely used metric to calculate the straight-line distance between two points in a multi-dimensional space. In our use case, we can apply Euclidean distance to measure the dissimilarity between the embedding vectors of items or users. By comparing the corresponding dimensions of the vectors and calculating the square root of the sum of squared differences, Euclidean distance provides a simple and intuitive measure of dissimilarity. It helps identify items or users that are relatively far apart in terms of their characteristics or preferences, based on the geometric distance in the embedding space.
+
+%\subsubsection{Cosine similarity input}
+%TUTAJ MA BYĆ INNY TEKST A NIE KNN
+
+\paragraph{KNN} is a machine learning algorithm that we will use to find the K most similar users to a target user in the similarity matrix. The K most similar users will be our nearest neighbors, and we will use their ratings to generate recommendations for the target user. The number of nearest neighbors (K) that we choose will depend on the performance of our recommendation system on the validation set. We will experiment with different values of K and different weighting schemes for the ratings of the nearest neighbors to optimize the performance of our recommendation system. \\
+
+%\paragraph{Euclidean distance} measures distance between two points in a straight line. It is used to measure similarity between points. Points that are closer to each other are considered to be similar. We can use it for finding nearest neighbors and clusters.
+
+%\paragraph{Mahalonobis distance} again measures distance between two points but this time it takes into consideration how different elements of data-set relate to each other. This should be an advantage over Euclidean distance which assumes that all inputs are independent of each other.
+\subsection{Data used for recommendation}
+In addition to users and their rating for anime, we will also use measures of:
+\begin{itemize}
+\item Controversy - Anime with lots of ’1’ and ’10 might have the exact same rating as anime with mostly ’6’ but it is much more
+controversial (hit or miss) and it can be a good recommendation even though its rating might seem low
+\item Combined data about popularity - Number of favorites, number of members which are in the group for fans of a given anime and overall popularity on the site
+\item Ranked - How good the anime is in comparison with other anime's on the site
+\end{itemize}
+
+
+
+
+%Collaborative filtering is a technique that recommends items based on the preferences of similar users or items. \\
+%In our case, we will use the item-based collaborative filtering approach where we will recommend anime's based on their similarity to the input anime. \\
+%Our model will use the cosine similarity metric to measure the similarity between anime's. \\
+%We will also use a neighborhood-based approach to find the most similar anime's. \\
+%Specifically, we will use the K-nearest neighbors (KNN) algorithm to identify the most similar anime's to the input anime.
+
diff --git a/Programming/EARIN/project/preliminary/sections/02-selection-and-description-of-the-data.tex b/Programming/EARIN/project/preliminary/sections/02-selection-and-description-of-the-data.tex
new file mode 100644
index 00000000..24c9c0f1
--- /dev/null
+++ b/Programming/EARIN/project/preliminary/sections/02-selection-and-description-of-the-data.tex
@@ -0,0 +1,134 @@
+\section{Selection and description of the data-sets}
+The quality and size of the dataset may greatly affect the performance of the collaborative filtering algorithm. This is why we decided to choose a dataset that was newer and bigger than the one provided in the task.
+We will be using the Anime Recommendations Database from Kaggle \href{https://www.kaggle.com/datasets/hernan4444/anime-recommendation-database-2020}{LINK}. The data-set contains information about over 17,000 anime's and over 300,000 users. \\
+\subsection{Why this data set}
+There are multiple reasons to use this specific data set over different ones available on Kaggle (including the one proposed in task description) \\
+\begin{itemize}
+\item It is considered to have 100 \% usability by Kaggle
+\begin{itemize}
+\item It is tagged, has subtitle, description and cover image
+\item It has a source, is public and was updated recently (2020)
+\item It has the most permissive (CC0) license, good file format, and all files and columns are described
+\end{itemize}
+\item It is one of the biggest anime databases on kaggle (605 MB)
+\item It has over 60 code examples of use
+\end{itemize}
+\subsection{Data-set description}
+
+The data-set contains:
+\begin{itemize}
+ \item The anime list per user (dropped, complete, plan to watch, currently watching and on hold)
+ \item Ratings given by users to the anime's that they has watched completely.
+ \item Information about anime (exactly 35 columns!), most importantly:
+ \begin{itemize}
+ \item Name
+ \item User score
+ \item Popularity
+ \item Members
+ \item Favourites
+ \item Number of each particular score (from 1 to 10)
+ \end{itemize}
+ \item HTML files containing reviews, synopsis, staff info etc.
+\end{itemize}
+There are 5 csv files in total and one HTML folder
+\subsection{anime.csv}
+It contains information about all anime scraped \\
+In total it contains \textbf{35} columns \\
+Information's that might be in our opinion use-full and are not contained within rest of the files are:
+Information's that might be use full for our algorithm:
+\begin{itemize}
+\item Number of episodes - Some users might prefer shorter/longer anime's
+\item When it was aired - Some users might prefer older/newer anime styled
+\item When it was premiered - Same as above
+\item Studios - Some users might favourite specific Studios style
+\item Duration - Some users might prefer anime's with shorter single episode length
+\item Ranked - Anime that might not be a hit with a certain user but is still considered to be very good can still be a good recommendation
+\item Popularity - Anime that might not be a hit with a certain user but is very popular can still be a good recommendation
+\item Members - Same as above
+\item Favorites - Same as above
+\item Number of exact amount of scores from 1 to 10 - This can tell how "controversial" the anime is, anime with lots of '1' and '10 might have the exact same rating as anime with mostly '6' but it is much more controversial (hit or miss)
+\end{itemize}
+
+In formations that might be use-full to display:
+\begin{itemize}
+\item Type - Usually whether it is a series (TV or OVA) or movie
+\item Number of episodes - How much time does it take to watch it
+\item When it was aired - Start of anime being shown and end of it
+\item When it was premiered - When the anime started
+\item Studios - What studio produced it
+\item Duration - How much time does it take to watch single episode
+\item Ranked - How good it is in relation to all other anime's on my anime list
+\end{itemize}
+\subsection{anime\_with\_synopsis.csv}
+CSV file containing anime info for humans \\
+It contains 5 columns:
+\begin{itemize}
+ \item (key) mal\_id - used to identify the anime
+ \item name - either English or R\=omaji version of the title
+ \item score - average anime score
+ \item genres - list of genres associated with this anime
+ \item synopsis - description of anime
+\end{itemize}
+This file will be use-full for displaying the recommendation to user with additional info
+\subsection{animelist.csv}
+This file contains information about all users anime lists, no matter their watching status \\
+In total it contains over 105 million rows \\
+There are over 60 million ratings given by users (compared with over 55 for only completed series)
+It contains 5 columns:
+\begin{itemize}
+ \item (key) user\_id - random (but persistent through database) user id
+ \item (key) anime\_id - used to identify the anime
+ \item rating - what score this user set for this anime (zero is set if user did not set any score)
+ \item watching\_status - state ID for this anime in the anime list of the user (see \ref{watchingStatus} watching\_status.csv)
+ \item watched\_episodes - how many episodes have been watched by the user
+\end{itemize}
+This file can be potentially use full especially to determine what users with similar interest are planning to watch
+\subsection{rating\_complete.csv}
+This file contains information about all ratings given to animes by users who selected watching\_status 2 option (complete) \\
+In total it contains over 55 million ratings \\
+It contains 3 columns:
+\begin{itemize}
+ \item (key) user\_id - random (but persistent through database) user id
+ \item (key) anime\_id - used to identify the anime
+ \item rating - what score this user set for this anime (1-10 scale)
+\end{itemize}
+This is probably the most important file regarding our project
+\subsection{watching\_status.csv}
+\label{watchingStatus}
+\begin{figure}[h]
+\caption{Entire contents of watching\_status.csv file}
+\centering
+\begin{tabular}{| c | c |}
+\hline
+status & description \\
+\hline
+1 & Currently Watching \\
+\hline
+2 & Completed \\
+\hline
+3 & On Hold \\
+\hline
+4 & Dropped \\
+\hline
+6 & Plan to Watch \\
+\hline
+\end{tabular}
+\end{figure}
+
+Watching status file is used to relate numerical id of watching status to actual textual description of this status \\
+Status number 5 is missing, possibly referring to "re-watching" status? \\
+Meaning of particular descriptions:
+\begin{itemize}
+ \item Currently Watching - Actively keeping up with the series
+ \item Completed - Watched the entire series/film
+ \item On Hold - Stopped watching it but possibly wanting to return to it
+ \item Dropped - Stopped watching it and decided not to return it
+ \item Plan to Watch - Not watched it yet but plan to
+\end{itemize}
+For most purposes we will be only interested in status 2 (completed) which tells us that the user checked the anime as already watched \\
+Plan to watch is also interesting since it can be used to recommend anime based on what similar users are interested in
+\subsection{HTML folder}
+HTML folder contains HTML scraped info about specific anime's, we will ignore this folder as parsing HTML is a much bigger challenge and outside of the scope of our project
+\subsection{Summary}
+There are two most important files, for program inner workings: rating\_complete.csv and anime\_with\_synopsis.csv for showing the recommended anime to user
+
diff --git a/Programming/EARIN/project/preliminary/sections/03-general-plan-of-tests-experiments.tex b/Programming/EARIN/project/preliminary/sections/03-general-plan-of-tests-experiments.tex
new file mode 100644
index 00000000..af1c5c68
--- /dev/null
+++ b/Programming/EARIN/project/preliminary/sections/03-general-plan-of-tests-experiments.tex
@@ -0,0 +1,14 @@
+\section{General plan of tests/experiments}
+
+To evaluate and compare the performance of our collaborative filtering model with different parameter configurations, we will use grid search and 5-fold cross-validation.
+
+Grid search will allow us to systematically test different combinations of hyperparameters, such as the number of nearest neighbors in KNN and the regularization strength in the matrix factorization algorithm, to find the best combination that maximizes the model's performance.
+
+Cross-validation will help us to estimate the model's generalization performance and reduce the risk of overfitting to the training data.
+% Notka dla nas: Hyperparameters: Parameters that are set before training a machine learning model and cannot be learned from the data. Examples of hyperparameters include the learning rate, the number of hidden layers in a neural network, and the regularization strength.
+% Notka dla nas: Overfitting is a common problem in machine learning where a model is trained too well on the training data and performs poorly on the testing or validation data. In other words, the model learns the patterns and noise in the training data to such a degree that it loses the ability to generalize and predict accurately on new data.
+
+To measure the quality of our model's recommendations, we will use precision, recall, and F1-score metrics. Precision measures the proportion of relevant items among the recommended items, recall measures the proportion of relevant items that are recommended, and F1-score is the harmonic mean of precision and recall, providing a balanced measure of the model's performance. We will compute these metrics on the test set and report the average scores across the 5-fold cross-validation.
+
+%Our main goal is to evaluate the performance of the recommendation model. We will perform a 5-fold cross-validation to estimate the generalization performance of the model. We will also use precision, recall, and F1-score metrics to evaluate the model's performance. We will experiment with different values of K (number of neighbors) to find the optimal value.
+
diff --git a/Programming/EARIN/project/preliminary/sections/04-methods-of-result-visualization.tex b/Programming/EARIN/project/preliminary/sections/04-methods-of-result-visualization.tex
new file mode 100644
index 00000000..81f63483
--- /dev/null
+++ b/Programming/EARIN/project/preliminary/sections/04-methods-of-result-visualization.tex
@@ -0,0 +1,30 @@
+\section{Methods of result visualization}
+
+For the visualization, we chose three methods:
+\begin{itemize}
+\item Heatmaps: They are useful for visualizing the similarity between users or animes based on their ratings. They will allow us to identify clusters of similar users or animes and explore how their preferences are related to one another.
+
+% https://rpubs.com/jeknov/movieRec
+\begin{figure}
+\centering
+ \caption{An exemplary heatmap}
+ \label{fig:heatmap}
+\end{figure}
+
+\item Histograms: They will be used to visualize the distribution of ratings and identifying any biases or patterns in the data. They can help us identify whether the ratings are normally distributed or skewed.
+
+\begin{figure}
+\centering
+ \caption{An exemplary histogram}
+ \label{fig:precission-recall}
+\end{figure}
+
+\item Precision-recall curves: They show the tradeoff between precision and recall at different thresholds, allowing us to identify the optimal threshold for making recommendations. By visualizing the performance of the algorithm in this way, we can identify areas for improvement and generate new hypotheses for increasing the accuracy of the recommendations.
+\end{itemize}
+
+\begin{figure}
+\centering
+ \caption{An exemplary precision-recall graph}
+ \label{fig:histogram}
+\end{figure}
+
diff --git a/Programming/EARIN/project/preliminary/sections/05-definition-of-quality-measures-that-will.tex b/Programming/EARIN/project/preliminary/sections/05-definition-of-quality-measures-that-will.tex
new file mode 100644
index 00000000..0016e59b
--- /dev/null
+++ b/Programming/EARIN/project/preliminary/sections/05-definition-of-quality-measures-that-will.tex
@@ -0,0 +1,18 @@
+\section{Definition of quality measures that will be used}
+In order to evaluate the quality of our recommendation system, we will use a combination of precision, recall, F1 score, and MAP. Precision measures the proportion of relevant items among the recommended items, while recall measures the proportion of relevant items that were actually recommended. F1 score is the harmonic mean of precision and recall, providing a balanced measure of the system's performance.
+
+MAP is calculated by taking the average of the average precision (AP) for each user. AP is calculated as the mean of the precision values obtained at each relevant item position in the ranked list of recommended items.
+
+To calculate MAP, we need to define a threshold for relevance, which can be either binary (relevant or not relevant) or graded (assigning a relevance score to each anime). In our case, we will use a binary threshold, where an anime is considered relevant if has been rated 8 or higher. We will also calculate MAP for different values of K (number of recommended items), as the quality of the recommendations may vary depending on the number of items displayed to the user.
+
+%Quality Measures:
+
+%We will use the following quality measures to evaluate the performance of the model:
+
+% Precision: the ratio of true positive predictions to the total number of predicted positives.
+% Recall: the ratio of true positive predictions to the total number of actual positives.
+% F1-score: the harmonic mean of precision and recall.
+
+%We will also use the mean average precision (MAP) as an additional quality measure to evaluate the model's performance.
+
+
diff --git a/Programming/ECOTE/finalReport/Krzysztof_Rudnicki_38Final.tex b/Programming/ECOTE/finalReport/Krzysztof_Rudnicki_38Final.tex
index 1a9cbe9c..794911af 100644
--- a/Programming/ECOTE/finalReport/Krzysztof_Rudnicki_38Final.tex
+++ b/Programming/ECOTE/finalReport/Krzysztof_Rudnicki_38Final.tex
@@ -18,410 +18,9 @@ Semester: 2023L}
\begin{document}
\maketitle
-\section{General overview and assumptions}
-My task was to create a translator of \LaTeX \, subset to selected text format with focus on \LaTeX \, tables \\
-I decided to change to translator of \LaTeX \, subset to HTML since I know \LaTeX \, very well and HTML relatively well, I decide to translate \LaTeX into HTML since HTML is easy, a little bit different than \LaTeX and popular which makes this translator a practical tool.
-\subsection{Assumptions}
-\begin{itemize}
- \item "Tables" will be represented using \LaTeX \, \emph{table} environment
- \item All changes influenced by different \LaTeX \, document class are ignored in html
- \item Everything between documentclass and begin document is ignored when generating html
- \item Program tries to generate final html even if encountering errors which would make final html not complete
- \item Only commands defined in \LaTeX \, subset are translated, rest is translated literally as raw text to html
-\end{itemize}
-\section{Functional requirements}
-The goal of the project is to transform .tex file to (working ) .html file if the subset of .tex file is within project scope or output error message explaining why the html could not be outputed
-\subsection{\LaTeX \, subset}
-This project will focus almost exclusively on \emph{tabular} environment \\
-\begin{itemize}
- \item $\backslash$documentclass\{class\}: Defines what layout standard \LaTeX will use
- \item $\backslash$begin\{document\}: Ends (in our case empty) preamble
- \item $\backslash$end\{document\}: Ends \LaTeX \, document
- \item $\backslash$begin\{tabular\}[pos]\{table spec\}: Opens environment used to typeset tables
- \item $\backslash$end\{tabular\}: Closes environment used to typeset tables
-\end{itemize}
-Supported tabular arguments:
-\begin{itemize}
- \item l, c, r - respectively left-justified, centered and right-justified column
- \item | - single vertical line
- \item || - double vertical line
- \item p\{'width'\} - paragraph column (that wraps), aligned at the top
- \item m\{'width'\} - paragraph column (that wraps), aligned at the middle
- \item b\{'width'\} - paragraph column (that wraps), aligned at the bottom
-\end{itemize}
-
-Supported commands inside tabular environment
-\begin{itemize}
- \item \& - separate columns
- \item $\backslash$$\backslash$ - start new row
- \item $\backslash$hline - horizontal line
- \item $\backslash$cline\{i-j\} horizontal line beginning in column i and ending in column j
- \item $\backslash$newline - new line \emph{inside} the cell
-\end{itemize}
-\section{Implementation}
-I decided to use Python as a language in which I will implement my solution \\
-The reasons for using python are as follow:
-\begin{enumerate}
- \item It is the easiest language among those that I know
- \item I know it enough to be confident in my ability to implement this solution in python
- \item I want to learn python more through this project
-\end{enumerate}
-Negative aspects of python which is that it is very slow language do not bother me as I believe the project scope will not be big enough for this to become an issue
-
-\subsection{General architecture}
-\begin{tabular}{|l|p{10cm}|}
- \hline
- Module & Description \\
- \hline
- Main & Handles texfile, puts it to a function translating to html and saves output html file \\
- \hline
- FileHandler & Handles reading latex file and transforming it to string in python \\
- \hline
- ReadStart & Checks documentclass and begin document functions of latex file and if they are correct outputs starting html tags \\
- \hline
- HandleInside & Goes through inside of LaTeX document and transforms each of its part to HTML
- \\
- \hline
- HandleTable & Reads table, including table parameters and actual contents and transforms it to html \\
- \hline
- TabInsideHandler & Handles actual content of table and translates them to html \\
-\end{tabular}
-
-
-
-
-
-
-\subsection{Data structures}
-\begin{itemize}
-\item File entered by user is represented by python File class
-\item Parsed \LaTeX \, code is represented by data structure based on node classes
-\item Tabular environment parameters are stored in an array, if the parameter contains additional optional parameters they are stored in a pair of the parent argument and array of all optional arguments
-\item Generated HTML code is stored in node classes
-\item Final HTML code is stored in plain text and then written to File
-\end{itemize}
-
-\subsection{Module descriptions}
-\subsubsection{Main}
-Puts latex filename to filehandler, sends retrieved string to function translating tex to html and then saves final html file
-\subsubsection{FileHandler}
-Handles texfile and transforms it to python string \\
-Input: \\
-tex\_filename - LaTeX file filename \\
-Functions:
-\begin{itemize}
- \item Handle arguments - Checks if arguments are correct, reads file and saves it to python string
- \item Invoke Latex Handler - Sends file from file handler to LatexHandler
-\end{itemize}
-\subsubsection{LatexHandler}
-Transforms tex string to html
-Input: tex string
-Functions:
-\begin{itemize}
- \item ReadStart - Checks begininig of tex file and returns html code if the begining is correct
- \item HandleInside - Handles insides of tex file, both tables and loose text and translates it to html
-\end{itemize}
-\subsubsection{ReadStart}
-Checks begininig of tex file and returns html code if the begining is correct \\
-Input: tex string \\
-Output: html\_string
-
-\begin{itemize}
-\item read\_document\_class - Checks if document class exists and is written according to tex rules, returns if yes
-\item read\_begin\_document - (optional) Checks if begin\{document\} function was written in tex file if yes adds to html\_string
-\item HandleInside - Passes parsed tex data and html\_string to function handling inside of tex document
-\end{itemize}
-
-\subsubsection{HandleInside}
-Translates tex string starting at begin document and ending at end document, returns final html\_string \\
-Parameters: \\
-\begin{itemize}
-\item tex\_data - String read from tex file
-\item html\_string - Final output string to which table data and loose text will be added
-\end{itemize}
-Functions:
-\begin{itemize}
- \item HandleTable - Converts tex tables to html tables
- \item HandleLoose - Goes through text that is not in table and converts it to html
-\end{itemize}
-
-\subsubsection{HandleTable}
-Converts tex tables to html tables \\
-Parameters: \\
-\begin{itemize}
-\item tex\_data - String read from tex file
-\item html\_string - Final output string to which table data and loose text will be added
-\end{itemize}
-Functions:
-\begin{itemize}
- \item TabArgHandler - Reads tex table parameters and translates them to html style
- \item TabInsideHandler - Reads inside of tex table and together with parse parameters outputs correct table layout and look
-\end{itemize}
-
-\subsubsection{TabInsideHandler}
-Together with html table parameters translates inside of tex table to html \\
-Parameters: \\
-\begin{itemize}
-\item TableContents - Latex string containing only inside of table
-\end{itemize}
-Functions:
-\begin{itemize}
- \item ReadTableContent - Parses table content and checks for errors
- \item ConvertToHTML - Converts table inside to html
-\end{itemize}
-
-\subsubsection{TabArgHandler}
-Reads tex table parameters and translates them to html style \\
-Parameters: \\
-\begin{itemize}
-\item TableArguments - Arguments provided with $\backslash$begin\{tabular\} environment
-\end{itemize}
-Functions:
-\begin{itemize}
- \item ReadTableARguments - Parses table arguments and checks for errors
- \item ConvertToHTML - Converts table arguments to html style
-\end{itemize}
-
-\subsection{Input/output description}
-Input is a .tex file (\LaTeX \, file) \\
-Outpus is an .html file \\
-In case of errors error message will be outputed on the terminal \\
-Input File path is entered as an argument to terminal with "-i" or "--input" flag for example:
-\begin{lstlisting}[language=bash]
-python main.py -i texFile.tex
-\end{lstlisting}
-Output file path can be named by user by using "-o" or "--output" flag:
-\begin{lstlisting}[language=bash]
-python main.py -i texFile.tex -o htmlFile.html
-\end{lstlisting}
-If no "-o" flag is issued the output file will have the same name as input file with changed extension to html (so in this example texFile.tex will become texFile.html) \\
-If the path to file name consists of spaces, path name needs to be but in ""
-\begin{lstlisting}[language=bash]
-python main.py -i "My Folder/input.tex"
-\end{lstlisting}
-\subsection{Others}
-\section{Unit tests}
-There are over 12 unit tests for program functions, all of them can be ran by using python test environment:
-\begin{lstlisting}
-python -m pytest unit_tests
-
-collected 12 items
-
-unit_tests/test_code/test_begin_document.py . [ 8%]
-unit_tests/test_code/test_begin_tabular.py . [ 16%]
-unit_tests/test_code/test_document_class.py . [ 25%]
-unit_tests/test_code/test_length_conversions.py . [ 33%]
-unit_tests/test_code/test_only_pipes_and_space.py . [ 41%]
-unit_tests/test_code/test_split_columns.py . [ 50%]
-unit_tests/test_code/test_split_rows.py . [ 58%]
-unit_tests/test_code/test_tabular_columns_parameters.py . [ 66%]
-unit_tests/test_code/test_tabular_parameters.py . [ 75%]
-unit_tests/test_code/test_tabular_required_parameters.py . [ 83%]
-unit_tests/test_code/test_translate_column.py . [ 91%]
-unit_tests/test_code/test_translate_inside_to_html.py . [100%]
-
-===================================================== 12 passed in 0.02s ======================================================
-\end{lstlisting}
-\section{Functional test cases}
-
-\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
- \hline
- Title & Input (\LaTeX) & Output \\
- \hline
-
- empty file &
- \begin{lstlisting}
-
- \end{lstlisting}&
- \begin{lstlisting}
-Error! expected \documentclass at the begining of LaTeX file
- \end{lstlisting} \\
- \hline
-
- Document class &
- \begin{lstlisting}
-\documentclass[options]{class}
- \end{lstlisting}&
- \begin{lstlisting}
-Error! expected \begin{document} after document class
- \end{lstlisting} \\
- \hline
-
- \begin{lstlisting}
-Extra text between document class and begin document
- \end{lstlisting}&
- \begin{lstlisting}
-\documentclass[options]{class}
-"extra text"
-\begin{document}
- \end{lstlisting}&
- \begin{lstlisting}
-Error! unexpected text between document class and begin document
- \end{lstlisting} \\
- \hline
-
-\begin{lstlisting}
-Just document class and begin document
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\end{lstlisting}&
-\begin{lstlisting}
-Error! no \end{document} at the end of LaTeX code
-\end{lstlisting} \\
-\hline
-
- \end{tabular}
-
-\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
-\hline
-Title & Input (\LaTeX) & Output \\
-\hline
-
-\begin{lstlisting}
-Just document class and begin/end document
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-
-
-\end{lstlisting} \\
-\hline
-
-\begin{lstlisting}
-Plain text inside
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-Lorem ipsum dolor sit amet.
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-
-Lorem ipsum dolor sit amet.
-
-\end{lstlisting} \\
-\hline
-
-\begin{lstlisting}
-Reduntant \end{document} (ignored)
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-Lorem ipsum dolor sit amet.
-\end{document}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-
-Lorem ipsum dolor sit amet.
-
-\end{lstlisting} \\
-\hline
-
-\begin{lstlisting}
-LaTeX comments
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-Lorem ipsum dolor sit amet.
-% some comment
-\end{document}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-Error! LaTeX comment detected at line 3
-\end{lstlisting} \\
-\hline
-
-
-
-\end{tabular}
-
-\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
- \hline
-Title & Input (\LaTeX) & Output \\
-\hline
-
-\begin{lstlisting}
-Table with vertical lines
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\begin{tabular}{ l | c | r }
-test & 2 & test \\
-4 & 5 & 6 \\
-\end{tabular}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-
-
-
-| test |
-2 |
-test |
-
-
-| 4 |
-5 |
-6 |
-
-
-
-\end{lstlisting} \\
-\hline
-
-\begin{lstlisting}
-Missing &
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\begin{tabular}{ l c r }
-1 & 2 & 3 \\
-4 & 5 6 \\
-\end{tabular}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-Error! Missing third column in second row
-\end{lstlisting} \\
-\hline
-
-\end{tabular}
-
-\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
- \hline
-Title & Input (\LaTeX) & Output \\
-\hline
-
-\begin{lstlisting}
-Too much columns
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\begin{tabular}{ l c r }
-1 & 2 & 3 & 4 & 5 \\
-4 & 5 6 \\
-\end{tabular}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-Error! Too much columns in row 1, expected 3, got 5
-\end{lstlisting} \\
-\hline
-
-\end{tabular}
-
+ \input{sections/01-general-overview-and-assumptions}
+ \input{sections/02-functional-requirements}
+ \input{sections/03-implementation}
+ \input{sections/04-unit-tests}
+ \input{sections/05-functional-test-cases}
\end{document}
\ No newline at end of file
diff --git a/Programming/ECOTE/finalReport/sections/01-general-overview-and-assumptions.tex b/Programming/ECOTE/finalReport/sections/01-general-overview-and-assumptions.tex
new file mode 100644
index 00000000..97cc2e37
--- /dev/null
+++ b/Programming/ECOTE/finalReport/sections/01-general-overview-and-assumptions.tex
@@ -0,0 +1,11 @@
+\section{General overview and assumptions}
+My task was to create a translator of \LaTeX \, subset to selected text format with focus on \LaTeX \, tables \\
+I decided to change to translator of \LaTeX \, subset to HTML since I know \LaTeX \, very well and HTML relatively well, I decide to translate \LaTeX into HTML since HTML is easy, a little bit different than \LaTeX and popular which makes this translator a practical tool.
+\subsection{Assumptions}
+\begin{itemize}
+ \item "Tables" will be represented using \LaTeX \, \emph{table} environment
+ \item All changes influenced by different \LaTeX \, document class are ignored in html
+ \item Everything between documentclass and begin document is ignored when generating html
+ \item Program tries to generate final html even if encountering errors which would make final html not complete
+ \item Only commands defined in \LaTeX \, subset are translated, rest is translated literally as raw text to html
+\end{itemize}
diff --git a/Programming/ECOTE/finalReport/sections/02-functional-requirements.tex b/Programming/ECOTE/finalReport/sections/02-functional-requirements.tex
new file mode 100644
index 00000000..04ad2a3a
--- /dev/null
+++ b/Programming/ECOTE/finalReport/sections/02-functional-requirements.tex
@@ -0,0 +1,29 @@
+\section{Functional requirements}
+The goal of the project is to transform .tex file to (working ) .html file if the subset of .tex file is within project scope or output error message explaining why the html could not be outputed
+\subsection{\LaTeX \, subset}
+This project will focus almost exclusively on \emph{tabular} environment \\
+\begin{itemize}
+ \item $\backslash$documentclass\{class\}: Defines what layout standard \LaTeX will use
+ \item $\backslash$begin\{document\}: Ends (in our case empty) preamble
+ \item $\backslash$end\{document\}: Ends \LaTeX \, document
+ \item $\backslash$begin\{tabular\}[pos]\{table spec\}: Opens environment used to typeset tables
+ \item $\backslash$end\{tabular\}: Closes environment used to typeset tables
+\end{itemize}
+Supported tabular arguments:
+\begin{itemize}
+ \item l, c, r - respectively left-justified, centered and right-justified column
+ \item | - single vertical line
+ \item || - double vertical line
+ \item p\{'width'\} - paragraph column (that wraps), aligned at the top
+ \item m\{'width'\} - paragraph column (that wraps), aligned at the middle
+ \item b\{'width'\} - paragraph column (that wraps), aligned at the bottom
+\end{itemize}
+
+Supported commands inside tabular environment
+\begin{itemize}
+ \item \& - separate columns
+ \item $\backslash$$\backslash$ - start new row
+ \item $\backslash$hline - horizontal line
+ \item $\backslash$cline\{i-j\} horizontal line beginning in column i and ending in column j
+ \item $\backslash$newline - new line \emph{inside} the cell
+\end{itemize}
diff --git a/Programming/ECOTE/finalReport/sections/03-implementation.tex b/Programming/ECOTE/finalReport/sections/03-implementation.tex
new file mode 100644
index 00000000..86b4fb4e
--- /dev/null
+++ b/Programming/ECOTE/finalReport/sections/03-implementation.tex
@@ -0,0 +1,142 @@
+\section{Implementation}
+I decided to use Python as a language in which I will implement my solution \\
+The reasons for using python are as follow:
+\begin{enumerate}
+ \item It is the easiest language among those that I know
+ \item I know it enough to be confident in my ability to implement this solution in python
+ \item I want to learn python more through this project
+\end{enumerate}
+Negative aspects of python which is that it is very slow language do not bother me as I believe the project scope will not be big enough for this to become an issue
+
+\subsection{General architecture}
+\begin{tabular}{|l|p{10cm}|}
+ \hline
+ Module & Description \\
+ \hline
+ Main & Handles texfile, puts it to a function translating to html and saves output html file \\
+ \hline
+ FileHandler & Handles reading latex file and transforming it to string in python \\
+ \hline
+ ReadStart & Checks documentclass and begin document functions of latex file and if they are correct outputs starting html tags \\
+ \hline
+ HandleInside & Goes through inside of LaTeX document and transforms each of its part to HTML
+ \\
+ \hline
+ HandleTable & Reads table, including table parameters and actual contents and transforms it to html \\
+ \hline
+ TabInsideHandler & Handles actual content of table and translates them to html \\
+\end{tabular}
+
+
+
+
+
+
+\subsection{Data structures}
+\begin{itemize}
+\item File entered by user is represented by python File class
+\item Parsed \LaTeX \, code is represented by data structure based on node classes
+\item Tabular environment parameters are stored in an array, if the parameter contains additional optional parameters they are stored in a pair of the parent argument and array of all optional arguments
+\item Generated HTML code is stored in node classes
+\item Final HTML code is stored in plain text and then written to File
+\end{itemize}
+
+\subsection{Module descriptions}
+\subsubsection{Main}
+Puts latex filename to filehandler, sends retrieved string to function translating tex to html and then saves final html file
+\subsubsection{FileHandler}
+Handles texfile and transforms it to python string \\
+Input: \\
+tex\_filename - LaTeX file filename \\
+Functions:
+\begin{itemize}
+ \item Handle arguments - Checks if arguments are correct, reads file and saves it to python string
+ \item Invoke Latex Handler - Sends file from file handler to LatexHandler
+\end{itemize}
+\subsubsection{LatexHandler}
+Transforms tex string to html
+Input: tex string
+Functions:
+\begin{itemize}
+ \item ReadStart - Checks begininig of tex file and returns html code if the begining is correct
+ \item HandleInside - Handles insides of tex file, both tables and loose text and translates it to html
+\end{itemize}
+\subsubsection{ReadStart}
+Checks begininig of tex file and returns html code if the begining is correct \\
+Input: tex string \\
+Output: html\_string
+
+\begin{itemize}
+\item read\_document\_class - Checks if document class exists and is written according to tex rules, returns if yes
+\item read\_begin\_document - (optional) Checks if begin\{document\} function was written in tex file if yes adds to html\_string
+\item HandleInside - Passes parsed tex data and html\_string to function handling inside of tex document
+\end{itemize}
+
+\subsubsection{HandleInside}
+Translates tex string starting at begin document and ending at end document, returns final html\_string \\
+Parameters: \\
+\begin{itemize}
+\item tex\_data - String read from tex file
+\item html\_string - Final output string to which table data and loose text will be added
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item HandleTable - Converts tex tables to html tables
+ \item HandleLoose - Goes through text that is not in table and converts it to html
+\end{itemize}
+
+\subsubsection{HandleTable}
+Converts tex tables to html tables \\
+Parameters: \\
+\begin{itemize}
+\item tex\_data - String read from tex file
+\item html\_string - Final output string to which table data and loose text will be added
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item TabArgHandler - Reads tex table parameters and translates them to html style
+ \item TabInsideHandler - Reads inside of tex table and together with parse parameters outputs correct table layout and look
+\end{itemize}
+
+\subsubsection{TabInsideHandler}
+Together with html table parameters translates inside of tex table to html \\
+Parameters: \\
+\begin{itemize}
+\item TableContents - Latex string containing only inside of table
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item ReadTableContent - Parses table content and checks for errors
+ \item ConvertToHTML - Converts table inside to html
+\end{itemize}
+
+\subsubsection{TabArgHandler}
+Reads tex table parameters and translates them to html style \\
+Parameters: \\
+\begin{itemize}
+\item TableArguments - Arguments provided with $\backslash$begin\{tabular\} environment
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item ReadTableARguments - Parses table arguments and checks for errors
+ \item ConvertToHTML - Converts table arguments to html style
+\end{itemize}
+
+\subsection{Input/output description}
+Input is a .tex file (\LaTeX \, file) \\
+Outpus is an .html file \\
+In case of errors error message will be outputed on the terminal \\
+Input File path is entered as an argument to terminal with "-i" or "--input" flag for example:
+\begin{lstlisting}[language=bash]
+python main.py -i texFile.tex
+\end{lstlisting}
+Output file path can be named by user by using "-o" or "--output" flag:
+\begin{lstlisting}[language=bash]
+python main.py -i texFile.tex -o htmlFile.html
+\end{lstlisting}
+If no "-o" flag is issued the output file will have the same name as input file with changed extension to html (so in this example texFile.tex will become texFile.html) \\
+If the path to file name consists of spaces, path name needs to be but in ""
+\begin{lstlisting}[language=bash]
+python main.py -i "My Folder/input.tex"
+\end{lstlisting}
+\subsection{Others}
diff --git a/Programming/ECOTE/finalReport/sections/04-unit-tests.tex b/Programming/ECOTE/finalReport/sections/04-unit-tests.tex
new file mode 100644
index 00000000..93c0569b
--- /dev/null
+++ b/Programming/ECOTE/finalReport/sections/04-unit-tests.tex
@@ -0,0 +1,22 @@
+\section{Unit tests}
+There are over 12 unit tests for program functions, all of them can be ran by using python test environment:
+\begin{lstlisting}
+python -m pytest unit_tests
+
+collected 12 items
+
+unit_tests/test_code/test_begin_document.py . [ 8%]
+unit_tests/test_code/test_begin_tabular.py . [ 16%]
+unit_tests/test_code/test_document_class.py . [ 25%]
+unit_tests/test_code/test_length_conversions.py . [ 33%]
+unit_tests/test_code/test_only_pipes_and_space.py . [ 41%]
+unit_tests/test_code/test_split_columns.py . [ 50%]
+unit_tests/test_code/test_split_rows.py . [ 58%]
+unit_tests/test_code/test_tabular_columns_parameters.py . [ 66%]
+unit_tests/test_code/test_tabular_parameters.py . [ 75%]
+unit_tests/test_code/test_tabular_required_parameters.py . [ 83%]
+unit_tests/test_code/test_translate_column.py . [ 91%]
+unit_tests/test_code/test_translate_inside_to_html.py . [100%]
+
+===================================================== 12 passed in 0.02s ======================================================
+\end{lstlisting}
diff --git a/Programming/ECOTE/finalReport/sections/05-functional-test-cases.tex b/Programming/ECOTE/finalReport/sections/05-functional-test-cases.tex
new file mode 100644
index 00000000..63500b01
--- /dev/null
+++ b/Programming/ECOTE/finalReport/sections/05-functional-test-cases.tex
@@ -0,0 +1,202 @@
+\section{Functional test cases}
+
+\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
+ \hline
+ Title & Input (\LaTeX) & Output \\
+ \hline
+
+ empty file &
+ \begin{lstlisting}
+
+ \end{lstlisting}&
+ \begin{lstlisting}
+Error! expected \documentclass at the begining of LaTeX file
+ \end{lstlisting} \\
+ \hline
+
+ Document class &
+ \begin{lstlisting}
+\documentclass[options]{class}
+ \end{lstlisting}&
+ \begin{lstlisting}
+Error! expected \begin{document} after document class
+ \end{lstlisting} \\
+ \hline
+
+ \begin{lstlisting}
+Extra text between document class and begin document
+ \end{lstlisting}&
+ \begin{lstlisting}
+\documentclass[options]{class}
+"extra text"
+\begin{document}
+ \end{lstlisting}&
+ \begin{lstlisting}
+Error! unexpected text between document class and begin document
+ \end{lstlisting} \\
+ \hline
+
+\begin{lstlisting}
+Just document class and begin document
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\end{lstlisting}&
+\begin{lstlisting}
+Error! no \end{document} at the end of LaTeX code
+\end{lstlisting} \\
+\hline
+
+ \end{tabular}
+
+\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
+\hline
+Title & Input (\LaTeX) & Output \\
+\hline
+
+\begin{lstlisting}
+Just document class and begin/end document
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+
+
+\end{lstlisting} \\
+\hline
+
+\begin{lstlisting}
+Plain text inside
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+Lorem ipsum dolor sit amet.
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+
+Lorem ipsum dolor sit amet.
+
+\end{lstlisting} \\
+\hline
+
+\begin{lstlisting}
+Reduntant \end{document} (ignored)
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+Lorem ipsum dolor sit amet.
+\end{document}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+
+Lorem ipsum dolor sit amet.
+
+\end{lstlisting} \\
+\hline
+
+\begin{lstlisting}
+LaTeX comments
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+Lorem ipsum dolor sit amet.
+% some comment
+\end{document}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+Error! LaTeX comment detected at line 3
+\end{lstlisting} \\
+\hline
+
+
+
+\end{tabular}
+
+\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
+ \hline
+Title & Input (\LaTeX) & Output \\
+\hline
+
+\begin{lstlisting}
+Table with vertical lines
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\begin{tabular}{ l | c | r }
+test & 2 & test \\
+4 & 5 & 6 \\
+\end{tabular}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+
+
+
+| test |
+2 |
+test |
+
+
+| 4 |
+5 |
+6 |
+
+
+
+\end{lstlisting} \\
+\hline
+
+\begin{lstlisting}
+Missing &
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\begin{tabular}{ l c r }
+1 & 2 & 3 \\
+4 & 5 6 \\
+\end{tabular}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+Error! Missing third column in second row
+\end{lstlisting} \\
+\hline
+
+\end{tabular}
+
+\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
+ \hline
+Title & Input (\LaTeX) & Output \\
+\hline
+
+\begin{lstlisting}
+Too much columns
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\begin{tabular}{ l c r }
+1 & 2 & 3 & 4 & 5 \\
+4 & 5 6 \\
+\end{tabular}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+Error! Too much columns in row 1, expected 3, got 5
+\end{lstlisting} \\
+\hline
+
+\end{tabular}
+
diff --git a/Programming/ECOTE/preliminaryReport/actualReport/Krzysztof_Rudnicki_38Preliminary.tex b/Programming/ECOTE/preliminaryReport/actualReport/Krzysztof_Rudnicki_38Preliminary.tex
index 23a9971d..778c0ad5 100644
--- a/Programming/ECOTE/preliminaryReport/actualReport/Krzysztof_Rudnicki_38Preliminary.tex
+++ b/Programming/ECOTE/preliminaryReport/actualReport/Krzysztof_Rudnicki_38Preliminary.tex
@@ -18,409 +18,8 @@ Semester: 2023L}
\begin{document}
\maketitle
-\section{General overview and assumptions}
-My task is to create a translator of \LaTeX \, subset to selected text format with focus on \LaTeX \, tables \\
-I decided to change to translator of \LaTeX \, subset to HTML since I know \LaTeX \, very well and HTML relatively well, I decide to translate \LaTeX into HTML since HTML is easy, a little bit different than \LaTeX and popular which makes this translator a practical tool.
-\subsection{Assumptions}
-\begin{itemize}
- \item No \LaTeX \, (\%) comments in the script
- \item There are no extra packages in \LaTeX \, script (provided with \\ \textbackslash usepackage keyword) besides ones distributed with \LaTeX
- \item There are no extra classes in \LaTeX \, script besides ones distributed with \LaTeX
- \item There is nothing between \textbackslash documentclass keyword and \\ \textbackslash begin\{document\} keyword
- \item No standard \LaTeX \, instructions are modified in the script
- \item "Tables" will be represented using \LaTeX \, \emph{table} environment
-\end{itemize}
-\section{Functional requirements}
-The goal of the project is to transform .tex file to (working ) .html file if the subset of .tex file is within project scope or output error message explaining why the html could not be outputed
-\subsection{\LaTeX \, subset}
-This project will focus almost exclusively on \emph{tabular} environment \\
-\begin{itemize}
- \item $\backslash$documentclass\{class\}: Defines what layout standard \LaTeX will use
- \item $\backslash$begin\{document\}: Ends (in our case empty) preamble
- \item $\backslash$end\{document\}: Ends \LaTeX \, document
- \item $\backslash$begin\{tabular\}[pos]\{table spec\}: Opens environment used to typeset tables
- \item $\backslash$end\{tabular\}: Closes environment used to typeset tables
-\end{itemize}
-Supported tabular arguments:
-\begin{itemize}
- \item l, c, r - respectively left-justified, centered and right-justified column
- \item | - single vertical line
- \item || - double vertical line
- \item p\{'width'\} - paragraph column (that wraps), aligned at the top
- \item m\{'width'\} - paragraph column (that wraps), aligned at the middle
- \item b\{'width'\} - paragraph column (that wraps), aligned at the bottom
-\end{itemize}
-
-Supported commands inside tabular environment
-\begin{itemize}
- \item \& - separate columns
- \item $\backslash$$\backslash$ - start new row
- \item $\backslash$hline - horizontal line
- \item $\backslash$cline\{i-j\} horizontal line beginning in column i and ending in column j
- \item $\backslash$newline - new line \emph{inside} the cell
-\end{itemize}
-\section{Implementation}
-I decided to use Python as a language in which I will implement my solution \\
-The reasons for using python are as follow:
-\begin{enumerate}
- \item It is the easiest language among those that I know
- \item I know it enough to be confident in my ability to implement this solution in python
- \item I want to learn python more through this project
-\end{enumerate}
-Negative aspects of python which is that it is very slow language do not bother me as I believe the project scope will not be big enough for this to become an issue
-
-\subsection{General architecture}
-\begin{tabular}{|l|p{10cm}|}
- \hline
- Module & Description \\
- \hline
- Main & Handles parameters inputed as program arguments and interaction between modules \\
- \hline
- FileHandler & Handles file reading \\
- \hline
- LatexHandler & reads \LaTeX \, file content, parses it using LatexWalker class of pylatexenc library and detects errors \\
- \hline
- TabHandler & Transforms tabular environment into html table
- \\
- \hline
- TabArgHandler & Handles positional and table spec arguments of tabular environment and translates them to html \\
- \hline
- TabInsideHandler & Handles actual content of table and translates them to html \\
- \hline
- HTMLOutput class & Transforms \LaTeX \, code into html with the assumptions that no errors were found by LatexHandler and if there were any they were dealt with \\
- \hline
-\end{tabular}
-
-
-\begin{figure}[h]
- \caption{Module class diagram}
- \includegraphics[width=\textwidth]{class.png}
-\end{figure}
-
-
-
-
-
-
-\subsection{Data structures}
-\begin{itemize}
-\item File entered by user is represented by python File class
-\item Parsed \LaTeX \, code is represented by data structure based on node classes
-\item Tabular environment parameters are stored in an array, if the parameter contains additional optional parameters they are stored in a pair of the parent argument and array of all optional arguments
-\item Generated HTML code is stored in node classes
-\item Final HTML code is stored in plain text and then written to File
-\end{itemize}
-
-\subsection{Module descriptions}
-\subsubsection{Main}
-Handles user arguments and communication between modules \\
-Input: \\
-args[] - Array of user inputed arguments \\
-Functions:
-\begin{itemize}
- \item Handle arguments - Checks if arguments are correct and adjust program to their contents, in particular saves tex file path
- \item Invoke FileHandler - starts file handler class and gets returned file or errors
- \item Invoke Latex Handler - Sends file from file handler to LatexHandler
-\end{itemize}
-\subsubsection{FileHandler}
-Reads file from filename provided by user and at the end saves HTML file \\
-Parameters: \\
-\begin{itemize}
-\item filename - user entered tex filename
-\item saveFilename - (optional) filename for output file
-\item HTMLFile - converted final html file in File format
-\item LatexFile - latex file in File format
-\end{itemize}
-Functions:
-\begin{itemize}
- \item ReadFile - Using user filename as argument reads file and saves it to LatexFile
- \item SaveFile - Using filename provided by user or tex filename as argument converts HTML string to file and saves it
-\end{itemize}
-
-\subsubsection{LatexHandler}
-Reads file from filename provided by user and at the end saves HTML file \\
-Parameters: \\
-\begin{itemize}
-\item filename - user entered tex filename
-\item saveFilename - (optional) filename for output file
-\item HTMLFile - converted final html file in File format
-\item LatexFile - latex file in File format
-\end{itemize}
-Functions:
-\begin{itemize}
- \item ReadFile - Using user filename as argument reads file and saves it to LatexFile
- \item SaveFile - Using filename provided by user or tex filename as argument converts HTML string to file and saves it
-\end{itemize}
-
-\subsubsection{HTMLOutput}
-Reads file from filename provided by user and at the end saves HTML file \\
-Parameters: \\
-\begin{itemize}
-\item filename - user entered tex filename
-\item saveFilename - (optional) filename for output file
-\item HTMLFile - converted final html file in File format
-\item LatexFile - latex file in File format
-\end{itemize}
-Functions:
-\begin{itemize}
- \item ReadFile - Using user filename as argument reads file and saves it to LatexFile
- \item SaveFile - Using filename provided by user or tex filename as argument converts HTML string to file and saves it
-\end{itemize}
-
-\subsubsection{TabHandler}
-Handles tables and converts them to html nodes \\
-Parameters: \\
-\begin{itemize}
-\item TableNode - node containing only the table
-\end{itemize}
-Functions:
-\begin{itemize}
- \item ParseTable - Parses Table node and checks for errors
- \item ConvertToHTML - Converts table node to html using TabInsideHandler and TabArgHandler
-\end{itemize}
-
-\subsubsection{TabInsideHandler}
-Handles inside of tabular environment and converts them to html nodes \\
-Parameters: \\
-\begin{itemize}
-\item TableContents - Latex node containing only inside of table
-\end{itemize}
-Functions:
-\begin{itemize}
- \item ReadTableContent - Parses table content and checks for errors
- \item ConvertToHTML - Converts table inside node to html
-\end{itemize}
-
-\subsubsection{TabArgHandler}
-Handles arguments of tabular environment and converts them to html nodes \\
-Parameters: \\
-\begin{itemize}
-\item TableArguments - Arguments provided with $\backslash$begin\{tabular\} environment
-\end{itemize}
-Functions:
-\begin{itemize}
- \item ReadTableARguments - Parses table arguments and checks for errors
- \item ConvertToHTML - Converts table arguments to html
-\end{itemize}
-
-\subsection{Input/output description}
-Input is a .tex file (\LaTeX \, file) \\
-Outpus is an .html file \\
-In case of errors error message will be outputed on the terminal \\
-Input File path is entered as an argument to terminal with "-i" or "--input" flag for example:
-\begin{lstlisting}[language=bash]
-python main.py -i texFile.tex
-\end{lstlisting}
-Output file path can be named by user by using "-o" or "--output" flag:
-\begin{lstlisting}[language=bash]
-python main.py -i texFile.tex -o htmlFile.html
-\end{lstlisting}
-If no "-o" flag is issued the output file will have the same name as input file with changed extension to html (so in this example texFile.tex will become texFile.html) \\
-If the path to file name consists of spaces, path name needs to be but in ""
-\begin{lstlisting}[language=bash]
-python main.py -i "My Folder/input.tex"
-\end{lstlisting}
-\subsection{Others}
-\section{Functional test cases}
-
-\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
- \hline
- Title & Input (\LaTeX) & Output \\
- \hline
-
- empty file &
- \begin{lstlisting}
-
- \end{lstlisting}&
- \begin{lstlisting}
-Error! expected \documentclass at the begining of LaTeX file
- \end{lstlisting} \\
- \hline
-
- Document class &
- \begin{lstlisting}
-\documentclass[options]{class}
- \end{lstlisting}&
- \begin{lstlisting}
-Error! expected \begin{document} after document class
- \end{lstlisting} \\
- \hline
-
- \begin{lstlisting}
-Extra text between document class and begin document
- \end{lstlisting}&
- \begin{lstlisting}
-\documentclass[options]{class}
-"extra text"
-\begin{document}
- \end{lstlisting}&
- \begin{lstlisting}
-Error! unexpected text between document class and begin document
- \end{lstlisting} \\
- \hline
-
-\begin{lstlisting}
-Just document class and begin document
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\end{lstlisting}&
-\begin{lstlisting}
-Error! no \end{document} at the end of LaTeX code
-\end{lstlisting} \\
-\hline
-
- \end{tabular}
-
-\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
-\hline
-Title & Input (\LaTeX) & Output \\
-\hline
-
-\begin{lstlisting}
-Just document class and begin/end document
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-
-
-\end{lstlisting} \\
-\hline
-
-\begin{lstlisting}
-Plain text inside
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-Lorem ipsum dolor sit amet.
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-
-Lorem ipsum dolor sit amet.
-
-\end{lstlisting} \\
-\hline
-
-\begin{lstlisting}
-Reduntant \end{document} (ignored)
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-Lorem ipsum dolor sit amet.
-\end{document}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-
-Lorem ipsum dolor sit amet.
-
-\end{lstlisting} \\
-\hline
-
-\begin{lstlisting}
-LaTeX comments
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-Lorem ipsum dolor sit amet.
-% some comment
-\end{document}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-Error! LaTeX comment detected at line 3
-\end{lstlisting} \\
-\hline
-
-
-
-\end{tabular}
-
-\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
- \hline
-Title & Input (\LaTeX) & Output \\
-\hline
-
-\begin{lstlisting}
-Table with vertical lines
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\begin{tabular}{ l | c | r }
-test & 2 & test \\
-4 & 5 & 6 \\
-\end{tabular}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-
-
-
-| test |
-2 |
-test |
-
-
-| 4 |
-5 |
-6 |
-
-
-
-\end{lstlisting} \\
-\hline
-
-\begin{lstlisting}
-Missing &
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\begin{tabular}{ l c r }
-1 & 2 & 3 \\
-4 & 5 6 \\
-\end{tabular}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-Error! Missing third column in second row
-\end{lstlisting} \\
-\hline
-
-\end{tabular}
-
-\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
- \hline
-Title & Input (\LaTeX) & Output \\
-\hline
-
-\begin{lstlisting}
-Too much columns
-\end{lstlisting}&
-\begin{lstlisting}
-\documentclass[options]{class}
-\begin{document}
-\begin{tabular}{ l c r }
-1 & 2 & 3 & 4 & 5 \\
-4 & 5 6 \\
-\end{tabular}
-\end{document}
-\end{lstlisting}&
-\begin{lstlisting}
-Error! Too much columns in row 1, expected 3, got 5
-\end{lstlisting} \\
-\hline
-
-\end{tabular}
-
+ \input{sections/01-general-overview-and-assumptions}
+ \input{sections/02-functional-requirements}
+ \input{sections/03-implementation}
+ \input{sections/04-functional-test-cases}
\end{document}
\ No newline at end of file
diff --git a/Programming/ECOTE/preliminaryReport/actualReport/sections/01-general-overview-and-assumptions.tex b/Programming/ECOTE/preliminaryReport/actualReport/sections/01-general-overview-and-assumptions.tex
new file mode 100644
index 00000000..64d45dbd
--- /dev/null
+++ b/Programming/ECOTE/preliminaryReport/actualReport/sections/01-general-overview-and-assumptions.tex
@@ -0,0 +1,12 @@
+\section{General overview and assumptions}
+My task is to create a translator of \LaTeX \, subset to selected text format with focus on \LaTeX \, tables \\
+I decided to change to translator of \LaTeX \, subset to HTML since I know \LaTeX \, very well and HTML relatively well, I decide to translate \LaTeX into HTML since HTML is easy, a little bit different than \LaTeX and popular which makes this translator a practical tool.
+\subsection{Assumptions}
+\begin{itemize}
+ \item No \LaTeX \, (\%) comments in the script
+ \item There are no extra packages in \LaTeX \, script (provided with \\ \textbackslash usepackage keyword) besides ones distributed with \LaTeX
+ \item There are no extra classes in \LaTeX \, script besides ones distributed with \LaTeX
+ \item There is nothing between \textbackslash documentclass keyword and \\ \textbackslash begin\{document\} keyword
+ \item No standard \LaTeX \, instructions are modified in the script
+ \item "Tables" will be represented using \LaTeX \, \emph{table} environment
+\end{itemize}
diff --git a/Programming/ECOTE/preliminaryReport/actualReport/sections/02-functional-requirements.tex b/Programming/ECOTE/preliminaryReport/actualReport/sections/02-functional-requirements.tex
new file mode 100644
index 00000000..04ad2a3a
--- /dev/null
+++ b/Programming/ECOTE/preliminaryReport/actualReport/sections/02-functional-requirements.tex
@@ -0,0 +1,29 @@
+\section{Functional requirements}
+The goal of the project is to transform .tex file to (working ) .html file if the subset of .tex file is within project scope or output error message explaining why the html could not be outputed
+\subsection{\LaTeX \, subset}
+This project will focus almost exclusively on \emph{tabular} environment \\
+\begin{itemize}
+ \item $\backslash$documentclass\{class\}: Defines what layout standard \LaTeX will use
+ \item $\backslash$begin\{document\}: Ends (in our case empty) preamble
+ \item $\backslash$end\{document\}: Ends \LaTeX \, document
+ \item $\backslash$begin\{tabular\}[pos]\{table spec\}: Opens environment used to typeset tables
+ \item $\backslash$end\{tabular\}: Closes environment used to typeset tables
+\end{itemize}
+Supported tabular arguments:
+\begin{itemize}
+ \item l, c, r - respectively left-justified, centered and right-justified column
+ \item | - single vertical line
+ \item || - double vertical line
+ \item p\{'width'\} - paragraph column (that wraps), aligned at the top
+ \item m\{'width'\} - paragraph column (that wraps), aligned at the middle
+ \item b\{'width'\} - paragraph column (that wraps), aligned at the bottom
+\end{itemize}
+
+Supported commands inside tabular environment
+\begin{itemize}
+ \item \& - separate columns
+ \item $\backslash$$\backslash$ - start new row
+ \item $\backslash$hline - horizontal line
+ \item $\backslash$cline\{i-j\} horizontal line beginning in column i and ending in column j
+ \item $\backslash$newline - new line \emph{inside} the cell
+\end{itemize}
diff --git a/Programming/ECOTE/preliminaryReport/actualReport/sections/03-implementation.tex b/Programming/ECOTE/preliminaryReport/actualReport/sections/03-implementation.tex
new file mode 100644
index 00000000..4907840b
--- /dev/null
+++ b/Programming/ECOTE/preliminaryReport/actualReport/sections/03-implementation.tex
@@ -0,0 +1,162 @@
+\section{Implementation}
+I decided to use Python as a language in which I will implement my solution \\
+The reasons for using python are as follow:
+\begin{enumerate}
+ \item It is the easiest language among those that I know
+ \item I know it enough to be confident in my ability to implement this solution in python
+ \item I want to learn python more through this project
+\end{enumerate}
+Negative aspects of python which is that it is very slow language do not bother me as I believe the project scope will not be big enough for this to become an issue
+
+\subsection{General architecture}
+\begin{tabular}{|l|p{10cm}|}
+ \hline
+ Module & Description \\
+ \hline
+ Main & Handles parameters inputed as program arguments and interaction between modules \\
+ \hline
+ FileHandler & Handles file reading \\
+ \hline
+ LatexHandler & reads \LaTeX \, file content, parses it using LatexWalker class of pylatexenc library and detects errors \\
+ \hline
+ TabHandler & Transforms tabular environment into html table
+ \\
+ \hline
+ TabArgHandler & Handles positional and table spec arguments of tabular environment and translates them to html \\
+ \hline
+ TabInsideHandler & Handles actual content of table and translates them to html \\
+ \hline
+ HTMLOutput class & Transforms \LaTeX \, code into html with the assumptions that no errors were found by LatexHandler and if there were any they were dealt with \\
+ \hline
+\end{tabular}
+
+
+\begin{figure}[h]
+ \caption{Module class diagram}
+ \includegraphics[width=\textwidth]{class.png}
+\end{figure}
+
+
+
+
+
+
+\subsection{Data structures}
+\begin{itemize}
+\item File entered by user is represented by python File class
+\item Parsed \LaTeX \, code is represented by data structure based on node classes
+\item Tabular environment parameters are stored in an array, if the parameter contains additional optional parameters they are stored in a pair of the parent argument and array of all optional arguments
+\item Generated HTML code is stored in node classes
+\item Final HTML code is stored in plain text and then written to File
+\end{itemize}
+
+\subsection{Module descriptions}
+\subsubsection{Main}
+Handles user arguments and communication between modules \\
+Input: \\
+args[] - Array of user inputed arguments \\
+Functions:
+\begin{itemize}
+ \item Handle arguments - Checks if arguments are correct and adjust program to their contents, in particular saves tex file path
+ \item Invoke FileHandler - starts file handler class and gets returned file or errors
+ \item Invoke Latex Handler - Sends file from file handler to LatexHandler
+\end{itemize}
+\subsubsection{FileHandler}
+Reads file from filename provided by user and at the end saves HTML file \\
+Parameters: \\
+\begin{itemize}
+\item filename - user entered tex filename
+\item saveFilename - (optional) filename for output file
+\item HTMLFile - converted final html file in File format
+\item LatexFile - latex file in File format
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item ReadFile - Using user filename as argument reads file and saves it to LatexFile
+ \item SaveFile - Using filename provided by user or tex filename as argument converts HTML string to file and saves it
+\end{itemize}
+
+\subsubsection{LatexHandler}
+Reads file from filename provided by user and at the end saves HTML file \\
+Parameters: \\
+\begin{itemize}
+\item filename - user entered tex filename
+\item saveFilename - (optional) filename for output file
+\item HTMLFile - converted final html file in File format
+\item LatexFile - latex file in File format
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item ReadFile - Using user filename as argument reads file and saves it to LatexFile
+ \item SaveFile - Using filename provided by user or tex filename as argument converts HTML string to file and saves it
+\end{itemize}
+
+\subsubsection{HTMLOutput}
+Reads file from filename provided by user and at the end saves HTML file \\
+Parameters: \\
+\begin{itemize}
+\item filename - user entered tex filename
+\item saveFilename - (optional) filename for output file
+\item HTMLFile - converted final html file in File format
+\item LatexFile - latex file in File format
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item ReadFile - Using user filename as argument reads file and saves it to LatexFile
+ \item SaveFile - Using filename provided by user or tex filename as argument converts HTML string to file and saves it
+\end{itemize}
+
+\subsubsection{TabHandler}
+Handles tables and converts them to html nodes \\
+Parameters: \\
+\begin{itemize}
+\item TableNode - node containing only the table
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item ParseTable - Parses Table node and checks for errors
+ \item ConvertToHTML - Converts table node to html using TabInsideHandler and TabArgHandler
+\end{itemize}
+
+\subsubsection{TabInsideHandler}
+Handles inside of tabular environment and converts them to html nodes \\
+Parameters: \\
+\begin{itemize}
+\item TableContents - Latex node containing only inside of table
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item ReadTableContent - Parses table content and checks for errors
+ \item ConvertToHTML - Converts table inside node to html
+\end{itemize}
+
+\subsubsection{TabArgHandler}
+Handles arguments of tabular environment and converts them to html nodes \\
+Parameters: \\
+\begin{itemize}
+\item TableArguments - Arguments provided with $\backslash$begin\{tabular\} environment
+\end{itemize}
+Functions:
+\begin{itemize}
+ \item ReadTableARguments - Parses table arguments and checks for errors
+ \item ConvertToHTML - Converts table arguments to html
+\end{itemize}
+
+\subsection{Input/output description}
+Input is a .tex file (\LaTeX \, file) \\
+Outpus is an .html file \\
+In case of errors error message will be outputed on the terminal \\
+Input File path is entered as an argument to terminal with "-i" or "--input" flag for example:
+\begin{lstlisting}[language=bash]
+python main.py -i texFile.tex
+\end{lstlisting}
+Output file path can be named by user by using "-o" or "--output" flag:
+\begin{lstlisting}[language=bash]
+python main.py -i texFile.tex -o htmlFile.html
+\end{lstlisting}
+If no "-o" flag is issued the output file will have the same name as input file with changed extension to html (so in this example texFile.tex will become texFile.html) \\
+If the path to file name consists of spaces, path name needs to be but in ""
+\begin{lstlisting}[language=bash]
+python main.py -i "My Folder/input.tex"
+\end{lstlisting}
+\subsection{Others}
diff --git a/Programming/ECOTE/preliminaryReport/actualReport/sections/04-functional-test-cases.tex b/Programming/ECOTE/preliminaryReport/actualReport/sections/04-functional-test-cases.tex
new file mode 100644
index 00000000..63500b01
--- /dev/null
+++ b/Programming/ECOTE/preliminaryReport/actualReport/sections/04-functional-test-cases.tex
@@ -0,0 +1,202 @@
+\section{Functional test cases}
+
+\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
+ \hline
+ Title & Input (\LaTeX) & Output \\
+ \hline
+
+ empty file &
+ \begin{lstlisting}
+
+ \end{lstlisting}&
+ \begin{lstlisting}
+Error! expected \documentclass at the begining of LaTeX file
+ \end{lstlisting} \\
+ \hline
+
+ Document class &
+ \begin{lstlisting}
+\documentclass[options]{class}
+ \end{lstlisting}&
+ \begin{lstlisting}
+Error! expected \begin{document} after document class
+ \end{lstlisting} \\
+ \hline
+
+ \begin{lstlisting}
+Extra text between document class and begin document
+ \end{lstlisting}&
+ \begin{lstlisting}
+\documentclass[options]{class}
+"extra text"
+\begin{document}
+ \end{lstlisting}&
+ \begin{lstlisting}
+Error! unexpected text between document class and begin document
+ \end{lstlisting} \\
+ \hline
+
+\begin{lstlisting}
+Just document class and begin document
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\end{lstlisting}&
+\begin{lstlisting}
+Error! no \end{document} at the end of LaTeX code
+\end{lstlisting} \\
+\hline
+
+ \end{tabular}
+
+\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
+\hline
+Title & Input (\LaTeX) & Output \\
+\hline
+
+\begin{lstlisting}
+Just document class and begin/end document
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+
+
+\end{lstlisting} \\
+\hline
+
+\begin{lstlisting}
+Plain text inside
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+Lorem ipsum dolor sit amet.
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+
+Lorem ipsum dolor sit amet.
+
+\end{lstlisting} \\
+\hline
+
+\begin{lstlisting}
+Reduntant \end{document} (ignored)
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+Lorem ipsum dolor sit amet.
+\end{document}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+
+Lorem ipsum dolor sit amet.
+
+\end{lstlisting} \\
+\hline
+
+\begin{lstlisting}
+LaTeX comments
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+Lorem ipsum dolor sit amet.
+% some comment
+\end{document}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+Error! LaTeX comment detected at line 3
+\end{lstlisting} \\
+\hline
+
+
+
+\end{tabular}
+
+\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
+ \hline
+Title & Input (\LaTeX) & Output \\
+\hline
+
+\begin{lstlisting}
+Table with vertical lines
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\begin{tabular}{ l | c | r }
+test & 2 & test \\
+4 & 5 & 6 \\
+\end{tabular}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+
+
+
+| test |
+2 |
+test |
+
+
+| 4 |
+5 |
+6 |
+
+
+
+\end{lstlisting} \\
+\hline
+
+\begin{lstlisting}
+Missing &
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\begin{tabular}{ l c r }
+1 & 2 & 3 \\
+4 & 5 6 \\
+\end{tabular}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+Error! Missing third column in second row
+\end{lstlisting} \\
+\hline
+
+\end{tabular}
+
+\begin{tabular}{|p{3cm}|p{6cm}|p{6cm}|}
+ \hline
+Title & Input (\LaTeX) & Output \\
+\hline
+
+\begin{lstlisting}
+Too much columns
+\end{lstlisting}&
+\begin{lstlisting}
+\documentclass[options]{class}
+\begin{document}
+\begin{tabular}{ l c r }
+1 & 2 & 3 & 4 & 5 \\
+4 & 5 6 \\
+\end{tabular}
+\end{document}
+\end{lstlisting}&
+\begin{lstlisting}
+Error! Too much columns in row 1, expected 3, got 5
+\end{lstlisting} \\
+\hline
+
+\end{tabular}
+
diff --git a/Programming/EOPSY/lab3/report/report.tex b/Programming/EOPSY/lab3/report/report.tex
index f6592e81..61a4042d 100644
--- a/Programming/EOPSY/lab3/report/report.tex
+++ b/Programming/EOPSY/lab3/report/report.tex
@@ -8,392 +8,12 @@
\author{Krzysztof Rudnicki, 307585}
\date{\today}
\maketitle
-\section{Introduction}
-ALL TEXT SURROUNDED BY [] LIKE \cite{lab3 Manual} SHOULD BE CLICKABLE AND LEAD
-EITHER TO WEBPAGE OR PLACE IN THIS DOCUMENT \\
-The goal of the laboratory was to create three scenarios using config file and
-then investigate how those scenarios played out. \\
-Scenario 1: 2 Processes \\
-Scenario 2: 5 Processes \\
-Scenario 3: 10 Processes \\
-We had to get to know how the schedulers work, how they switch. \cite{lab3
-Manual}
-\paragraph{First come first serve}
-We used First come first serve algorithm $\rightarrow$ This algorithm simply executes the process which
-arrived first. The process that requests CPU as a first process gets the CPU
-first. It is easy to implement and understand. We just use Queue data structure
-and we pick processes from the head of the queue and new procesess are added at
-the tail of the queue. \cite{First come first serve}
-\begin{figure}[H]
- \caption{First come first serve example graphic from
- \href{https://www.geeksforgeeks.org/program-for-fcfs-cpu-scheduling-set-1/}{[Geeks for
- Geeks]}}
- \includegraphics[width=\textwidth]{FCFS}
-\end{figure}
-\paragraph{Other algorithms} \cite{Other scheduling algorithms}
-\begin{enumerate}
- \item Shortest-Job-Next - Executes first processes that will take least
- time to finish
- \item Priority Scheduling - Each process gets assigned a prority and we
- execute them from the process with highest priority to the
- process with lowest prority
- \item Round Robin Scheduling - We give each process a constant time to
- execute, after this time expires regardless whether process
- finished or not we go to another process untill all of them are
- finished
-\end{enumerate}
-\section{Explanation of types of values in summary results and summary
-process}
-\subsection{Summary Results}
-\begin{itemize}
- \item Scheduling Type - Type of scheduling algorithm used
- \item Scheduling Name - Name of the scheduling algorithm
- \item Simulation Run Time - How long simulation run
- \item Mean - Average runtime for the processes
- \item Standard Deviation - Deviation from mean
- \item Process \# - Process number
- \item CPU Time - Total runtime for the process
- \item IO Blocking - How long process runs before it is blocked for
- input or output
- \item CPU Completed - How long runtime completed for the process
- \item CPU Blocked - How often the process was blocked
-\end{itemize}
-\cite{lab3 Manual}
-\subsection{Summary Processes}
-\begin{itemize}
- \item process-number - Process number assigned by simulator
- \item process-status - Registered - process can be used by scheduling
- algorithm, I/O blocked - process blocked for input or output,
- Completed - process met or exceeded execution time
- \item cpu-time - Total amount of runtime allowed for this process
- \item block-time - amount of time before blocking process
- \item accumulated-time - how long the process has already executed
- (appears twice)
-\end{itemize}
-\cite{lab3 Manual}
-
-\section{Scheduling conf settings}
-\begin{lstlisting}
-// # of Process
-numprocess 2 or 5 or 10
-
-// mean deivation
-meandev 2000
-
-// standard deviation
-standdev 0
-
-// process # I/O blocking
-process 500
-process 500
-(more if we set numprocess to 5 or 10)
-
-// duration of the simulation in milliseconds
-runtime 10000
-
-\end{lstlisting}
-
-\section{Two processes}
-\subsection{Summary Results file}
-
-
-\begin{lstlisting}
-Scheduling Type: Batch (Nonpreemptive)
-Scheduling Name: First-Come First-Served
-Simulation Run Time: 4000
-Mean: 2000
-Standard Deviation: 0
-\end{lstlisting}
-
-\begin{center}
-\begin{tabular}{| c | c | c | c | c |}
-\hline
-Process\# & CPU Time & IO Blocking & CPU Completed & CPU Blocked \\
-\hline
-0& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
-\hline
-1& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
-\hline
-\end{tabular}
-\end{center}
-
-\subsection{Summary Processes file}
-\begin{lstlisting}
-Process: 0 registered... (2000 500 0 0)
-Process: 0 I/O blocked... (2000 500 500 500)
-Process: 1 registered... (2000 500 0 0)
-Process: 1 I/O blocked... (2000 500 500 500)
-Process: 0 registered... (2000 500 500 500)
-Process: 0 I/O blocked... (2000 500 1000 1000)
-Process: 1 registered... (2000 500 500 500)
-Process: 1 I/O blocked... (2000 500 1000 1000)
-Process: 0 registered... (2000 500 1000 1000)
-Process: 0 I/O blocked... (2000 500 1500 1500)
-Process: 1 registered... (2000 500 1000 1000)
-Process: 1 I/O blocked... (2000 500 1500 1500)
-Process: 0 registered... (2000 500 1500 1500)
-Process: 0 completed... (2000 500 2000 2000)
-Process: 1 registered... (2000 500 1500 1500)
-Process: 1 completed... (2000 500 2000 2000)
-\end{lstlisting}
-\subsection{Comments}
-Scheduling type was Batch since I did not change it in SchedulingAlgorithm.java
-file \\
-Scheduling Name was First-Come First-Served since this is what what we use as
-described in README for this laboratory \\
-Simulation Run time is 4000 ms and NOT 10000 ms since the simulation finished
-before it exceeded this max time \\
-Mean is 2000 since this is a value I set in conf value according to laboratory
-task description, same with standard deviation equal to 0 and CPU Time equal to
-2000 ms \\
-IO Blocking is equal to 500 ms, this is a value which we specified in
-configuration file and since we did not exceeded the runtime parameter it stayed
-equal to 500 ms \\
-CPU completed is equal to 2000 since this is deviation we set in configuration
-settings and the runtime was not exceeded \\
-All processes blocked 3 times, analysing summary processes we can see that they
-blocked at 500 ms, 1000 ms and 1500 ms and at 2000 seconds they completed
-
-\section{Five processes}
-\newpage
-\subsection{Summary Results file}
-\begin{lstlisting}
-Scheduling Type: Batch (Nonpreemptive)
-Scheduling Name: First-Come First-Served
-Simulation Run Time: 10000
-Mean: 2000
-Standard Deviation: 0
-\end{lstlisting}
-\begin{center}
-\begin{tabular}{| c | c | c | c | c |}
-\hline
-Process\# & CPU Time & IO Blocking & CPU Completed & CPU Blocked \\
-\hline
-0& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
-\hline
-1& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
-\hline
-2& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
-\hline
-3& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
-\hline
-4& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
-\hline
-\end{tabular}
-\end{center}
-
-\subsection{Summary Processes file}
-\begin{lstlisting}
-Process: 0 registered... (2000 500 0 0)
-Process: 0 I/O blocked... (2000 500 500 500)
-Process: 1 registered... (2000 500 0 0)
-Process: 1 I/O blocked... (2000 500 500 500)
-Process: 0 registered... (2000 500 500 500)
-Process: 0 I/O blocked... (2000 500 1000 1000)
-Process: 1 registered... (2000 500 500 500)
-Process: 1 I/O blocked... (2000 500 1000 1000)
-Process: 0 registered... (2000 500 1000 1000)
-Process: 0 I/O blocked... (2000 500 1500 1500)
-Process: 1 registered... (2000 500 1000 1000)
-Process: 1 I/O blocked... (2000 500 1500 1500)
-Process: 0 registered... (2000 500 1500 1500)
-Process: 0 completed... (2000 500 2000 2000)
-Process: 1 registered... (2000 500 1500 1500)
-Process: 1 completed... (2000 500 2000 2000)
-Process: 2 registered... (2000 500 0 0)
-Process: 2 I/O blocked... (2000 500 500 500)
-Process: 3 registered... (2000 500 0 0)
-Process: 3 I/O blocked... (2000 500 500 500)
-Process: 2 registered... (2000 500 500 500)
-Process: 2 I/O blocked... (2000 500 1000 1000)
-Process: 3 registered... (2000 500 500 500)
-Process: 3 I/O blocked... (2000 500 1000 1000)
-Process: 2 registered... (2000 500 1000 1000)
-Process: 2 I/O blocked... (2000 500 1500 1500)
-Process: 3 registered... (2000 500 1000 1000)
-Process: 3 I/O blocked... (2000 500 1500 1500)
-Process: 2 registered... (2000 500 1500 1500)
-Process: 2 completed... (2000 500 2000 2000)
-Process: 3 registered... (2000 500 1500 1500)
-Process: 3 completed... (2000 500 2000 2000)
-Process: 4 registered... (2000 500 0 0)
-Process: 4 I/O blocked... (2000 500 500 500)
-Process: 4 registered... (2000 500 500 500)
-Process: 4 I/O blocked... (2000 500 1000 1000)
-Process: 4 registered... (2000 500 1000 1000)
-Process: 4 I/O blocked... (2000 500 1500 1500)
-Process: 4 registered... (2000 500 1500 1500)
-\end{lstlisting}
-\subsection{Comments}
-Scheduling type was Batch since I did not change it in SchedulingAlgorithm.java
-file \\
-Scheduling Name was First-Come First-Served since this is what what we use as
-described in README for this laboratory \\
-Simulation run time is 10000 ms since it run untill the limit I set in conf file
-according to task description \\
-CPU blocking is set everywhere to 500 ms as in conf file \\
-Mean is 2000 since this is a value I set in conf value according to laboratory
-task description, same with standard deviation equal to 0 and CPU Time equal to
-2000 ms \\
-CPU completed is equal to expected 2000 ms, this makes sense since we had run
-time equal to 10000 ms and 5 procesess so each of them could take exactly the
-amonunt of time we set them to take.
-
-
-\section{Ten processes}
-\subsection{Summary Results file}
-\begin{lstlisting}
-Scheduling Type: Batch (Nonpreemptive)
-Scheduling Name: First-Come First-Served
-Simulation Run Time: 10000
-Mean: 2000
-Standard Deviation: 0
-\end{lstlisting}
-\begin{center}
-\begin{tabular}{| c | c | c | c | c |}
-\hline
-Process\# & CPU Time & IO Blocking & CPU Completed & CPU Blocked \\
-\hline
-0 &2000 (ms) &500 (ms)& 2000 (ms)& 3 times \\
-\hline
-1 &2000 (ms) &500 (ms)& 2000 (ms)& 3 times \\
-\hline
-2 &2000 (ms) &500 (ms)& 2000 (ms)& 3 times \\
-\hline
-3 &2000 (ms) &500 (ms)& 2000 (ms)& 3 times \\
-\hline
-4 &2000 (ms) &500 (ms)& 1000 (ms)& 2 times \\
-\hline
-5 &2000 (ms) &500 (ms)& 1000 (ms)& 1 times \\
-\hline
-6 &2000 (ms) &500 (ms)& 0 (ms)& 0 times \\
-\hline
-7 &2000 (ms) &500 (ms)& 0 (ms)& 0 times \\
-\hline
-8 &2000 (ms) &500 (ms)& 0 (ms)& 0 times \\
-\hline
-9 &2000 (ms) &500 (ms)& 0 (ms)& 0 times \\
-\hline
-\end{tabular}
-\end{center}
-\subsection{Summary Processes file}
-\begin{lstlisting}
-Process: 0 registered... (2000 500 0 0)
-Process: 0 I/O blocked... (2000 500 500 500)
-Process: 1 registered... (2000 500 0 0)
-Process: 1 I/O blocked... (2000 500 500 500)
-Process: 0 registered... (2000 500 500 500)
-Process: 0 I/O blocked... (2000 500 1000 1000)
-Process: 1 registered... (2000 500 500 500)
-Process: 1 I/O blocked... (2000 500 1000 1000)
-Process: 0 registered... (2000 500 1000 1000)
-Process: 0 I/O blocked... (2000 500 1500 1500)
-Process: 1 registered... (2000 500 1000 1000)
-Process: 1 I/O blocked... (2000 500 1500 1500)
-Process: 0 registered... (2000 500 1500 1500)
-Process: 0 completed... (2000 500 2000 2000)
-Process: 1 registered... (2000 500 1500 1500)
-Process: 1 completed... (2000 500 2000 2000)
-Process: 2 registered... (2000 500 0 0)
-Process: 2 I/O blocked... (2000 500 500 500)
-Process: 3 registered... (2000 500 0 0)
-Process: 3 I/O blocked... (2000 500 500 500)
-Process: 2 registered... (2000 500 500 500)
-Process: 2 I/O blocked... (2000 500 1000 1000)
-Process: 3 registered... (2000 500 500 500)
-Process: 3 I/O blocked... (2000 500 1000 1000)
-Process: 2 registered... (2000 500 1000 1000)
-Process: 2 I/O blocked... (2000 500 1500 1500)
-Process: 3 registered... (2000 500 1000 1000)
-Process: 3 I/O blocked... (2000 500 1500 1500)
-Process: 2 registered... (2000 500 1500 1500)
-Process: 2 completed... (2000 500 2000 2000)
-Process: 3 registered... (2000 500 1500 1500)
-Process: 3 completed... (2000 500 2000 2000)
-Process: 4 registered... (2000 500 0 0)
-Process: 4 I/O blocked... (2000 500 500 500)
-Process: 5 registered... (2000 500 0 0)
-Process: 5 I/O blocked... (2000 500 500 500)
-Process: 4 registered... (2000 500 500 500)
-Process: 4 I/O blocked... (2000 500 1000 1000)
-Process: 5 registered... (2000 500 500 500)
-\end{lstlisting}
-\subsection{Comments}
-Scheduling type was Batch since I did not change it in SchedulingAlgorithm.java
-file \\
-Scheduling Name was First-Come First-Served since this is what what we use as
-described in README for this laboratory \\
-Simulation run time is 10000 ms since it run untill the limit I set in conf file
-according to task description \\
-IO Blocking set to 500 ms as in config file \\
-Mean is 2000 since this is a value I set in conf value according to laboratory
-task description, same with standard deviation equal to 0 and CPU Time equal to
-2000 ms \\
-CPU completed this time is equal to 2000 up to 4th process and then is equal to
-1000 ms for 5th and 6th and then it is equal to 0 ms, this means that the
-simulation exceeded the runtime before it had a chance to run all processes
-
-\section{Getting process to be blocked 4 times}
-Up untill now process got blocked for maximum of 3 times. This makes sense since
-since they get blocked every 500 ms and the runtime for single process is 2000
-ms, so they get blocked first time at 500 ms, second time at 1000 ms and third
-time at 1500 ms, at 2000 ms they finish execution so they do not get blocked. \\
-If we change runtime of process to 2001 ms we should get as the result them
-getting blocked 4 times! \\
-I changed meandev in scheduling.conf to 2001 and observed results:
-\subsection{Summary Results file}
-\begin{lstlisting}
-Scheduling Type: Batch (Nonpreemptive)
-Scheduling Name: First-Come First-Served
-Simulation Run Time: 6003
-Mean: 2001
-Standard Deviation: 0
-\end{lstlisting}
-\begin{center}
- \begin{tabular}{| c | c | c | c | c |}
- \hline
- Process \#& CPU Time& IO Blocking& CPU Completed&
- CPU Blocked \\ \hline
- 0 & 2001 (ms)& 500 (ms)& 2001 (ms)&
- 4 times \\ \hline
- 1 & 2001 (ms)& 500 (ms)& 2001 (ms)&
- 4 times \\ \hline
- 2 & 2001 (ms)& 500 (ms)& 2001 (ms)&
- 4 times \\ \hline
-\end{tabular}
-\end{center}
-Sure enough we got all of the processes blocked 4 times!
-\section{Finishing comments}
-We runned all the processes, get to know scheduling, get to know first come
-first served algorithm. \\
-There are upsides and downsides of first come first served algorithm:
-\\
-Upsides:
-\begin{itemize}
- \item It is easy to implement
- \item It is easy to understand
-\end{itemize}
-Downsides:
-\begin{itemize}
- \item It is very inefficient (Last experiment with 10 processes barely
- acknowledged existence of the 5th one)
- \item High average wait time (Imagine 1000 processes and how long we
- would have to wait)
-\end{itemize}
-Using pretty much any other algorithm we could get better results \cite{First
-come first serve}
-\begin{figure}[H]
- \caption{\href{https://commons.wikimedia.org/wiki/File:Process_states.svg}{[Process
- states and how they switch from wikimedia]}}
- \includegraphics[width=\textwidth]{procestates}
-\end{figure}
-
-\begin{thebibliography}{9}
- \bibitem{lab3 Manual} Manual in the laboratory 3 files.
- \bibitem{First come first serve}
- \href{https://www.studytonight.com/operating-system/first-come-first-serve}{[https://www.studytonight.com/operating-system/first-come-first-serve]}
- \bibitem{Other scheduling algorithms}
- \href{https://www.tutorialspoint.com/operating_system/os_process_scheduling_algorithms.htm}{[Tutorials
-point process scheduling algorithms]}
-\end{thebibliography}
+ \input{sections/01-introduction}
+ \input{sections/02-explanation-of-types-of-values-in}
+ \input{sections/03-scheduling-conf-settings}
+ \input{sections/04-two-processes}
+ \input{sections/05-five-processes}
+ \input{sections/06-ten-processes}
+ \input{sections/07-getting-process-to-be-blocked-4}
+ \input{sections/08-finishing-comments}
\end{document}
diff --git a/Programming/EOPSY/lab3/report/sections/01-introduction.tex b/Programming/EOPSY/lab3/report/sections/01-introduction.tex
new file mode 100644
index 00000000..1bb4536a
--- /dev/null
+++ b/Programming/EOPSY/lab3/report/sections/01-introduction.tex
@@ -0,0 +1,34 @@
+\section{Introduction}
+ALL TEXT SURROUNDED BY [] LIKE \cite{lab3 Manual} SHOULD BE CLICKABLE AND LEAD
+EITHER TO WEBPAGE OR PLACE IN THIS DOCUMENT \\
+The goal of the laboratory was to create three scenarios using config file and
+then investigate how those scenarios played out. \\
+Scenario 1: 2 Processes \\
+Scenario 2: 5 Processes \\
+Scenario 3: 10 Processes \\
+We had to get to know how the schedulers work, how they switch. \cite{lab3
+Manual}
+\paragraph{First come first serve}
+We used First come first serve algorithm $\rightarrow$ This algorithm simply executes the process which
+arrived first. The process that requests CPU as a first process gets the CPU
+first. It is easy to implement and understand. We just use Queue data structure
+and we pick processes from the head of the queue and new procesess are added at
+the tail of the queue. \cite{First come first serve}
+\begin{figure}[H]
+ \caption{First come first serve example graphic from
+ \href{https://www.geeksforgeeks.org/program-for-fcfs-cpu-scheduling-set-1/}{[Geeks for
+ Geeks]}}
+ \includegraphics[width=\textwidth]{FCFS}
+\end{figure}
+\paragraph{Other algorithms} \cite{Other scheduling algorithms}
+\begin{enumerate}
+ \item Shortest-Job-Next - Executes first processes that will take least
+ time to finish
+ \item Priority Scheduling - Each process gets assigned a prority and we
+ execute them from the process with highest priority to the
+ process with lowest prority
+ \item Round Robin Scheduling - We give each process a constant time to
+ execute, after this time expires regardless whether process
+ finished or not we go to another process untill all of them are
+ finished
+\end{enumerate}
diff --git a/Programming/EOPSY/lab3/report/sections/02-explanation-of-types-of-values-in.tex b/Programming/EOPSY/lab3/report/sections/02-explanation-of-types-of-values-in.tex
new file mode 100644
index 00000000..1c05e60d
--- /dev/null
+++ b/Programming/EOPSY/lab3/report/sections/02-explanation-of-types-of-values-in.tex
@@ -0,0 +1,30 @@
+\section{Explanation of types of values in summary results and summary
+process}
+\subsection{Summary Results}
+\begin{itemize}
+ \item Scheduling Type - Type of scheduling algorithm used
+ \item Scheduling Name - Name of the scheduling algorithm
+ \item Simulation Run Time - How long simulation run
+ \item Mean - Average runtime for the processes
+ \item Standard Deviation - Deviation from mean
+ \item Process \# - Process number
+ \item CPU Time - Total runtime for the process
+ \item IO Blocking - How long process runs before it is blocked for
+ input or output
+ \item CPU Completed - How long runtime completed for the process
+ \item CPU Blocked - How often the process was blocked
+\end{itemize}
+\cite{lab3 Manual}
+\subsection{Summary Processes}
+\begin{itemize}
+ \item process-number - Process number assigned by simulator
+ \item process-status - Registered - process can be used by scheduling
+ algorithm, I/O blocked - process blocked for input or output,
+ Completed - process met or exceeded execution time
+ \item cpu-time - Total amount of runtime allowed for this process
+ \item block-time - amount of time before blocking process
+ \item accumulated-time - how long the process has already executed
+ (appears twice)
+\end{itemize}
+\cite{lab3 Manual}
+
diff --git a/Programming/EOPSY/lab3/report/sections/03-scheduling-conf-settings.tex b/Programming/EOPSY/lab3/report/sections/03-scheduling-conf-settings.tex
new file mode 100644
index 00000000..de292fc8
--- /dev/null
+++ b/Programming/EOPSY/lab3/report/sections/03-scheduling-conf-settings.tex
@@ -0,0 +1,21 @@
+\section{Scheduling conf settings}
+\begin{lstlisting}
+// # of Process
+numprocess 2 or 5 or 10
+
+// mean deivation
+meandev 2000
+
+// standard deviation
+standdev 0
+
+// process # I/O blocking
+process 500
+process 500
+(more if we set numprocess to 5 or 10)
+
+// duration of the simulation in milliseconds
+runtime 10000
+
+\end{lstlisting}
+
diff --git a/Programming/EOPSY/lab3/report/sections/04-two-processes.tex b/Programming/EOPSY/lab3/report/sections/04-two-processes.tex
new file mode 100644
index 00000000..01d812d6
--- /dev/null
+++ b/Programming/EOPSY/lab3/report/sections/04-two-processes.tex
@@ -0,0 +1,61 @@
+\section{Two processes}
+\subsection{Summary Results file}
+
+
+\begin{lstlisting}
+Scheduling Type: Batch (Nonpreemptive)
+Scheduling Name: First-Come First-Served
+Simulation Run Time: 4000
+Mean: 2000
+Standard Deviation: 0
+\end{lstlisting}
+
+\begin{center}
+\begin{tabular}{| c | c | c | c | c |}
+\hline
+Process\# & CPU Time & IO Blocking & CPU Completed & CPU Blocked \\
+\hline
+0& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
+\hline
+1& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
+\hline
+\end{tabular}
+\end{center}
+
+\subsection{Summary Processes file}
+\begin{lstlisting}
+Process: 0 registered... (2000 500 0 0)
+Process: 0 I/O blocked... (2000 500 500 500)
+Process: 1 registered... (2000 500 0 0)
+Process: 1 I/O blocked... (2000 500 500 500)
+Process: 0 registered... (2000 500 500 500)
+Process: 0 I/O blocked... (2000 500 1000 1000)
+Process: 1 registered... (2000 500 500 500)
+Process: 1 I/O blocked... (2000 500 1000 1000)
+Process: 0 registered... (2000 500 1000 1000)
+Process: 0 I/O blocked... (2000 500 1500 1500)
+Process: 1 registered... (2000 500 1000 1000)
+Process: 1 I/O blocked... (2000 500 1500 1500)
+Process: 0 registered... (2000 500 1500 1500)
+Process: 0 completed... (2000 500 2000 2000)
+Process: 1 registered... (2000 500 1500 1500)
+Process: 1 completed... (2000 500 2000 2000)
+\end{lstlisting}
+\subsection{Comments}
+Scheduling type was Batch since I did not change it in SchedulingAlgorithm.java
+file \\
+Scheduling Name was First-Come First-Served since this is what what we use as
+described in README for this laboratory \\
+Simulation Run time is 4000 ms and NOT 10000 ms since the simulation finished
+before it exceeded this max time \\
+Mean is 2000 since this is a value I set in conf value according to laboratory
+task description, same with standard deviation equal to 0 and CPU Time equal to
+2000 ms \\
+IO Blocking is equal to 500 ms, this is a value which we specified in
+configuration file and since we did not exceeded the runtime parameter it stayed
+equal to 500 ms \\
+CPU completed is equal to 2000 since this is deviation we set in configuration
+settings and the runtime was not exceeded \\
+All processes blocked 3 times, analysing summary processes we can see that they
+blocked at 500 ms, 1000 ms and 1500 ms and at 2000 seconds they completed
+
diff --git a/Programming/EOPSY/lab3/report/sections/05-five-processes.tex b/Programming/EOPSY/lab3/report/sections/05-five-processes.tex
new file mode 100644
index 00000000..5293514a
--- /dev/null
+++ b/Programming/EOPSY/lab3/report/sections/05-five-processes.tex
@@ -0,0 +1,86 @@
+\section{Five processes}
+\newpage
+\subsection{Summary Results file}
+\begin{lstlisting}
+Scheduling Type: Batch (Nonpreemptive)
+Scheduling Name: First-Come First-Served
+Simulation Run Time: 10000
+Mean: 2000
+Standard Deviation: 0
+\end{lstlisting}
+\begin{center}
+\begin{tabular}{| c | c | c | c | c |}
+\hline
+Process\# & CPU Time & IO Blocking & CPU Completed & CPU Blocked \\
+\hline
+0& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
+\hline
+1& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
+\hline
+2& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
+\hline
+3& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
+\hline
+4& 2000 (ms)& 500 (ms)& 2000 (ms)& 3 times \\
+\hline
+\end{tabular}
+\end{center}
+
+\subsection{Summary Processes file}
+\begin{lstlisting}
+Process: 0 registered... (2000 500 0 0)
+Process: 0 I/O blocked... (2000 500 500 500)
+Process: 1 registered... (2000 500 0 0)
+Process: 1 I/O blocked... (2000 500 500 500)
+Process: 0 registered... (2000 500 500 500)
+Process: 0 I/O blocked... (2000 500 1000 1000)
+Process: 1 registered... (2000 500 500 500)
+Process: 1 I/O blocked... (2000 500 1000 1000)
+Process: 0 registered... (2000 500 1000 1000)
+Process: 0 I/O blocked... (2000 500 1500 1500)
+Process: 1 registered... (2000 500 1000 1000)
+Process: 1 I/O blocked... (2000 500 1500 1500)
+Process: 0 registered... (2000 500 1500 1500)
+Process: 0 completed... (2000 500 2000 2000)
+Process: 1 registered... (2000 500 1500 1500)
+Process: 1 completed... (2000 500 2000 2000)
+Process: 2 registered... (2000 500 0 0)
+Process: 2 I/O blocked... (2000 500 500 500)
+Process: 3 registered... (2000 500 0 0)
+Process: 3 I/O blocked... (2000 500 500 500)
+Process: 2 registered... (2000 500 500 500)
+Process: 2 I/O blocked... (2000 500 1000 1000)
+Process: 3 registered... (2000 500 500 500)
+Process: 3 I/O blocked... (2000 500 1000 1000)
+Process: 2 registered... (2000 500 1000 1000)
+Process: 2 I/O blocked... (2000 500 1500 1500)
+Process: 3 registered... (2000 500 1000 1000)
+Process: 3 I/O blocked... (2000 500 1500 1500)
+Process: 2 registered... (2000 500 1500 1500)
+Process: 2 completed... (2000 500 2000 2000)
+Process: 3 registered... (2000 500 1500 1500)
+Process: 3 completed... (2000 500 2000 2000)
+Process: 4 registered... (2000 500 0 0)
+Process: 4 I/O blocked... (2000 500 500 500)
+Process: 4 registered... (2000 500 500 500)
+Process: 4 I/O blocked... (2000 500 1000 1000)
+Process: 4 registered... (2000 500 1000 1000)
+Process: 4 I/O blocked... (2000 500 1500 1500)
+Process: 4 registered... (2000 500 1500 1500)
+\end{lstlisting}
+\subsection{Comments}
+Scheduling type was Batch since I did not change it in SchedulingAlgorithm.java
+file \\
+Scheduling Name was First-Come First-Served since this is what what we use as
+described in README for this laboratory \\
+Simulation run time is 10000 ms since it run untill the limit I set in conf file
+according to task description \\
+CPU blocking is set everywhere to 500 ms as in conf file \\
+Mean is 2000 since this is a value I set in conf value according to laboratory
+task description, same with standard deviation equal to 0 and CPU Time equal to
+2000 ms \\
+CPU completed is equal to expected 2000 ms, this makes sense since we had run
+time equal to 10000 ms and 5 procesess so each of them could take exactly the
+amonunt of time we set them to take.
+
+
diff --git a/Programming/EOPSY/lab3/report/sections/06-ten-processes.tex b/Programming/EOPSY/lab3/report/sections/06-ten-processes.tex
new file mode 100644
index 00000000..a0495427
--- /dev/null
+++ b/Programming/EOPSY/lab3/report/sections/06-ten-processes.tex
@@ -0,0 +1,93 @@
+\section{Ten processes}
+\subsection{Summary Results file}
+\begin{lstlisting}
+Scheduling Type: Batch (Nonpreemptive)
+Scheduling Name: First-Come First-Served
+Simulation Run Time: 10000
+Mean: 2000
+Standard Deviation: 0
+\end{lstlisting}
+\begin{center}
+\begin{tabular}{| c | c | c | c | c |}
+\hline
+Process\# & CPU Time & IO Blocking & CPU Completed & CPU Blocked \\
+\hline
+0 &2000 (ms) &500 (ms)& 2000 (ms)& 3 times \\
+\hline
+1 &2000 (ms) &500 (ms)& 2000 (ms)& 3 times \\
+\hline
+2 &2000 (ms) &500 (ms)& 2000 (ms)& 3 times \\
+\hline
+3 &2000 (ms) &500 (ms)& 2000 (ms)& 3 times \\
+\hline
+4 &2000 (ms) &500 (ms)& 1000 (ms)& 2 times \\
+\hline
+5 &2000 (ms) &500 (ms)& 1000 (ms)& 1 times \\
+\hline
+6 &2000 (ms) &500 (ms)& 0 (ms)& 0 times \\
+\hline
+7 &2000 (ms) &500 (ms)& 0 (ms)& 0 times \\
+\hline
+8 &2000 (ms) &500 (ms)& 0 (ms)& 0 times \\
+\hline
+9 &2000 (ms) &500 (ms)& 0 (ms)& 0 times \\
+\hline
+\end{tabular}
+\end{center}
+\subsection{Summary Processes file}
+\begin{lstlisting}
+Process: 0 registered... (2000 500 0 0)
+Process: 0 I/O blocked... (2000 500 500 500)
+Process: 1 registered... (2000 500 0 0)
+Process: 1 I/O blocked... (2000 500 500 500)
+Process: 0 registered... (2000 500 500 500)
+Process: 0 I/O blocked... (2000 500 1000 1000)
+Process: 1 registered... (2000 500 500 500)
+Process: 1 I/O blocked... (2000 500 1000 1000)
+Process: 0 registered... (2000 500 1000 1000)
+Process: 0 I/O blocked... (2000 500 1500 1500)
+Process: 1 registered... (2000 500 1000 1000)
+Process: 1 I/O blocked... (2000 500 1500 1500)
+Process: 0 registered... (2000 500 1500 1500)
+Process: 0 completed... (2000 500 2000 2000)
+Process: 1 registered... (2000 500 1500 1500)
+Process: 1 completed... (2000 500 2000 2000)
+Process: 2 registered... (2000 500 0 0)
+Process: 2 I/O blocked... (2000 500 500 500)
+Process: 3 registered... (2000 500 0 0)
+Process: 3 I/O blocked... (2000 500 500 500)
+Process: 2 registered... (2000 500 500 500)
+Process: 2 I/O blocked... (2000 500 1000 1000)
+Process: 3 registered... (2000 500 500 500)
+Process: 3 I/O blocked... (2000 500 1000 1000)
+Process: 2 registered... (2000 500 1000 1000)
+Process: 2 I/O blocked... (2000 500 1500 1500)
+Process: 3 registered... (2000 500 1000 1000)
+Process: 3 I/O blocked... (2000 500 1500 1500)
+Process: 2 registered... (2000 500 1500 1500)
+Process: 2 completed... (2000 500 2000 2000)
+Process: 3 registered... (2000 500 1500 1500)
+Process: 3 completed... (2000 500 2000 2000)
+Process: 4 registered... (2000 500 0 0)
+Process: 4 I/O blocked... (2000 500 500 500)
+Process: 5 registered... (2000 500 0 0)
+Process: 5 I/O blocked... (2000 500 500 500)
+Process: 4 registered... (2000 500 500 500)
+Process: 4 I/O blocked... (2000 500 1000 1000)
+Process: 5 registered... (2000 500 500 500)
+\end{lstlisting}
+\subsection{Comments}
+Scheduling type was Batch since I did not change it in SchedulingAlgorithm.java
+file \\
+Scheduling Name was First-Come First-Served since this is what what we use as
+described in README for this laboratory \\
+Simulation run time is 10000 ms since it run untill the limit I set in conf file
+according to task description \\
+IO Blocking set to 500 ms as in config file \\
+Mean is 2000 since this is a value I set in conf value according to laboratory
+task description, same with standard deviation equal to 0 and CPU Time equal to
+2000 ms \\
+CPU completed this time is equal to 2000 up to 4th process and then is equal to
+1000 ms for 5th and 6th and then it is equal to 0 ms, this means that the
+simulation exceeded the runtime before it had a chance to run all processes
+
diff --git a/Programming/EOPSY/lab3/report/sections/07-getting-process-to-be-blocked-4.tex b/Programming/EOPSY/lab3/report/sections/07-getting-process-to-be-blocked-4.tex
new file mode 100644
index 00000000..9e544b5c
--- /dev/null
+++ b/Programming/EOPSY/lab3/report/sections/07-getting-process-to-be-blocked-4.tex
@@ -0,0 +1,30 @@
+\section{Getting process to be blocked 4 times}
+Up untill now process got blocked for maximum of 3 times. This makes sense since
+since they get blocked every 500 ms and the runtime for single process is 2000
+ms, so they get blocked first time at 500 ms, second time at 1000 ms and third
+time at 1500 ms, at 2000 ms they finish execution so they do not get blocked. \\
+If we change runtime of process to 2001 ms we should get as the result them
+getting blocked 4 times! \\
+I changed meandev in scheduling.conf to 2001 and observed results:
+\subsection{Summary Results file}
+\begin{lstlisting}
+Scheduling Type: Batch (Nonpreemptive)
+Scheduling Name: First-Come First-Served
+Simulation Run Time: 6003
+Mean: 2001
+Standard Deviation: 0
+\end{lstlisting}
+\begin{center}
+ \begin{tabular}{| c | c | c | c | c |}
+ \hline
+ Process \#& CPU Time& IO Blocking& CPU Completed&
+ CPU Blocked \\ \hline
+ 0 & 2001 (ms)& 500 (ms)& 2001 (ms)&
+ 4 times \\ \hline
+ 1 & 2001 (ms)& 500 (ms)& 2001 (ms)&
+ 4 times \\ \hline
+ 2 & 2001 (ms)& 500 (ms)& 2001 (ms)&
+ 4 times \\ \hline
+\end{tabular}
+\end{center}
+Sure enough we got all of the processes blocked 4 times!
diff --git a/Programming/EOPSY/lab3/report/sections/08-finishing-comments.tex b/Programming/EOPSY/lab3/report/sections/08-finishing-comments.tex
new file mode 100644
index 00000000..635ff623
--- /dev/null
+++ b/Programming/EOPSY/lab3/report/sections/08-finishing-comments.tex
@@ -0,0 +1,33 @@
+\section{Finishing comments}
+We runned all the processes, get to know scheduling, get to know first come
+first served algorithm. \\
+There are upsides and downsides of first come first served algorithm:
+\\
+Upsides:
+\begin{itemize}
+ \item It is easy to implement
+ \item It is easy to understand
+\end{itemize}
+Downsides:
+\begin{itemize}
+ \item It is very inefficient (Last experiment with 10 processes barely
+ acknowledged existence of the 5th one)
+ \item High average wait time (Imagine 1000 processes and how long we
+ would have to wait)
+\end{itemize}
+Using pretty much any other algorithm we could get better results \cite{First
+come first serve}
+\begin{figure}[H]
+ \caption{\href{https://commons.wikimedia.org/wiki/File:Process_states.svg}{[Process
+ states and how they switch from wikimedia]}}
+ \includegraphics[width=\textwidth]{procestates}
+\end{figure}
+
+\begin{thebibliography}{9}
+ \bibitem{lab3 Manual} Manual in the laboratory 3 files.
+ \bibitem{First come first serve}
+ \href{https://www.studytonight.com/operating-system/first-come-first-serve}{[https://www.studytonight.com/operating-system/first-come-first-serve]}
+ \bibitem{Other scheduling algorithms}
+ \href{https://www.tutorialspoint.com/operating_system/os_process_scheduling_algorithms.htm}{[Tutorials
+point process scheduling algorithms]}
+\end{thebibliography}
diff --git a/Programming/EOPSY/lab4/report/report.tex b/Programming/EOPSY/lab4/report/report.tex
index 1bfbfa94..49ab8d98 100644
--- a/Programming/EOPSY/lab4/report/report.tex
+++ b/Programming/EOPSY/lab4/report/report.tex
@@ -9,291 +9,7 @@
\author{Krzysztof Rudnicki, 307585}
\date{\today}
\maketitle
-\section{Introduction}
-\subsection{Page replacement algorithms}
-\paragraph{First in First out}
-What page replacament algorithm is being used? \\
-We use FIFO (First in First out) page replacement algorithm for those laboratories as indicated
-by the PageFault.java file line 18
-\begin{figure}[H]
-\caption{PageFault.java file}
-\begin{lstlisting}[language=Java]
-[...]
-public class PageFault {
-
- /**
- * The page replacement algorithm for the memory management sumulator.
- * This method gets called whenever a page needs to be replaced.
- *
- * The page replacement algorithm included with the simulator is
- * FIFO (first-in first-out). A while or for loop should be used
- * to search through the current memory contents for a canidate
- * replacement page. In the case of FIFO the while loop is used
- * to find the proper page while making sure that virtPageNum is
- * not exceeded.
-[...]
-\end{lstlisting}
-\end{figure}
-All pages are stored in memory in a queue. Oldest page (First that came in) is
-in front of this queue. \\ When we need to replace the page we remove the page that
-is first in queue (so the one that came in as a first one, first in, first out)
-\\
-It is easy to explain and implement but in practical application it performs
-poorly. It is still used but usually we use modified version of it.
-\cite{Page Replacement Algorithms}
-\paragraph{Optimal Page Replacement}
-We replace pages which in the future will not be used for the longest time.
-This is purely theoretical algorithm. It is perfect but not doable in practice
-since operating systems can not know future requests. \\
-It is used as a benchmark against which we compare other algorithms.
-\cite{Page Replacement Algorithms}
-\paragraph{Least Recently Used}
-We replace page which was not used for the longest time. \\
-It is based on the idea that we will in future work on pages which we used
-heavily in the past. In theory its performance can be close to optimal one but
-in practice it is expensive to implement. \\
-Most expensive way of implementing this algorithm is using linked lists. Most
-recently used pages in front, least recently used in the back. Every time we
-reference memory we have to move elements in list which takes a lot of time. \\
-We can also use operating system counter \\
-This algorithm is often used in different cheaper modified versions.
-\cite{Page Replacement Algorithms}
-\cite{pageWiki}
-\subsection{Other}
-\paragraph{Memory Management Unit}
-Hardware unit which translates virtual memory to physical one.
-\cite{mmuWiki}
-\paragraph{Page fault}
-Exception raised when process wants to access page without preparations.
-Preparation consists of adding the mapping to process's virtual address space
-and/or loading page from a disk. MMU detects the fault but it is up to kernel
-and/or loading page from a disk.
-
-\section{Laboratory}
-\subsection{Instruction}
-\begin{enumerate}
- \item Map 8 pages of physical memory to the first 8 pages of virtual
- memory
- \item Go through each virtual page and read from one virtual memory
- address
-\end{enumerate}
-\subsection{Configuration}
-In memory.conf file I changed the memset and mapped first 8 pages of virtual
-memory to first 8 pages of physical memory (we could use any physical memory
-pages we wanted so I settled for this for sake of simplicity)
-\begin{figure}[H]
-\caption{memory.conf file}
-\begin{lstlisting}
-// memset virt page # physical page # R (read from)
-// M (modified) inMemTime (ns) lastTouchTime (ns)
-memset 0 0 0 0 0 0
-memset 1 1 0 0 0 0
-memset 2 2 0 0 0 0
-memset 3 3 0 0 0 0
-memset 4 4 0 0 0 0
-memset 5 5 0 0 0 0
-memset 6 6 0 0 0 0
-memset 7 7 0 0 0 0
-
-// enable_logging 'true' or 'false'
-// When true specify a log_file or leave blank for stdout
-enable_logging true
-
-// log_file
-// Where is the name of the file you want output
-// to be print to.
-log_file tracefile
-
-// page size, defaults to 2^14 and cannot be greater than 2^26
-// pagesize or <'power' num (base 2)>
-pagesize 16384
-
-// addressradix sets the radix
-// in which numerical values are displayed
-// 2 is the default value
-// addressradix
-addressradix 16
-
-// numpages sets the number of pages (physical and virtual)
-// 64 is the default value
-// numpages must be at least 2 and no more than 64
-// numpages
-numpages 64
-\end{lstlisting}
-\end{figure}
-We want to access each virtual page and read from one virtualk memory address of
-each page. \\
-To achieve this we need to read from pages in increments of pagesize. Which is
-set by default to 16384 and I do not change that. \\
-We have 64 pages so the last address we will read from will be address
-\[ 64 \cdot 16384 = 1048576 \]
-And since we start from address number 0 we need to substract
-\[ 1048576 - 16384 = 1032192 \]
-And so the last address we will read from is \textbf{1032192} \\
-We modify the commands file accordingly
-\begin{figure}
- \caption{commands file}
-\begin{lstlisting}
-READ 0
-READ 16384
-READ 32768
-READ 49152
-READ 65536
-READ 81920
-READ 98304
-READ 114688
-READ 131072
-READ 147456
-READ 163840
-READ 180224
-READ 196608
-READ 212992
-READ 229376
-READ 245760
-READ 262144
-READ 278528
-READ 294912
-READ 311296
-READ 327680
-READ 344064
-READ 360448
-READ 376832
-READ 393216
-READ 409600
-[...]
-READ 704512
-READ 720896
-READ 737280
-READ 753664
-READ 770048
-READ 786432
-READ 802816
-READ 819200
-READ 835584
-READ 851968
-READ 868352
-READ 884736
-READ 901120
-READ 917504
-READ 933888
-READ 950272
-READ 966656
-READ 983040
-READ 999424
-READ 1015808
-READ 1032192
-\end{lstlisting}
-\end{figure}
-\subsection{Procedure}
-After modifying config files I run the simulation using make compile and make
-run in work directory and go step by step through the program.
-\begin{figure}[H]
- \caption{tracefile}
-\begin{lstlisting}
-READ 0 ... okay
-READ 4000 ... okay
-READ 8000 ... okay
-READ c000 ... okay
-READ 10000 ... okay
-READ 14000 ... okay
-READ 18000 ... okay
-READ 1c000 ... okay
-READ 20000 ... okay
-READ 24000 ... okay
-READ 28000 ... okay
-READ 2c000 ... okay
-READ 30000 ... okay
-READ 34000 ... okay
-READ 38000 ... okay
-READ 3c000 ... okay
-READ 40000 ... okay
-READ 44000 ... okay
-[...]
-READ 54000 ... okay
-READ 58000 ... okay
-READ 5c000 ... okay
-READ 60000 ... okay
-READ 64000 ... okay
-READ 68000 ... okay
-READ 6c000 ... okay
-READ 70000 ... okay
-READ 74000 ... okay
-READ 78000 ... okay
-READ 7c000 ... okay
-READ 80000 ... page fault
-READ 84000 ... page fault
-READ 88000 ... page fault
-READ 8c000 ... page fault
-READ 90000 ... page fault
-READ 94000 ... page fault
-READ 98000 ... page fault
-READ 9c000 ... page fault
-READ a0000 ... page fault
-READ a4000 ... page fault
-[...]
-READ e4000 ... page fault
-READ e8000 ... page fault
-READ ec000 ... page fault
-READ f0000 ... page fault
-READ f4000 ... page fault
-READ f8000 ... page fault
-READ fc000 ... page fault%
-\end{lstlisting}
-\end{figure}
-As we can see mapping first 8 pages was successful. Their mapping was specified
-in memory.conf file and they were mapped as expected. \\
-Then pages up to 32 were also mapped correctly \\
-Then we get to page number 32 and we get page fault. We do not have mapping
-between this page and physical page so we use algorithm of first in first out
-and map page 32 to page 0, which was mapped to virtual page 0 in the first step.
-\\
-This process gets repeated up to the last page. We take the virtual page which
-was mapped to physical one as a first one and we map it to virtual page which
-got page fault error. \\
-This can be observed on following screens:
-\begin{figure}[H]
- \caption{Very start of application}
- \includegraphics[width=\linewidth]{mm1}
-\end{figure}
-\begin{figure}[H]
- \caption{First step correctly mapped}
- \includegraphics[width=\linewidth]{mm2}
-\end{figure}
-\begin{figure}[H]
- \caption{16th page correctly mapped}
- \includegraphics[width=\linewidth]{mm3}
-\end{figure}
-\begin{figure}[H]
- \caption{First page fault on 32th step}
- \includegraphics[width=\linewidth]{mm4}
-\end{figure}
-\begin{figure}[H]
- \caption{First in First out, we map page 0 physical to the page we just
- got page fault on}
- \includegraphics[width=\linewidth]{mm5}
-\end{figure}
-\begin{figure}[H]
- \caption{Again first in, first out}
- \includegraphics[width=\linewidth]{mm6}
-\end{figure}
-\begin{figure}[H]
- \caption{Final view of application}
- \includegraphics[width=\linewidth]{mm7}
-\end{figure}
-\section{Finishing comments}
-Both by looking at the source code and simulation results we can say that the
-simulation uses First in First out algorithm. First 8 pages were mapped
-correctly because of the memory.conf file, pages up to 32 were mapped correctly
-because they are mapped by default by the application. \\
-Then we got page faults which were resolved by first in first out algorithm.
-\begin{thebibliography}{9}
- \bibitem{mmuWiki} \href{https://en.wikipedia.org/wiki/Memory_management_unit}{Wiki Memory Management Unit}
- \bibitem{faultWiki} \href{https://en.wikipedia.org/wiki/Page_fault}{[Wiki Page Fault]}
-\bibitem{Page Replacement Algorithms}
-\href{https://www.geeksforgeeks.org/page-replacement-algorithms-in-operating-systems/}{[Geeks
-for Geeks page replacament algorithms]}
-\bibitem{pageWiki}
-\href{https://en.wikipedia.org/wiki/Page_replacement_algorithm}{Wikipedia Page
-replacament algorithm}
-\end{thebibliography}
+ \input{sections/01-introduction}
+ \input{sections/02-laboratory}
+ \input{sections/03-finishing-comments}
\end{document}
diff --git a/Programming/EOPSY/lab4/report/sections/01-introduction.tex b/Programming/EOPSY/lab4/report/sections/01-introduction.tex
new file mode 100644
index 00000000..a85643f0
--- /dev/null
+++ b/Programming/EOPSY/lab4/report/sections/01-introduction.tex
@@ -0,0 +1,60 @@
+\section{Introduction}
+\subsection{Page replacement algorithms}
+\paragraph{First in First out}
+What page replacament algorithm is being used? \\
+We use FIFO (First in First out) page replacement algorithm for those laboratories as indicated
+by the PageFault.java file line 18
+\begin{figure}[H]
+\caption{PageFault.java file}
+\begin{lstlisting}[language=Java]
+[...]
+public class PageFault {
+
+ /**
+ * The page replacement algorithm for the memory management sumulator.
+ * This method gets called whenever a page needs to be replaced.
+ *
+ * The page replacement algorithm included with the simulator is
+ * FIFO (first-in first-out). A while or for loop should be used
+ * to search through the current memory contents for a canidate
+ * replacement page. In the case of FIFO the while loop is used
+ * to find the proper page while making sure that virtPageNum is
+ * not exceeded.
+[...]
+\end{lstlisting}
+\end{figure}
+All pages are stored in memory in a queue. Oldest page (First that came in) is
+in front of this queue. \\ When we need to replace the page we remove the page that
+is first in queue (so the one that came in as a first one, first in, first out)
+\\
+It is easy to explain and implement but in practical application it performs
+poorly. It is still used but usually we use modified version of it.
+\cite{Page Replacement Algorithms}
+\paragraph{Optimal Page Replacement}
+We replace pages which in the future will not be used for the longest time.
+This is purely theoretical algorithm. It is perfect but not doable in practice
+since operating systems can not know future requests. \\
+It is used as a benchmark against which we compare other algorithms.
+\cite{Page Replacement Algorithms}
+\paragraph{Least Recently Used}
+We replace page which was not used for the longest time. \\
+It is based on the idea that we will in future work on pages which we used
+heavily in the past. In theory its performance can be close to optimal one but
+in practice it is expensive to implement. \\
+Most expensive way of implementing this algorithm is using linked lists. Most
+recently used pages in front, least recently used in the back. Every time we
+reference memory we have to move elements in list which takes a lot of time. \\
+We can also use operating system counter \\
+This algorithm is often used in different cheaper modified versions.
+\cite{Page Replacement Algorithms}
+\cite{pageWiki}
+\subsection{Other}
+\paragraph{Memory Management Unit}
+Hardware unit which translates virtual memory to physical one.
+\cite{mmuWiki}
+\paragraph{Page fault}
+Exception raised when process wants to access page without preparations.
+Preparation consists of adding the mapping to process's virtual address space
+and/or loading page from a disk. MMU detects the fault but it is up to kernel
+and/or loading page from a disk.
+
diff --git a/Programming/EOPSY/lab4/report/sections/02-laboratory.tex b/Programming/EOPSY/lab4/report/sections/02-laboratory.tex
new file mode 100644
index 00000000..69f0eb90
--- /dev/null
+++ b/Programming/EOPSY/lab4/report/sections/02-laboratory.tex
@@ -0,0 +1,211 @@
+\section{Laboratory}
+\subsection{Instruction}
+\begin{enumerate}
+ \item Map 8 pages of physical memory to the first 8 pages of virtual
+ memory
+ \item Go through each virtual page and read from one virtual memory
+ address
+\end{enumerate}
+\subsection{Configuration}
+In memory.conf file I changed the memset and mapped first 8 pages of virtual
+memory to first 8 pages of physical memory (we could use any physical memory
+pages we wanted so I settled for this for sake of simplicity)
+\begin{figure}[H]
+\caption{memory.conf file}
+\begin{lstlisting}
+// memset virt page # physical page # R (read from)
+// M (modified) inMemTime (ns) lastTouchTime (ns)
+memset 0 0 0 0 0 0
+memset 1 1 0 0 0 0
+memset 2 2 0 0 0 0
+memset 3 3 0 0 0 0
+memset 4 4 0 0 0 0
+memset 5 5 0 0 0 0
+memset 6 6 0 0 0 0
+memset 7 7 0 0 0 0
+
+// enable_logging 'true' or 'false'
+// When true specify a log_file or leave blank for stdout
+enable_logging true
+
+// log_file
+// Where is the name of the file you want output
+// to be print to.
+log_file tracefile
+
+// page size, defaults to 2^14 and cannot be greater than 2^26
+// pagesize or <'power' num (base 2)>
+pagesize 16384
+
+// addressradix sets the radix
+// in which numerical values are displayed
+// 2 is the default value
+// addressradix
+addressradix 16
+
+// numpages sets the number of pages (physical and virtual)
+// 64 is the default value
+// numpages must be at least 2 and no more than 64
+// numpages
+numpages 64
+\end{lstlisting}
+\end{figure}
+We want to access each virtual page and read from one virtualk memory address of
+each page. \\
+To achieve this we need to read from pages in increments of pagesize. Which is
+set by default to 16384 and I do not change that. \\
+We have 64 pages so the last address we will read from will be address
+\[ 64 \cdot 16384 = 1048576 \]
+And since we start from address number 0 we need to substract
+\[ 1048576 - 16384 = 1032192 \]
+And so the last address we will read from is \textbf{1032192} \\
+We modify the commands file accordingly
+\begin{figure}
+ \caption{commands file}
+\begin{lstlisting}
+READ 0
+READ 16384
+READ 32768
+READ 49152
+READ 65536
+READ 81920
+READ 98304
+READ 114688
+READ 131072
+READ 147456
+READ 163840
+READ 180224
+READ 196608
+READ 212992
+READ 229376
+READ 245760
+READ 262144
+READ 278528
+READ 294912
+READ 311296
+READ 327680
+READ 344064
+READ 360448
+READ 376832
+READ 393216
+READ 409600
+[...]
+READ 704512
+READ 720896
+READ 737280
+READ 753664
+READ 770048
+READ 786432
+READ 802816
+READ 819200
+READ 835584
+READ 851968
+READ 868352
+READ 884736
+READ 901120
+READ 917504
+READ 933888
+READ 950272
+READ 966656
+READ 983040
+READ 999424
+READ 1015808
+READ 1032192
+\end{lstlisting}
+\end{figure}
+\subsection{Procedure}
+After modifying config files I run the simulation using make compile and make
+run in work directory and go step by step through the program.
+\begin{figure}[H]
+ \caption{tracefile}
+\begin{lstlisting}
+READ 0 ... okay
+READ 4000 ... okay
+READ 8000 ... okay
+READ c000 ... okay
+READ 10000 ... okay
+READ 14000 ... okay
+READ 18000 ... okay
+READ 1c000 ... okay
+READ 20000 ... okay
+READ 24000 ... okay
+READ 28000 ... okay
+READ 2c000 ... okay
+READ 30000 ... okay
+READ 34000 ... okay
+READ 38000 ... okay
+READ 3c000 ... okay
+READ 40000 ... okay
+READ 44000 ... okay
+[...]
+READ 54000 ... okay
+READ 58000 ... okay
+READ 5c000 ... okay
+READ 60000 ... okay
+READ 64000 ... okay
+READ 68000 ... okay
+READ 6c000 ... okay
+READ 70000 ... okay
+READ 74000 ... okay
+READ 78000 ... okay
+READ 7c000 ... okay
+READ 80000 ... page fault
+READ 84000 ... page fault
+READ 88000 ... page fault
+READ 8c000 ... page fault
+READ 90000 ... page fault
+READ 94000 ... page fault
+READ 98000 ... page fault
+READ 9c000 ... page fault
+READ a0000 ... page fault
+READ a4000 ... page fault
+[...]
+READ e4000 ... page fault
+READ e8000 ... page fault
+READ ec000 ... page fault
+READ f0000 ... page fault
+READ f4000 ... page fault
+READ f8000 ... page fault
+READ fc000 ... page fault%
+\end{lstlisting}
+\end{figure}
+As we can see mapping first 8 pages was successful. Their mapping was specified
+in memory.conf file and they were mapped as expected. \\
+Then pages up to 32 were also mapped correctly \\
+Then we get to page number 32 and we get page fault. We do not have mapping
+between this page and physical page so we use algorithm of first in first out
+and map page 32 to page 0, which was mapped to virtual page 0 in the first step.
+\\
+This process gets repeated up to the last page. We take the virtual page which
+was mapped to physical one as a first one and we map it to virtual page which
+got page fault error. \\
+This can be observed on following screens:
+\begin{figure}[H]
+ \caption{Very start of application}
+ \includegraphics[width=\linewidth]{mm1}
+\end{figure}
+\begin{figure}[H]
+ \caption{First step correctly mapped}
+ \includegraphics[width=\linewidth]{mm2}
+\end{figure}
+\begin{figure}[H]
+ \caption{16th page correctly mapped}
+ \includegraphics[width=\linewidth]{mm3}
+\end{figure}
+\begin{figure}[H]
+ \caption{First page fault on 32th step}
+ \includegraphics[width=\linewidth]{mm4}
+\end{figure}
+\begin{figure}[H]
+ \caption{First in First out, we map page 0 physical to the page we just
+ got page fault on}
+ \includegraphics[width=\linewidth]{mm5}
+\end{figure}
+\begin{figure}[H]
+ \caption{Again first in, first out}
+ \includegraphics[width=\linewidth]{mm6}
+\end{figure}
+\begin{figure}[H]
+ \caption{Final view of application}
+ \includegraphics[width=\linewidth]{mm7}
+\end{figure}
diff --git a/Programming/EOPSY/lab4/report/sections/03-finishing-comments.tex b/Programming/EOPSY/lab4/report/sections/03-finishing-comments.tex
new file mode 100644
index 00000000..82d95f7d
--- /dev/null
+++ b/Programming/EOPSY/lab4/report/sections/03-finishing-comments.tex
@@ -0,0 +1,16 @@
+\section{Finishing comments}
+Both by looking at the source code and simulation results we can say that the
+simulation uses First in First out algorithm. First 8 pages were mapped
+correctly because of the memory.conf file, pages up to 32 were mapped correctly
+because they are mapped by default by the application. \\
+Then we got page faults which were resolved by first in first out algorithm.
+\begin{thebibliography}{9}
+ \bibitem{mmuWiki} \href{https://en.wikipedia.org/wiki/Memory_management_unit}{Wiki Memory Management Unit}
+ \bibitem{faultWiki} \href{https://en.wikipedia.org/wiki/Page_fault}{[Wiki Page Fault]}
+\bibitem{Page Replacement Algorithms}
+\href{https://www.geeksforgeeks.org/page-replacement-algorithms-in-operating-systems/}{[Geeks
+for Geeks page replacament algorithms]}
+\bibitem{pageWiki}
+\href{https://en.wikipedia.org/wiki/Page_replacement_algorithm}{Wikipedia Page
+replacament algorithm}
+\end{thebibliography}
diff --git a/Programming/PORR/report/first_part/main.tex b/Programming/PORR/report/first_part/main.tex
index b4222dd0..f12e9d96 100644
--- a/Programming/PORR/report/first_part/main.tex
+++ b/Programming/PORR/report/first_part/main.tex
@@ -37,338 +37,7 @@
\author{Kacper Górka, Krzysztof Rudnicki, Aleksandra Sobala}
\begin{document}
\maketitle
-\section{Zadanie}
-\paragraph{Metoda Richardsona}
-Metoda Richardsona służy do iteracyjnego rozwiązywania systemów równań liniowych postaci $Ax = b$.
-\\
-Pojedyńcza iteracja wygląda następująco:
-\[
- x^{(k+1)} = x^{(k)} + \omega (b - Ax^{(k)})
-\]
-Gdzie $\omega$ to skalar wybrany tak by $x^{(k)}$ zbiegało
-\paragraph{Wymagania}
-Mieliśmy za zadanie stworzyć program rozwiązujący układ równań dla wygenerowanych
-macierzy gęstych oraz dla macierzy rzadkich: \\
-\href{https://sparse.tamu.edu/Nemeth/nemeth12}{nemeth12} \\
-i \\
-\href{https://sparse.tamu.edu/Grund/poli3}{poli3}
-
-\section{Baza}
-\paragraph{Generowanie i zapisywanie macierzy}
-Macierze gęste są przez nas generowane przy użyciu biblioteki \textbf{numpy},
-aby przyśpieszyć obliczenia zapewniamy \textbf{bewzględna dominację wierszową głównej przekątnej} i
-upewniamy się że wygenerowana macierz jest \textbf{symetryczna i dodatnio określona} \\
-Macierze są potem zapisywane do pliku w
-formacie .npz, łącznie z ich wartościami własnymi, tak by
-skrócić działanie programu i ujednolicić testy
-\\ \null \\
-Macierze nemeth12 i poli3 są pobierane ze strony podanej wyżej, dla macierzy nemeth12 aby spełnić
-warunki stosowalności metody musieliśmy przemnożyć ją przez -1
-\paragraph{Testy}
-Do testów wykorzystujemy biblioteki \textbf{numpy} oraz \textbf{pytest} oraz wbudowane w Pythona
-narzędzia do mierzenia czasu. \\
-Sprawdzamy popawność naszych algorytmów poprzez porównanie naszych wyników z wynikami policzonymi przy
-wykorzystaniu funkcji np.linalg.norm z biblioteki numpy. Jeżeli nasze rozwiązanie różni się od
-rozwiązania numpy o mniej niż $8 \times 10^{-3}$ akceptujemy je jako poprawne \\
-Zarówno wielkośc macierzy, jej typ i typ metody użytej do zrównoleglenia Richardsona jest podawana jako
-parametr testów, pozwala nam to łatwo dodawać nowe metody zrównoleglenia bez zmiany kodu testów.
-\paragraph{Funkcje pomocnicze}
-Wszelkie podstawowe metody operacji na macierzach takie jak mnożenie wektorów, macierzy itp,
-napisaliśmy od zera, bez użycia zewnętrznych bibliotek, funkcje są zdefiniowane w pliku
-\textbf{linear\_algebra\_utils.py}
-\paragraph{Metoda Richardsona}
-Metoda Richardsona jest zaimplementowana w pliku \textbf{richardson\_method.py}, sprowadza się ona do
-pętli:
-\begin{lstlisting}[language=Python, basicstyle=\ttfamily\small, breaklines=true, caption=Python Code for Iterative Solver]
- for iteration in range(self.max_iterations):
- Ax = self.LinAlg.matrix_vector_multiply(self.A, x)
- residual = self.LinAlg.vector_vector_subtraction(self.b, Ax)
- x = self.LinAlg.vector_vector_addition(
- x,
- self.LinAlg.scalar_vector_multiply(self.omega, residual)
- )
- if self.LinAlg.SequentialLinearAlgebraUtils.vector_norm(residual) < self.tol:
- break
-\end{lstlisting}
-Dla różnych metod zrównoleglenia stosujemy różne implementacje podstawowych funkcji odpowiedzialnych za
-mnożenie macierzy przez wektor, odejmowanie wektorów itp. Ponownie, dzięki temu możemy łatwo dodawać nowe
-metody zrównoleglenia bez zmiany podstawowego kodu Richardsona
-
-
-\section{Zrównoleglenie}
-Wykorzystaliśmy 3 metody zrównoleglenia:
-\begin{enumerate}
- \item Tablice rozproszone
- \item Wątki
- \item Procesy
-\end{enumerate}
-\subsection{Procesy}
-Aby wykonać obliczenia na wielu rdzeniach procesora \textbf{jednocześnie} wykorzystujemy model w którym różne
-frakcje danych są przetwarzane przez oddzielne procesy. Dzięki temu dla dużych zbiorów danych możemy
-znacznie zwiększyć wydajnośc obliczeń \\
-W tym celu wykorzystujemy klasę \textbf{multiprocessing.Pool} z biblioteki \textbf{multiprocessing}.
-Wykorzystujemy ją do stworzenia puli procesów które potem niezależnie wykonują funkcje na różnych frakcjach
-danych.
-\paragraph{Funkcje}
-Procesy wykorzystujemy do:
-\begin{enumerate}
- \item Obliczenia iloczynu skalarnego - Metoda $dot\_product$ wykorzystuje pulę procesów do obliczenia iloczynów par elementów dwóch wektorów, a następnie sumuje te wyniki. Zrównoleglenie tej operacji jest korzystne, gdy mamy do czynienia z bardzo długimi wektorami.
- \item Mnożenia macierzy przez wektor - $matrix\_vector\_multiply$, każdy wiersz macierzy jest mnożony przez wektor w osobnym procesie. Dzięki temu każde takie mnożenie może być przeprowadzane równolegle, co jest szczególnie efektywne dla macierzy o dużym rozmiarze.
- \item Obliczenia normy wektora - Procesy są używane do obliczenia kwadratów poszczególnych elementów wektora, a następnie sumowanie tych wartości (także w procesach) umożliwia obliczenie pierwiastka kwadratowego z ich sumy, co daje normę wektora.
- \item Działania na wektorach i macierzach - Działania takie jak dodawanie i odejmowanie wektorów, dzielenie wektora przez skalar, czy mnożenie macierzy przez skalar, są przeprowadzane w segmentach, gdzie każdy segment jest przetwarzany przez osobny proces.
-\end{enumerate}
-\paragraph{Wyzwania}
-\begin{itemize}
- \item Zarządzanie procesami jest kosztowne - tworzenie i zarządzanie procesami jest droższe od wątków ze względu na większy narzut systemowy.
- \item Wymiana danych między procesami - wymaga serializacji i deserializacji danych, co może wprowadzić dodatkowe opóźnienia.
- \item Brak korzyści dla małych danych - w przypadku małych macierzy, gdzie rozmiar nie przekracza 5 tysięcy x 5 tysięcy elementów, zarządzanie procesami i koszty komunikacji międzyprocesowej mogą przewyższać korzyści wynikające z równoległego przetwarzania,
-\end{itemize}
-
-\subsection{Wątki}
-Do implementacji wątków użyto dwóch bibliotek, ThreadPoolExecutor która umożliwia zarządzanie pulą wątków i delegowanie zadań do wątków
-w sposób równoległy oraz funkcji partial z biblioteki functools która pozwala na tworzenie częściowo zainicjalizowanych funkcji.
-\paragraph{Funkcje}
-Wątki zaimplementowano w mnożeniu macierzy przeez wektor, odejmowaniu wektorów, dodawaniu wektorów oraz mnożeniu wektora przez skalar, metody zostają
-zrównoleglone poprzez podzielenie liczby wierszy macierzy między wątki, następnie ThreadPoolExecutor tworzy wątki i przekazuje im odpowiednie, niezależne
-części pracy do wykonania.
-\paragraph{Zalety}
-Zalety wykorzystania wątków to przede wszystkim szybki czas tworzenia i niszczenia wątków przez system operacyjny w porównaniu do procesów.
-Co więcej mają one dostęp do całej przestrzeni adresowej programu, co oszczędza niepotrzebne kopiowanie danych. Jedynie ich własny stos jest prywatny.
-
-\paragraph{ChatGPT}
-Po konsultacjach z prowadzącym użyliśmy chata-gpta do wygenerowania kodu dla wątków, rozwiązanie chata po kilku (ludzkich) poprawkach zadziałało ale jego dokładność była niesatysfakcjonująca,
-nie spełniała wymogów naszych testów
-
-\subsection{Tablice rozproszone}
-Tablice rozproszone dzielą macierz i przypisują każdą z jej części do konkretnego procesora.
-Procesory wykonują obliczenia na danych przechowywanych w ich lokalnej pamięci, co minimalizuje konieczność przesyłania danych pomiędzy węzłami. \\
-Tablice rozporoszone nie są natywnie wspierane przez Python-a, w związku z tym zostały zaimplementowane przy użyciu modułu array z biblioteki \textbf{dask}. \\
-Wszystkie podstawowe funkcje wykorzystywane w Richardsonie zostały zrównoleglone przy użyciu tablic rozproszonych.
-
-\paragraph{Wyzwania}
-\begin{itemize}
-\item Przy dużej zależności danych dochodzi do częstej komunikacji która obniża wydajnośc
-\item Elementy tablicy należy dobrze zbalansować aby procesory były równo obciążone
-\end{itemize}
-
-\subsection{MPI}
-Metoda zrównoleglenia przy użyciu MPI (Message Passing Interface) zrównolegla obliczenia na wielu procesorach
-\subsubsection{Podział pracy}
-\paragraph{Rozdzielenie macierzy i wektora}
-Macierz A i wektor b są dzielone na części, które każdy procesor przetwarza indywidualnie. Każdy proces obsługuje określony zakres wierszy macierzy A i odpowiadającą im część wektora b.
-\paragraph{Residuum r} Każdy proces oblicza swoją lokalną wartość residuum r, czyli różnicę pomiędzy obliczonym a rzeczywistym wynikiem.
-
-\subsubsection{Synchronizacja danych}
-\paragraph{Rozgłoszenie wspólnych wartości}
-Parametry takie jak współczynnik relaksacji (omega) są obliczane na jednym procesie (zwykle procesie 0) i rozsyłane do wszystkich procesów za pomocą funkcji \textbf{bcast}.
-
-\paragraph{Sumowanie wyników} Po obliczeniu lokalnego residuum przez każdy proces, dane te są sumowane w jedną globalną wartość przy użyciu funkcji \textbf{Allreduce}, co pozwala uwzględnić wkład wszystkich procesów
-
-\subsubsection{Iteracyjna aktualizacja}
-\paragraph{Równoległe aktualizowanie rozwiązania}
-Wektor rozwiązania x jest aktualizowany równolegle na każdym procesie na podstawie globalnego residuum. Każdy proces używa swojej części danych do modyfikacji wspólnego rozwiązania.
-
-\paragraph{Sprawdzenie warunku zbieżności} Norma residuum (miara błędu) jest sprawdzana po każdej iteracji. Gdy osiągnie tolerancję, algorytm przerywa dalsze obliczenia.
-
-
-\subsubsection{Efektywność i skalowalność}
-\paragraph{Wykorzystanie procesów}
-Procesy wykonują większość obliczeń równolegle, co znacząco zmniejsza czas potrzebny na rozwiązanie dużych układów równań.
-
-\paragraph{Minimalizacja komunikacji} Dane przesyłane między procesami są ograniczone do kluczowych informacji (np. residuum, parametry), co redukuje narzut związany z komunikacją.
-
-
-\subsubsection{Zalety}
-\begin{itemize}
- \item Skalowalność: Algorytm można stosować na dużej liczbie procesorów, co umożliwia rozwiązywanie bardzo dużych układów.
- \item Wydajność: Dzięki podziałowi pracy, obliczenia są szybsze niż w wersji sekwencyjnej.
- \item Elastyczność: Można go zastosować do różnych typów macierzy i układów równań.
-\end{itemize}
-\subsubsection{Wady}
-\begin{itemize}
- \item Narzut komunikacyjny: Przy bardzo dużej liczbie procesorów koszt komunikacji może zniwelować zysk z równoleglenia.
- \item Obciążenie procesorów: Jeśli rozmiar macierzy nie dzieli się równomiernie między procesy, niektóre procesory mogą być mniej obciążone.
-\end{itemize}
-
-
-\subsection{Wyniki}
-\begin{table}[H]
- \centering
- \begin{tabular}{|l|l|l|l|l|l|}
- \hline
- \textbf{Wielkość/Typ} & \textbf{Sekwencyjnie [s]} & \textbf{Procesy [s]} & \textbf{Wątki [s]} & \textbf{Tablice [s]} & \textbf{MPI [s]} \\ \hline
- 2 & 7.784e-05 & 2.896e+00 & 9.772e-03 & 8.817e-02 & 1.737e-02 \\ \hline
- 5 & 1.746e-04 & 3.897e+00 & 1.960e-02 & 9.443e-02 & 5.670e-04 \\ \hline
- 10 & 6.769e-04 & 7.073e+00 & 2.895e-02 & 1.674e-01 & 1.766e-02 \\ \hline
- 50 & 2.735e-02 & 2.153e+01 & 1.059e-01 & 4.899e-01 & 1.808e-02 \\ \hline
- 100 & 1.195e-01 & 2.167e+01 & 2.067e-01 & 6.921e-01 & 1.946e-02 \\ \hline
- 300 & 7.863e-01 & 2.363e+01 & 9.558e-01 & 7.461e-01 & 4.492e-02 \\ \hline
- 500 & 2.206e+00 & 2.657e+01 & 2.494e+00 & 8.521e-01 & 9.526e-02 \\ \hline
- 750 & 4.785e+00 & 2.939e+01 & 5.520e+00 & 9.408e-01 & 2.832e-01 \\ \hline
- 1000 & 8.689e+00 & 3.259e+01 & 9.672e+00 & 1.201e+00 & 5.430e-01 \\ \hline
- 5000 & 2.170e+02 & 9.077e+01 & 2.402e+02 & 1.368e+01 & 7.480e+01 \\ \hline
- 10000 & 8.615e+02 & 2.378e+02 & 9.705e+02 & 4.643e+01 & 4.046e+02 \\ \hline
- nemeth12 & 3.630e+02 & 1.105e+02 & 3.863e+02 & 2.133e+01 & 4.427e+01 \\ \hline
- poli3 & 1.291e+03 & 1.187e+03 & 1.363e+03 & 7.029e+01 & \textit{N/A} \\ \hline
- \end{tabular}
- \caption{Wyniki dla różnych rozmiarów i zrównolegleń (sekwencyjne, procesy, wątki, tablice rozproszone i MPI)}
- \label{tab:test_results_full}
-\end{table}
-
-\begin{figure}[H]
- \centering
- \begin{tikzpicture}
- \begin{loglogaxis}[
- width=12.99cm,
- height=12.99cm,
- xlabel={Wielkość},
- ylabel={Czas [s]},
- title={Wyniki dla różnych zrównolegleń},
- grid=both,
- legend pos=north west,
- legend style={font=\small},
- grid style={dashed, gray!30},
- cycle list name=color list % Use the default color list for different lines
- ]
-
- % Sequential
- \addplot[
- mark=o,
- line width=0.8pt,
- color=blue
- ] table[x index=0, y index=1] {
- 2 7.784e-05
- 5 1.746e-04
- 10 6.769e-04
- 50 2.735e-02
- 100 1.195e-01
- 300 7.863e-01
- 500 2.206e+00
- 750 4.785e+00
- 1000 8.689e+00
- 5000 2.170e+02
- 10000 8.615e+02
- };
- \addlegendentry{Sekwencyjnie}
-
- % Processes
- \addplot[
- mark=o,
- line width=0.8pt,
- color=red
- ] table[x index=0, y index=1] {
- 2 2.896e+00
- 5 3.897e+00
- 10 7.073e+00
- 50 2.153e+01
- 100 2.167e+01
- 300 2.363e+01
- 500 2.657e+01
- 750 2.939e+01
- 1000 3.259e+01
- 5000 9.077e+01
- 10000 2.378e+02
- };
- \addlegendentry{Procesy}
-
- % Threads
- \addplot[
- mark=o,
- line width=0.8pt,
- color=green
- ] table[x index=0, y index=1] {
- 2 9.772e-03
- 5 1.960e-02
- 10 2.895e-02
- 50 1.059e-01
- 100 2.067e-01
- 300 9.558e-01
- 500 2.494e+00
- 750 5.520e+00
- 1000 9.672e+00
- 5000 2.402e+02
- 10000 9.705e+02
- };
- \addlegendentry{Wątki}
-
- % Distributed Arrays
- \addplot[
- mark=o,
- line width=0.8pt,
- color=purple
- ] table[x index=0, y index=1] {
- 2 8.817e-02
- 5 9.443e-02
- 10 1.674e-01
- 50 4.899e-01
- 100 6.921e-01
- 300 7.461e-01
- 500 8.521e-01
- 750 9.408e-01
- 1000 1.201e+00
- 5000 1.368e+01
- 10000 4.643e+01
- };
- \addlegendentry{Tablice}
-
- \addplot[
- mark=triangle,
- line width=0.8pt,
- color=orange
- ] table[x index=0, y index=1] {
- 2 5.123e-05
- 5 1.234e-04
- 10 4.567e-04
- 50 1.234e-02
- 100 5.678e-02
- 300 3.456e-01
- 500 1.234e+00
- 750 2.345e+00
- 1000 4.567e+00
- 5000 1.234e+02
- 10000 4.567e+02
- };
- \addlegendentry{MPI}
-
- \end{loglogaxis}
- \end{tikzpicture}
-\end{figure}
-
-\subsection{Przyśpieszenie według definicji z wykładu}
-$S(n, p) = \frac{T(n, 1)}{T(n, p)} $
-\begin{table}[H]
- \centering
- \begin{tabular}{|l|l|l|l|l|}
- \hline
- \textbf{Wielkość/Typ} & \textbf{S(n,p) - Procesy} & \textbf{S(n,p) - Wątki} & \textbf{S(n,p) - Tablice} & \textbf{S(n,p) - MPI} \\ \hline
- 2 & 2.69e-05 & 8.17e-03 & 8.83e-04 & 1.52e+00 \\ \hline
- 5 & 4.48e-05 & 8.91e-03 & 1.85e-03 & 1.41e+00 \\ \hline
- 10 & 9.57e-05 & 2.34e-02 & 4.04e-03 & 1.48e+00 \\ \hline
- 50 & 1.27e-03 & 2.58e-01 & 5.58e-02 & 2.15e+00 \\ \hline
- 100 & 5.52e-03 & 5.78e-01 & 1.73e-01 & 2.11e+00 \\ \hline
- 300 & 3.33e-02 & 8.23e-01 & 1.05e+00 & 2.27e+00 \\ \hline
- 500 & 8.30e-02 & 8.85e-01 & 2.59e+00 & 1.79e+00 \\ \hline
- 750 & 1.63e-01 & 8.67e-01 & 5.08e+00 & 2.04e+00 \\ \hline
- 1000 & 2.67e-01 & 8.98e-01 & 7.24e+00 & 1.90e+00 \\ \hline
- 5000 & 2.39e+00 & 9.04e-01 & 1.59e+01 & 1.76e+00 \\ \hline
- 10000 & 3.62e+00 & 8.88e-01 & 1.86e+01 & 1.89e+00 \\ \hline
- nemeth12 & 3.28e+00 & 9.40e-01 & 1.70e+01 & 1.95e+00 \\ \hline
- poli3 & 1.09e+00 & 9.47e-01 & 1.84e+01 & \textit{N/A} \\ \hline
- \end{tabular}
- \label{tab:calculated_speedup}
-\end{table}
-
-\subsubsection{Wnioski}
-Zrównoleglenie metodą tablic rozproszonych okazało się najbardziej efektywne. Wynika to prawdopodobnie z wykorzystania zewnętrznej biblioteki
-dedykowanej i rozwijanej przyśpieszaniu obliczeń na tablicach rozproszonych. W przypadku procesów zrównoleglenie przyśpieszyło obliczenia dla
-dużych (większych niż 5000 na 5000) macierzy i spowolniło dla mniejszych, co jest zgodnę z teorią opisaną w seksji poświęconej procesom.
- \\
-\paragraph{Wątki} Dla wątków nie udało się uzyskać przyśpieszenia ani dla małych ani dla dużych macierzy, podejrzewamy że jest to spowodowane przez nieefektywne
-zarządzanie wątkami przez Python-a
-\\
-\paragraph{MPI} Rozwiązanie nie działa dla dużych macierzy, takich jak poli3, ze względu na ograniczenia związane z serializacją i komunikacją w bibliotekach MPI oraz sposób,
-w jaki macierze są rozgłaszane między procesami. W przypadku przesyłania dużych obiektów, takich jak masywne macierze w formacie numpy.ndarray,
-funkcja bcast używa mechanizmu pickle do serializacji danych. Jednak mechanizm ten ma ograniczenia co do rozmiaru i złożoności przesyłanych obiektów,
-co prowadzi do błędów, takich jak OverflowError.
-
+ \input{sections/01-zadanie}
+ \input{sections/02-baza}
+ \input{sections/03-zrownoleglenie}
\end{document}
diff --git a/Programming/PORR/report/first_part/sections/01-zadanie.tex b/Programming/PORR/report/first_part/sections/01-zadanie.tex
new file mode 100644
index 00000000..a4180a48
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/01-zadanie.tex
@@ -0,0 +1,16 @@
+\section{Zadanie}
+\paragraph{Metoda Richardsona}
+Metoda Richardsona służy do iteracyjnego rozwiązywania systemów równań liniowych postaci $Ax = b$.
+\\
+Pojedyńcza iteracja wygląda następująco:
+\[
+ x^{(k+1)} = x^{(k)} + \omega (b - Ax^{(k)})
+\]
+Gdzie $\omega$ to skalar wybrany tak by $x^{(k)}$ zbiegało
+\paragraph{Wymagania}
+Mieliśmy za zadanie stworzyć program rozwiązujący układ równań dla wygenerowanych
+macierzy gęstych oraz dla macierzy rzadkich: \\
+\href{https://sparse.tamu.edu/Nemeth/nemeth12}{nemeth12} \\
+i \\
+\href{https://sparse.tamu.edu/Grund/poli3}{poli3}
+
diff --git a/Programming/PORR/report/first_part/sections/02-baza.tex b/Programming/PORR/report/first_part/sections/02-baza.tex
new file mode 100644
index 00000000..c69431ad
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/02-baza.tex
@@ -0,0 +1,42 @@
+\section{Baza}
+\paragraph{Generowanie i zapisywanie macierzy}
+Macierze gęste są przez nas generowane przy użyciu biblioteki \textbf{numpy},
+aby przyśpieszyć obliczenia zapewniamy \textbf{bewzględna dominację wierszową głównej przekątnej} i
+upewniamy się że wygenerowana macierz jest \textbf{symetryczna i dodatnio określona} \\
+Macierze są potem zapisywane do pliku w
+formacie .npz, łącznie z ich wartościami własnymi, tak by
+skrócić działanie programu i ujednolicić testy
+\\ \null \\
+Macierze nemeth12 i poli3 są pobierane ze strony podanej wyżej, dla macierzy nemeth12 aby spełnić
+warunki stosowalności metody musieliśmy przemnożyć ją przez -1
+\paragraph{Testy}
+Do testów wykorzystujemy biblioteki \textbf{numpy} oraz \textbf{pytest} oraz wbudowane w Pythona
+narzędzia do mierzenia czasu. \\
+Sprawdzamy popawność naszych algorytmów poprzez porównanie naszych wyników z wynikami policzonymi przy
+wykorzystaniu funkcji np.linalg.norm z biblioteki numpy. Jeżeli nasze rozwiązanie różni się od
+rozwiązania numpy o mniej niż $8 \times 10^{-3}$ akceptujemy je jako poprawne \\
+Zarówno wielkośc macierzy, jej typ i typ metody użytej do zrównoleglenia Richardsona jest podawana jako
+parametr testów, pozwala nam to łatwo dodawać nowe metody zrównoleglenia bez zmiany kodu testów.
+\paragraph{Funkcje pomocnicze}
+Wszelkie podstawowe metody operacji na macierzach takie jak mnożenie wektorów, macierzy itp,
+napisaliśmy od zera, bez użycia zewnętrznych bibliotek, funkcje są zdefiniowane w pliku
+\textbf{linear\_algebra\_utils.py}
+\paragraph{Metoda Richardsona}
+Metoda Richardsona jest zaimplementowana w pliku \textbf{richardson\_method.py}, sprowadza się ona do
+pętli:
+\begin{lstlisting}[language=Python, basicstyle=\ttfamily\small, breaklines=true, caption=Python Code for Iterative Solver]
+ for iteration in range(self.max_iterations):
+ Ax = self.LinAlg.matrix_vector_multiply(self.A, x)
+ residual = self.LinAlg.vector_vector_subtraction(self.b, Ax)
+ x = self.LinAlg.vector_vector_addition(
+ x,
+ self.LinAlg.scalar_vector_multiply(self.omega, residual)
+ )
+ if self.LinAlg.SequentialLinearAlgebraUtils.vector_norm(residual) < self.tol:
+ break
+\end{lstlisting}
+Dla różnych metod zrównoleglenia stosujemy różne implementacje podstawowych funkcji odpowiedzialnych za
+mnożenie macierzy przez wektor, odejmowanie wektorów itp. Ponownie, dzięki temu możemy łatwo dodawać nowe
+metody zrównoleglenia bez zmiany podstawowego kodu Richardsona
+
+
diff --git a/Programming/PORR/report/first_part/sections/03-zrownoleglenie.tex b/Programming/PORR/report/first_part/sections/03-zrownoleglenie.tex
new file mode 100644
index 00000000..c7038fde
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/03-zrownoleglenie.tex
@@ -0,0 +1,13 @@
+\section{Zrównoleglenie}
+Wykorzystaliśmy 3 metody zrównoleglenia:
+\begin{enumerate}
+ \item Tablice rozproszone
+ \item Wątki
+ \item Procesy
+\end{enumerate}
+ \input{sections/03-zrownoleglenie/01-procesy}
+ \input{sections/03-zrownoleglenie/02-watki}
+ \input{sections/03-zrownoleglenie/03-tablice-rozproszone}
+ \input{sections/03-zrownoleglenie/04-mpi}
+ \input{sections/03-zrownoleglenie/05-wyniki}
+ \input{sections/03-zrownoleglenie/06-przyspieszenie-wedlug-definicji-z-wykladu}
diff --git a/Programming/PORR/report/first_part/sections/03-zrownoleglenie/01-procesy.tex b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/01-procesy.tex
new file mode 100644
index 00000000..8eadb451
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/01-procesy.tex
@@ -0,0 +1,22 @@
+\subsection{Procesy}
+Aby wykonać obliczenia na wielu rdzeniach procesora \textbf{jednocześnie} wykorzystujemy model w którym różne
+frakcje danych są przetwarzane przez oddzielne procesy. Dzięki temu dla dużych zbiorów danych możemy
+znacznie zwiększyć wydajnośc obliczeń \\
+W tym celu wykorzystujemy klasę \textbf{multiprocessing.Pool} z biblioteki \textbf{multiprocessing}.
+Wykorzystujemy ją do stworzenia puli procesów które potem niezależnie wykonują funkcje na różnych frakcjach
+danych.
+\paragraph{Funkcje}
+Procesy wykorzystujemy do:
+\begin{enumerate}
+ \item Obliczenia iloczynu skalarnego - Metoda $dot\_product$ wykorzystuje pulę procesów do obliczenia iloczynów par elementów dwóch wektorów, a następnie sumuje te wyniki. Zrównoleglenie tej operacji jest korzystne, gdy mamy do czynienia z bardzo długimi wektorami.
+ \item Mnożenia macierzy przez wektor - $matrix\_vector\_multiply$, każdy wiersz macierzy jest mnożony przez wektor w osobnym procesie. Dzięki temu każde takie mnożenie może być przeprowadzane równolegle, co jest szczególnie efektywne dla macierzy o dużym rozmiarze.
+ \item Obliczenia normy wektora - Procesy są używane do obliczenia kwadratów poszczególnych elementów wektora, a następnie sumowanie tych wartości (także w procesach) umożliwia obliczenie pierwiastka kwadratowego z ich sumy, co daje normę wektora.
+ \item Działania na wektorach i macierzach - Działania takie jak dodawanie i odejmowanie wektorów, dzielenie wektora przez skalar, czy mnożenie macierzy przez skalar, są przeprowadzane w segmentach, gdzie każdy segment jest przetwarzany przez osobny proces.
+\end{enumerate}
+\paragraph{Wyzwania}
+\begin{itemize}
+ \item Zarządzanie procesami jest kosztowne - tworzenie i zarządzanie procesami jest droższe od wątków ze względu na większy narzut systemowy.
+ \item Wymiana danych między procesami - wymaga serializacji i deserializacji danych, co może wprowadzić dodatkowe opóźnienia.
+ \item Brak korzyści dla małych danych - w przypadku małych macierzy, gdzie rozmiar nie przekracza 5 tysięcy x 5 tysięcy elementów, zarządzanie procesami i koszty komunikacji międzyprocesowej mogą przewyższać korzyści wynikające z równoległego przetwarzania,
+\end{itemize}
+
diff --git a/Programming/PORR/report/first_part/sections/03-zrownoleglenie/02-watki.tex b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/02-watki.tex
new file mode 100644
index 00000000..4bc7b0ae
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/02-watki.tex
@@ -0,0 +1,15 @@
+\subsection{Wątki}
+Do implementacji wątków użyto dwóch bibliotek, ThreadPoolExecutor która umożliwia zarządzanie pulą wątków i delegowanie zadań do wątków
+w sposób równoległy oraz funkcji partial z biblioteki functools która pozwala na tworzenie częściowo zainicjalizowanych funkcji.
+\paragraph{Funkcje}
+Wątki zaimplementowano w mnożeniu macierzy przeez wektor, odejmowaniu wektorów, dodawaniu wektorów oraz mnożeniu wektora przez skalar, metody zostają
+zrównoleglone poprzez podzielenie liczby wierszy macierzy między wątki, następnie ThreadPoolExecutor tworzy wątki i przekazuje im odpowiednie, niezależne
+części pracy do wykonania.
+\paragraph{Zalety}
+Zalety wykorzystania wątków to przede wszystkim szybki czas tworzenia i niszczenia wątków przez system operacyjny w porównaniu do procesów.
+Co więcej mają one dostęp do całej przestrzeni adresowej programu, co oszczędza niepotrzebne kopiowanie danych. Jedynie ich własny stos jest prywatny.
+
+\paragraph{ChatGPT}
+Po konsultacjach z prowadzącym użyliśmy chata-gpta do wygenerowania kodu dla wątków, rozwiązanie chata po kilku (ludzkich) poprawkach zadziałało ale jego dokładność była niesatysfakcjonująca,
+nie spełniała wymogów naszych testów
+
diff --git a/Programming/PORR/report/first_part/sections/03-zrownoleglenie/03-tablice-rozproszone.tex b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/03-tablice-rozproszone.tex
new file mode 100644
index 00000000..e24ceb81
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/03-tablice-rozproszone.tex
@@ -0,0 +1,12 @@
+\subsection{Tablice rozproszone}
+Tablice rozproszone dzielą macierz i przypisują każdą z jej części do konkretnego procesora.
+Procesory wykonują obliczenia na danych przechowywanych w ich lokalnej pamięci, co minimalizuje konieczność przesyłania danych pomiędzy węzłami. \\
+Tablice rozporoszone nie są natywnie wspierane przez Python-a, w związku z tym zostały zaimplementowane przy użyciu modułu array z biblioteki \textbf{dask}. \\
+Wszystkie podstawowe funkcje wykorzystywane w Richardsonie zostały zrównoleglone przy użyciu tablic rozproszonych.
+
+\paragraph{Wyzwania}
+\begin{itemize}
+\item Przy dużej zależności danych dochodzi do częstej komunikacji która obniża wydajnośc
+\item Elementy tablicy należy dobrze zbalansować aby procesory były równo obciążone
+\end{itemize}
+
diff --git a/Programming/PORR/report/first_part/sections/03-zrownoleglenie/04-mpi.tex b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/04-mpi.tex
new file mode 100644
index 00000000..eeebbed7
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/04-mpi.tex
@@ -0,0 +1,40 @@
+\subsection{MPI}
+Metoda zrównoleglenia przy użyciu MPI (Message Passing Interface) zrównolegla obliczenia na wielu procesorach
+\subsubsection{Podział pracy}
+\paragraph{Rozdzielenie macierzy i wektora}
+Macierz A i wektor b są dzielone na części, które każdy procesor przetwarza indywidualnie. Każdy proces obsługuje określony zakres wierszy macierzy A i odpowiadającą im część wektora b.
+\paragraph{Residuum r} Każdy proces oblicza swoją lokalną wartość residuum r, czyli różnicę pomiędzy obliczonym a rzeczywistym wynikiem.
+
+\subsubsection{Synchronizacja danych}
+\paragraph{Rozgłoszenie wspólnych wartości}
+Parametry takie jak współczynnik relaksacji (omega) są obliczane na jednym procesie (zwykle procesie 0) i rozsyłane do wszystkich procesów za pomocą funkcji \textbf{bcast}.
+
+\paragraph{Sumowanie wyników} Po obliczeniu lokalnego residuum przez każdy proces, dane te są sumowane w jedną globalną wartość przy użyciu funkcji \textbf{Allreduce}, co pozwala uwzględnić wkład wszystkich procesów
+
+\subsubsection{Iteracyjna aktualizacja}
+\paragraph{Równoległe aktualizowanie rozwiązania}
+Wektor rozwiązania x jest aktualizowany równolegle na każdym procesie na podstawie globalnego residuum. Każdy proces używa swojej części danych do modyfikacji wspólnego rozwiązania.
+
+\paragraph{Sprawdzenie warunku zbieżności} Norma residuum (miara błędu) jest sprawdzana po każdej iteracji. Gdy osiągnie tolerancję, algorytm przerywa dalsze obliczenia.
+
+
+\subsubsection{Efektywność i skalowalność}
+\paragraph{Wykorzystanie procesów}
+Procesy wykonują większość obliczeń równolegle, co znacząco zmniejsza czas potrzebny na rozwiązanie dużych układów równań.
+
+\paragraph{Minimalizacja komunikacji} Dane przesyłane między procesami są ograniczone do kluczowych informacji (np. residuum, parametry), co redukuje narzut związany z komunikacją.
+
+
+\subsubsection{Zalety}
+\begin{itemize}
+ \item Skalowalność: Algorytm można stosować na dużej liczbie procesorów, co umożliwia rozwiązywanie bardzo dużych układów.
+ \item Wydajność: Dzięki podziałowi pracy, obliczenia są szybsze niż w wersji sekwencyjnej.
+ \item Elastyczność: Można go zastosować do różnych typów macierzy i układów równań.
+\end{itemize}
+\subsubsection{Wady}
+\begin{itemize}
+ \item Narzut komunikacyjny: Przy bardzo dużej liczbie procesorów koszt komunikacji może zniwelować zysk z równoleglenia.
+ \item Obciążenie procesorów: Jeśli rozmiar macierzy nie dzieli się równomiernie między procesy, niektóre procesory mogą być mniej obciążone.
+\end{itemize}
+
+
diff --git a/Programming/PORR/report/first_part/sections/03-zrownoleglenie/05-wyniki.tex b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/05-wyniki.tex
new file mode 100644
index 00000000..ee79e017
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/05-wyniki.tex
@@ -0,0 +1,143 @@
+\subsection{Wyniki}
+\begin{table}[H]
+ \centering
+ \begin{tabular}{|l|l|l|l|l|l|}
+ \hline
+ \textbf{Wielkość/Typ} & \textbf{Sekwencyjnie [s]} & \textbf{Procesy [s]} & \textbf{Wątki [s]} & \textbf{Tablice [s]} & \textbf{MPI [s]} \\ \hline
+ 2 & 7.784e-05 & 2.896e+00 & 9.772e-03 & 8.817e-02 & 1.737e-02 \\ \hline
+ 5 & 1.746e-04 & 3.897e+00 & 1.960e-02 & 9.443e-02 & 5.670e-04 \\ \hline
+ 10 & 6.769e-04 & 7.073e+00 & 2.895e-02 & 1.674e-01 & 1.766e-02 \\ \hline
+ 50 & 2.735e-02 & 2.153e+01 & 1.059e-01 & 4.899e-01 & 1.808e-02 \\ \hline
+ 100 & 1.195e-01 & 2.167e+01 & 2.067e-01 & 6.921e-01 & 1.946e-02 \\ \hline
+ 300 & 7.863e-01 & 2.363e+01 & 9.558e-01 & 7.461e-01 & 4.492e-02 \\ \hline
+ 500 & 2.206e+00 & 2.657e+01 & 2.494e+00 & 8.521e-01 & 9.526e-02 \\ \hline
+ 750 & 4.785e+00 & 2.939e+01 & 5.520e+00 & 9.408e-01 & 2.832e-01 \\ \hline
+ 1000 & 8.689e+00 & 3.259e+01 & 9.672e+00 & 1.201e+00 & 5.430e-01 \\ \hline
+ 5000 & 2.170e+02 & 9.077e+01 & 2.402e+02 & 1.368e+01 & 7.480e+01 \\ \hline
+ 10000 & 8.615e+02 & 2.378e+02 & 9.705e+02 & 4.643e+01 & 4.046e+02 \\ \hline
+ nemeth12 & 3.630e+02 & 1.105e+02 & 3.863e+02 & 2.133e+01 & 4.427e+01 \\ \hline
+ poli3 & 1.291e+03 & 1.187e+03 & 1.363e+03 & 7.029e+01 & \textit{N/A} \\ \hline
+ \end{tabular}
+ \caption{Wyniki dla różnych rozmiarów i zrównolegleń (sekwencyjne, procesy, wątki, tablice rozproszone i MPI)}
+ \label{tab:test_results_full}
+\end{table}
+
+\begin{figure}[H]
+ \centering
+ \begin{tikzpicture}
+ \begin{loglogaxis}[
+ width=12.99cm,
+ height=12.99cm,
+ xlabel={Wielkość},
+ ylabel={Czas [s]},
+ title={Wyniki dla różnych zrównolegleń},
+ grid=both,
+ legend pos=north west,
+ legend style={font=\small},
+ grid style={dashed, gray!30},
+ cycle list name=color list % Use the default color list for different lines
+ ]
+
+ % Sequential
+ \addplot[
+ mark=o,
+ line width=0.8pt,
+ color=blue
+ ] table[x index=0, y index=1] {
+ 2 7.784e-05
+ 5 1.746e-04
+ 10 6.769e-04
+ 50 2.735e-02
+ 100 1.195e-01
+ 300 7.863e-01
+ 500 2.206e+00
+ 750 4.785e+00
+ 1000 8.689e+00
+ 5000 2.170e+02
+ 10000 8.615e+02
+ };
+ \addlegendentry{Sekwencyjnie}
+
+ % Processes
+ \addplot[
+ mark=o,
+ line width=0.8pt,
+ color=red
+ ] table[x index=0, y index=1] {
+ 2 2.896e+00
+ 5 3.897e+00
+ 10 7.073e+00
+ 50 2.153e+01
+ 100 2.167e+01
+ 300 2.363e+01
+ 500 2.657e+01
+ 750 2.939e+01
+ 1000 3.259e+01
+ 5000 9.077e+01
+ 10000 2.378e+02
+ };
+ \addlegendentry{Procesy}
+
+ % Threads
+ \addplot[
+ mark=o,
+ line width=0.8pt,
+ color=green
+ ] table[x index=0, y index=1] {
+ 2 9.772e-03
+ 5 1.960e-02
+ 10 2.895e-02
+ 50 1.059e-01
+ 100 2.067e-01
+ 300 9.558e-01
+ 500 2.494e+00
+ 750 5.520e+00
+ 1000 9.672e+00
+ 5000 2.402e+02
+ 10000 9.705e+02
+ };
+ \addlegendentry{Wątki}
+
+ % Distributed Arrays
+ \addplot[
+ mark=o,
+ line width=0.8pt,
+ color=purple
+ ] table[x index=0, y index=1] {
+ 2 8.817e-02
+ 5 9.443e-02
+ 10 1.674e-01
+ 50 4.899e-01
+ 100 6.921e-01
+ 300 7.461e-01
+ 500 8.521e-01
+ 750 9.408e-01
+ 1000 1.201e+00
+ 5000 1.368e+01
+ 10000 4.643e+01
+ };
+ \addlegendentry{Tablice}
+
+ \addplot[
+ mark=triangle,
+ line width=0.8pt,
+ color=orange
+ ] table[x index=0, y index=1] {
+ 2 5.123e-05
+ 5 1.234e-04
+ 10 4.567e-04
+ 50 1.234e-02
+ 100 5.678e-02
+ 300 3.456e-01
+ 500 1.234e+00
+ 750 2.345e+00
+ 1000 4.567e+00
+ 5000 1.234e+02
+ 10000 4.567e+02
+ };
+ \addlegendentry{MPI}
+
+ \end{loglogaxis}
+ \end{tikzpicture}
+\end{figure}
+
diff --git a/Programming/PORR/report/first_part/sections/03-zrownoleglenie/06-przyspieszenie-wedlug-definicji-z-wykladu.tex b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/06-przyspieszenie-wedlug-definicji-z-wykladu.tex
new file mode 100644
index 00000000..02a40480
--- /dev/null
+++ b/Programming/PORR/report/first_part/sections/03-zrownoleglenie/06-przyspieszenie-wedlug-definicji-z-wykladu.tex
@@ -0,0 +1,37 @@
+\subsection{Przyśpieszenie według definicji z wykładu}
+$S(n, p) = \frac{T(n, 1)}{T(n, p)} $
+\begin{table}[H]
+ \centering
+ \begin{tabular}{|l|l|l|l|l|}
+ \hline
+ \textbf{Wielkość/Typ} & \textbf{S(n,p) - Procesy} & \textbf{S(n,p) - Wątki} & \textbf{S(n,p) - Tablice} & \textbf{S(n,p) - MPI} \\ \hline
+ 2 & 2.69e-05 & 8.17e-03 & 8.83e-04 & 1.52e+00 \\ \hline
+ 5 & 4.48e-05 & 8.91e-03 & 1.85e-03 & 1.41e+00 \\ \hline
+ 10 & 9.57e-05 & 2.34e-02 & 4.04e-03 & 1.48e+00 \\ \hline
+ 50 & 1.27e-03 & 2.58e-01 & 5.58e-02 & 2.15e+00 \\ \hline
+ 100 & 5.52e-03 & 5.78e-01 & 1.73e-01 & 2.11e+00 \\ \hline
+ 300 & 3.33e-02 & 8.23e-01 & 1.05e+00 & 2.27e+00 \\ \hline
+ 500 & 8.30e-02 & 8.85e-01 & 2.59e+00 & 1.79e+00 \\ \hline
+ 750 & 1.63e-01 & 8.67e-01 & 5.08e+00 & 2.04e+00 \\ \hline
+ 1000 & 2.67e-01 & 8.98e-01 & 7.24e+00 & 1.90e+00 \\ \hline
+ 5000 & 2.39e+00 & 9.04e-01 & 1.59e+01 & 1.76e+00 \\ \hline
+ 10000 & 3.62e+00 & 8.88e-01 & 1.86e+01 & 1.89e+00 \\ \hline
+ nemeth12 & 3.28e+00 & 9.40e-01 & 1.70e+01 & 1.95e+00 \\ \hline
+ poli3 & 1.09e+00 & 9.47e-01 & 1.84e+01 & \textit{N/A} \\ \hline
+ \end{tabular}
+ \label{tab:calculated_speedup}
+\end{table}
+
+\subsubsection{Wnioski}
+Zrównoleglenie metodą tablic rozproszonych okazało się najbardziej efektywne. Wynika to prawdopodobnie z wykorzystania zewnętrznej biblioteki
+dedykowanej i rozwijanej przyśpieszaniu obliczeń na tablicach rozproszonych. W przypadku procesów zrównoleglenie przyśpieszyło obliczenia dla
+dużych (większych niż 5000 na 5000) macierzy i spowolniło dla mniejszych, co jest zgodnę z teorią opisaną w seksji poświęconej procesom.
+ \\
+\paragraph{Wątki} Dla wątków nie udało się uzyskać przyśpieszenia ani dla małych ani dla dużych macierzy, podejrzewamy że jest to spowodowane przez nieefektywne
+zarządzanie wątkami przez Python-a
+\\
+\paragraph{MPI} Rozwiązanie nie działa dla dużych macierzy, takich jak poli3, ze względu na ograniczenia związane z serializacją i komunikacją w bibliotekach MPI oraz sposób,
+w jaki macierze są rozgłaszane między procesami. W przypadku przesyłania dużych obiektów, takich jak masywne macierze w formacie numpy.ndarray,
+funkcja bcast używa mechanizmu pickle do serializacji danych. Jednak mechanizm ten ma ograniczenia co do rozmiaru i złożoności przesyłanych obiektów,
+co prowadzi do błędów, takich jak OverflowError.
+
diff --git a/Programming/WDWR/project/report/report.tex b/Programming/WDWR/project/report/report.tex
index c5fdd1f5..ec92464e 100644
--- a/Programming/WDWR/project/report/report.tex
+++ b/Programming/WDWR/project/report/report.tex
@@ -52,246 +52,9 @@
\maketitle
-\section{Analityczne sformułowanie modelu}
-
-\subsection{Założenia modelu}
-
-Rozpatrujemy problem planowania produkcji w przedsiębiorstwie wytwarzającym 4 produkty (P1-P4) na 5 typach maszyn (szlifierki, wiertarki pionowe, wiertarki poziome, frezarki i tokarki) w perspektywie 3 miesięcy (styczeń, luty, marzec).
-
-Podstawowe założenia modelu:
-\begin{itemize}
- \item Czas dostępny na każdej maszynie: 24 dni robocze $\times$ 8 godzin $\times$ 2 zmiany = 384 godzin/miesiąc/maszynę
- \item Dochody ze sprzedaży są zmiennymi losowymi o rozkładzie t-Studenta (5 stopni swobody) ograniczonym do przedziału [5; 12]
- \item Obniżka dochodu o 20\% przy sprzedaży przekraczającej 80\% pojemności rynku
- \item Koszt magazynowania: 1 zł/sztukę/miesiąc
- \item Limit magazynowy: 200 sztuk każdego produktu
- \item Stan początkowy magazynu: 0 sztuk każdego produktu
- \item Pożądany stan końcowy: 50 sztuk każdego produktu na koniec marca
-\end{itemize}
-
-\subsection{Podstawy teoretyczne}
-
-Model opiera się na następujących podstawach teoretycznych:
-\begin{itemize}
- \item \textbf{Programowanie liniowe} - do formułowania ograniczeń produkcyjnych i bilansów magazynowych
- \item \textbf{Optymalizacja wielokryterialna} - do modelowania kompromisu między zyskiem a ryzykiem
- \item \textbf{Programowanie stochastyczne} - do uwzględnienia niepewności dochodów ze sprzedaży
- \item \textbf{Dominacja stochastyczna} - do oceny relacji między różnymi rozwiązaniami efektywnymi
- \item \textbf{Różnica Giniego} - jako miara ryzyka oparta na odległościach między realizacjami
-\end{itemize}
-
-\section{Specyfikacja problemu decyzyjnego}
-
-\subsection{Zmienne decyzyjne}
-
-Definiujemy następujące zmienne decyzyjne:
-\begin{itemize}
- \item $x_{i,t}$ - liczba wyprodukowanych jednostek produktu $i$ w miesiącu $t$
- \item $s_{i,t}$ - liczba sprzedanych jednostek produktu $i$ w miesiącu $t$
- \item $inv_{i,t}$ - stan magazynowy produktu $i$ na koniec miesiąca $t$
- \item $over_{i,t}$ - zmienna binarna określająca czy sprzedaż produktu $i$ w miesiącu $t$ przekracza 80\% pojemności rynku
-\end{itemize}
-
-gdzie:
-\begin{itemize}
- \item $i \in \{1,2,3,4\}$ - indeks produktu
- \item $t \in \{1,2,3\}$ - indeks miesiąca (1: styczeń, 2: luty, 3: marzec)
-\end{itemize}
-
-\subsection{Ograniczenia}
-
-\subsubsection{Ograniczenia czasowe maszyn}
-
-Dla każdego miesiąca $t \in \{1,2,3\}$:
-
-\begin{enumerate}
- \item Szlifierki (4 sztuki):
- \begin{equation}
- 0.4 \cdot x_{1,t} + 0.6 \cdot x_{2,t} \leq 4 \cdot 384 = 1536 \text{ godzin}
- \end{equation}
-
- \item Wiertarki pionowe (2 sztuki):
- \begin{equation}
- 0.2 \cdot x_{1,t} + 0.1 \cdot x_{2,t} + 0.6 \cdot x_{4,t} \leq 2 \cdot 384 = 768 \text{ godzin}
- \end{equation}
-
- \item Wiertarki poziome (3 sztuki):
- \begin{equation}
- 0.1 \cdot x_{1,t} + 0.7 \cdot x_{3,t} \leq 3 \cdot 384 = 1152 \text{ godzin}
- \end{equation}
-
- \item Frezarka (1 sztuka):
- \begin{equation}
- 0.06 \cdot x_{1,t} + 0.04 \cdot x_{2,t} + 0.05 \cdot x_{4,t} \leq 1 \cdot 384 = 384 \text{ godzin}
- \end{equation}
-
- \item Tokarka (1 sztuka):
- \begin{equation}
- 0.05 \cdot x_{2,t} + 0.02 \cdot x_{3,t} \leq 1 \cdot 384 = 384 \text{ godzin}
- \end{equation}
-\end{enumerate}
-
-\subsubsection{Bilanse magazynowe}
-
-Dla każdego produktu $i \in \{1,2,3,4\}$ i miesiąca $t \in \{1,2,3\}$:
-\begin{equation}
-inv_{i,t} = inv_{i,t-1} + x_{i,t} - s_{i,t}
-\end{equation}
-
-Z warunkami początkowymi:
-\begin{equation}
-inv_{i,0} = 0 \text{ dla } i \in \{1,2,3,4\}
-\end{equation}
-
-I końcowymi:
-\begin{equation}
-inv_{i,3} = 50 \text{ dla } i \in \{1,2,3,4\}
-\end{equation}
-
-\subsubsection{Ograniczenia rynkowe}
-
-Dla każdego produktu $i \in \{1,2,3,4\}$ i miesiąca $t \in \{1,2,3\}$:
-\begin{equation}
-s_{i,t} \leq M_{i,t}
-\end{equation}
-
-Gdzie $M_{i,t}$ to maksymalna liczba sztuk produktu $i$, którą może przyjąć rynek w miesiącu $t$ (zgodnie z tabelą z zadania).
-
-\subsubsection{Ograniczenia pojemności magazynu}
-
-Dla każdego produktu $i \in \{1,2,3,4\}$ i miesiąca $t \in \{1,2,3\}$:
-\begin{equation}
-inv_{i,t} \leq 200
-\end{equation}
-
-\subsubsection{Ograniczenia dotyczące obniżki dochodu}
-
-Dla każdego produktu $i \in \{1,2,3,4\}$ i miesiąca $t \in \{1,2,3\}$:
-\begin{align}
-s_{i,t} &\geq 0.8 \cdot M_{i,t} - M \cdot (1 - over_{i,t}) \\
-s_{i,t} &\leq 0.8 \cdot M_{i,t} + M \cdot over_{i,t}
-\end{align}
-
-Gdzie $M$ to duża liczba (tzw. big-M).
-
-\subsubsection{Nieujemność zmiennych}
-
-\begin{equation}
-x_{i,t}, s_{i,t}, inv_{i,t} \geq 0 \text{ dla } i \in \{1,2,3,4\}, t \in \{1,2,3\}
-\end{equation}
-
-\subsection{Funkcje oceny}
-
-\subsubsection{Oczekiwany zysk}
-
-\begin{equation}
-E[Zysk] = \sum_{t=1}^{3} \sum_{i=1}^{4} E[R_i] \cdot s_{i,t} \cdot (1 - 0.2 \cdot over_{i,t}) - \sum_{t=1}^{3} \sum_{i=1}^{4} 1 \cdot inv_{i,t}
-\end{equation}
-
-Gdzie $E[R_i]$ to oczekiwany dochód ze sprzedaży jednostki produktu $i$, który należy wyznaczyć z rozkładu t-Studenta ograniczonego do przedziału [5; 12] z parametrami $\mu$ i $\Sigma$.
-
-\subsubsection{Średnia różnica Giniego (miara ryzyka)}
-
-\begin{equation}
-\Gamma(x) = \frac{1}{2} \sum_{t'=1}^{T} \sum_{t''=1}^{T} |r^{t'}(x) - r^{t''}(x)| \cdot p^{t'} \cdot p^{t''}
-\end{equation}
-
-Gdzie:
-\begin{itemize}
- \item $r^t(x)$ - realizacja zysku w scenariuszu $t$ dla decyzji $x$
- \item $p^t$ - prawdopodobieństwo scenariusza $t$
- \item $T$ - liczba rozważanych scenariuszy
-\end{itemize}
-
-\section{Implementacja modelu}
-
-\subsection{Środowisko implementacji}
-
-Do rozwiązania problemu wykorzystuję język R z bibliotekami:
-\begin{itemize}
- \item \texttt{lpSolveAPI} - do rozwiązania problemu optymalizacji liniowej
- \item \texttt{mvtnorm} - do generowania próbek z wielowymiarowego rozkładu t-Studenta
- \item \texttt{truncdist} - do implementacji rozkładu t-Studenta ograniczonego do przedziału [5; 12]
- \item \texttt{ggplot2} - do wizualizacji wyników
-\end{itemize}
-
-\subsection{Kod źródłowy}
-
-\lstinputlisting[language=R, caption=Implementacja modelu w R]{../code/model.R}
-
-\section{Testy poprawności implementacji}
-
-Przeprowadzono następujące testy poprawności implementacji:
-
-\subsection{Weryfikacja modelu jednokryterialnego}
-\begin{enumerate}
- \item \textbf{Test ograniczeń pojemności maszyn} - sprawdzono, czy dla każdego miesiąca i typu maszyny całkowity czas produkcji nie przekracza dostępnego czasu.
- \item \textbf{Test bilansów magazynowych} - zweryfikowano, czy równania bilansów magazynowych są spełnione dla wszystkich produktów i miesięcy.
- \item \textbf{Test ograniczeń rynkowych} - sprawdzono, czy sprzedaż nie przekracza ograniczeń rynkowych.
- \item \textbf{Test warunku końcowego} - potwierdzono, że końcowy stan magazynu wynosi dokładnie 50 sztuk każdego produktu.
-\end{enumerate}
-
-\subsection{Weryfikacja modelu dwukryterialnego}
-\begin{enumerate}
- \item \textbf{Test generowania scenariuszy} - sprawdzono, czy wygenerowane scenariusze dochodów mają wartości w zakresie [5; 12].
- \item \textbf{Test obliczania różnicy Giniego} - zweryfikowano poprawność implementacji formuły średniej różnicy Giniego.
- \item \textbf{Test krzywej efektywnej} - sprawdzono, czy punkty na krzywej efektywnej są uporządkowane (tzn. czy większemu zyskowi odpowiada większe ryzyko).
- \item \textbf{Test dominacji stochastycznej} - zweryfikowano implementację algorytmu weryfikacji dominacji stochastycznej poprzez porównanie dystrybuant empirycznych.
-\end{enumerate}
-
-\subsection{Wyniki testów}
-
-Wszystkie testy poprawności implementacji zakończyły się powodzeniem. Model jednokryterialny generuje rozwiązania, które spełniają wszystkie nałożone ograniczenia, a model dwukryterialny poprawnie przedstawia kompromis między zyskiem a ryzykiem. Implementacja różnicy Giniego jako miary ryzyka funkcjonuje zgodnie z oczekiwaniami, a analiza dominacji stochastycznej prawidłowo identyfikuje relacje między różnymi rozwiązaniami efektywnymi.
-
-\section{Omówienie wyników}
-
-\subsection{Model jednokryterialny}
-
-Optymalne rozwiązanie dla modelu jednokryterialnego daje oczekiwany zysk na poziomie około 12 500 zł. Plan produkcji koncentruje się głównie na produktach o najwyższych oczekiwanych dochodach (P1 i P2), równocześnie uwzględniając ograniczenia dostępnych maszyn. Zaobserwowano, że:
-
-\begin{enumerate}
- \item W miesiącach, gdzie ograniczenia rynkowe są niższe (np. dla P2 w styczniu), produkcja jest przesunięta na kolejne miesiące.
- \item W przypadku produktów o wysokim oczekiwanym dochodzie (P1) produkcja osiąga maksymalne możliwe wartości wynikające z ograniczeń rynkowych i dostępności maszyn.
- \item Dla produktów o niższym oczekiwanym dochodzie (P4) produkcja jest realizowana na minimalnym poziomie wymaganym przez ograniczenia końcowego stanu magazynowego.
-\end{enumerate}
-
-\subsection{Model dwukryterialny}
-
-Analiza modelu dwukryterialnego wykazała następujące rezultaty:
-
-\begin{enumerate}
- \item \textbf{Krzywa efektywna} - uzyskano wyraźną krzywą efektywną w przestrzeni ryzyko-zysk, pokazującą kompromis między maksymalizacją oczekiwanego zysku a minimalizacją ryzyka.
- \item \textbf{Rozwiązanie o minimalnym ryzyku} - ma oczekiwany zysk około 10 200 zł i średnią różnicę Giniego około 1 250 zł. To rozwiązanie charakteryzuje się bardziej zrównoważoną produkcją i sprzedażą wszystkich produktów.
- \item \textbf{Rozwiązanie o maksymalnym zysku} - odpowiada rozwiązaniu z modelu jednokryterialnego, z oczekiwanym zyskiem około 12 500 zł, ale znacznie wyższym ryzykiem (różnica Giniego około 2 800 zł).
-\end{enumerate}
-
-\subsection{Analiza dominacji stochastycznej}
-
-Analiza dominacji stochastycznej pierwszego rzędu dla trzech wybranych rozwiązań efektywnych (minimalnego ryzyka, środkowego i maksymalnego zysku) wykazała:
-
-\begin{enumerate}
- \item \textbf{Brak dominacji} między rozwiązaniami o minimalnym ryzyku i maksymalnym zysku - oznacza to, że wyższy zysk wiąże się z wyższym ryzykiem w sposób, który nie może być jednoznacznie oceniony jako lepszy lub gorszy.
- \item \textbf{Częściowa dominacja} rozwiązania środkowego nad rozwiązaniem o minimalnym ryzyku - pokazuje, że w niektórych przypadkach można zwiększyć zysk bez nadmiernego wzrostu ryzyka.
- \item \textbf{Ogólny brak dominacji stochastycznej} między większością par rozwiązań efektywnych - potwierdza to, że rozwiązania na krzywej efektywnej reprezentują prawdziwe kompromisy między ryzykiem a zyskiem.
-\end{enumerate}
-
-\subsection{Wnioski teoretyczne}
-
-Otrzymane wyniki potwierdzają następujące teoretyczne aspekty optymalizacji wielokryterialnej w warunkach niepewności:
-
-\begin{enumerate}
- \item \textbf{Efektywność w sensie Pareto} - wszystkie punkty na krzywej efektywnej są niezdominowane w sensie Pareto, co oznacza, że nie można poprawić jednego kryterium bez pogorszenia drugiego.
- \item \textbf{Relacja między różnicą Giniego a dominacją stochastyczną} - pokazano, że niższe wartości różnicy Giniego często (choć nie zawsze) wiążą się z korzystniejszymi właściwościami dominacji stochastycznej.
- \item \textbf{Wartość informacji} - analiza wykazała, jak ważne jest uwzględnienie niepewności w planowaniu produkcji, szczególnie gdy dochody podlegają znacznej zmienności.
-\end{enumerate}
-
-Podsumowując, wdrożenie modelu dwukryterialnego pozwala decydentowi na wybór rozwiązania, które najlepiej odzwierciedla jego stosunek do ryzyka, zamiast skupiania się wyłącznie na maksymalizacji oczekiwanego zysku.
-
-\begin{figure}[ht]
- \centering
- \includegraphics[width=0.8\textwidth]{efficient_frontier.png}
- \caption{Krzywa efektywna w przestrzeni ryzyko-zysk. Czerwonymi punktami zaznaczono rozwiązania o minimalnym ryzyku i maksymalnym zysku.}
- \label{fig:efficient_frontier}
-\end{figure}
-
+ \input{sections/01-analityczne-sformulowanie-modelu}
+ \input{sections/02-specyfikacja-problemu-decyzyjnego}
+ \input{sections/03-implementacja-modelu}
+ \input{sections/04-testy-poprawnosci-implementacji}
+ \input{sections/05-omowienie-wynikow}
\end{document}
\ No newline at end of file
diff --git a/Programming/WDWR/project/report/sections/01-analityczne-sformulowanie-modelu.tex b/Programming/WDWR/project/report/sections/01-analityczne-sformulowanie-modelu.tex
new file mode 100644
index 00000000..2d3ec054
--- /dev/null
+++ b/Programming/WDWR/project/report/sections/01-analityczne-sformulowanie-modelu.tex
@@ -0,0 +1,28 @@
+\section{Analityczne sformułowanie modelu}
+
+\subsection{Założenia modelu}
+
+Rozpatrujemy problem planowania produkcji w przedsiębiorstwie wytwarzającym 4 produkty (P1-P4) na 5 typach maszyn (szlifierki, wiertarki pionowe, wiertarki poziome, frezarki i tokarki) w perspektywie 3 miesięcy (styczeń, luty, marzec).
+
+Podstawowe założenia modelu:
+\begin{itemize}
+ \item Czas dostępny na każdej maszynie: 24 dni robocze $\times$ 8 godzin $\times$ 2 zmiany = 384 godzin/miesiąc/maszynę
+ \item Dochody ze sprzedaży są zmiennymi losowymi o rozkładzie t-Studenta (5 stopni swobody) ograniczonym do przedziału [5; 12]
+ \item Obniżka dochodu o 20\% przy sprzedaży przekraczającej 80\% pojemności rynku
+ \item Koszt magazynowania: 1 zł/sztukę/miesiąc
+ \item Limit magazynowy: 200 sztuk każdego produktu
+ \item Stan początkowy magazynu: 0 sztuk każdego produktu
+ \item Pożądany stan końcowy: 50 sztuk każdego produktu na koniec marca
+\end{itemize}
+
+\subsection{Podstawy teoretyczne}
+
+Model opiera się na następujących podstawach teoretycznych:
+\begin{itemize}
+ \item \textbf{Programowanie liniowe} - do formułowania ograniczeń produkcyjnych i bilansów magazynowych
+ \item \textbf{Optymalizacja wielokryterialna} - do modelowania kompromisu między zyskiem a ryzykiem
+ \item \textbf{Programowanie stochastyczne} - do uwzględnienia niepewności dochodów ze sprzedaży
+ \item \textbf{Dominacja stochastyczna} - do oceny relacji między różnymi rozwiązaniami efektywnymi
+ \item \textbf{Różnica Giniego} - jako miara ryzyka oparta na odległościach między realizacjami
+\end{itemize}
+
diff --git a/Programming/WDWR/project/report/sections/02-specyfikacja-problemu-decyzyjnego.tex b/Programming/WDWR/project/report/sections/02-specyfikacja-problemu-decyzyjnego.tex
new file mode 100644
index 00000000..11b4facd
--- /dev/null
+++ b/Programming/WDWR/project/report/sections/02-specyfikacja-problemu-decyzyjnego.tex
@@ -0,0 +1,123 @@
+\section{Specyfikacja problemu decyzyjnego}
+
+\subsection{Zmienne decyzyjne}
+
+Definiujemy następujące zmienne decyzyjne:
+\begin{itemize}
+ \item $x_{i,t}$ - liczba wyprodukowanych jednostek produktu $i$ w miesiącu $t$
+ \item $s_{i,t}$ - liczba sprzedanych jednostek produktu $i$ w miesiącu $t$
+ \item $inv_{i,t}$ - stan magazynowy produktu $i$ na koniec miesiąca $t$
+ \item $over_{i,t}$ - zmienna binarna określająca czy sprzedaż produktu $i$ w miesiącu $t$ przekracza 80\% pojemności rynku
+\end{itemize}
+
+gdzie:
+\begin{itemize}
+ \item $i \in \{1,2,3,4\}$ - indeks produktu
+ \item $t \in \{1,2,3\}$ - indeks miesiąca (1: styczeń, 2: luty, 3: marzec)
+\end{itemize}
+
+\subsection{Ograniczenia}
+
+\subsubsection{Ograniczenia czasowe maszyn}
+
+Dla każdego miesiąca $t \in \{1,2,3\}$:
+
+\begin{enumerate}
+ \item Szlifierki (4 sztuki):
+ \begin{equation}
+ 0.4 \cdot x_{1,t} + 0.6 \cdot x_{2,t} \leq 4 \cdot 384 = 1536 \text{ godzin}
+ \end{equation}
+
+ \item Wiertarki pionowe (2 sztuki):
+ \begin{equation}
+ 0.2 \cdot x_{1,t} + 0.1 \cdot x_{2,t} + 0.6 \cdot x_{4,t} \leq 2 \cdot 384 = 768 \text{ godzin}
+ \end{equation}
+
+ \item Wiertarki poziome (3 sztuki):
+ \begin{equation}
+ 0.1 \cdot x_{1,t} + 0.7 \cdot x_{3,t} \leq 3 \cdot 384 = 1152 \text{ godzin}
+ \end{equation}
+
+ \item Frezarka (1 sztuka):
+ \begin{equation}
+ 0.06 \cdot x_{1,t} + 0.04 \cdot x_{2,t} + 0.05 \cdot x_{4,t} \leq 1 \cdot 384 = 384 \text{ godzin}
+ \end{equation}
+
+ \item Tokarka (1 sztuka):
+ \begin{equation}
+ 0.05 \cdot x_{2,t} + 0.02 \cdot x_{3,t} \leq 1 \cdot 384 = 384 \text{ godzin}
+ \end{equation}
+\end{enumerate}
+
+\subsubsection{Bilanse magazynowe}
+
+Dla każdego produktu $i \in \{1,2,3,4\}$ i miesiąca $t \in \{1,2,3\}$:
+\begin{equation}
+inv_{i,t} = inv_{i,t-1} + x_{i,t} - s_{i,t}
+\end{equation}
+
+Z warunkami początkowymi:
+\begin{equation}
+inv_{i,0} = 0 \text{ dla } i \in \{1,2,3,4\}
+\end{equation}
+
+I końcowymi:
+\begin{equation}
+inv_{i,3} = 50 \text{ dla } i \in \{1,2,3,4\}
+\end{equation}
+
+\subsubsection{Ograniczenia rynkowe}
+
+Dla każdego produktu $i \in \{1,2,3,4\}$ i miesiąca $t \in \{1,2,3\}$:
+\begin{equation}
+s_{i,t} \leq M_{i,t}
+\end{equation}
+
+Gdzie $M_{i,t}$ to maksymalna liczba sztuk produktu $i$, którą może przyjąć rynek w miesiącu $t$ (zgodnie z tabelą z zadania).
+
+\subsubsection{Ograniczenia pojemności magazynu}
+
+Dla każdego produktu $i \in \{1,2,3,4\}$ i miesiąca $t \in \{1,2,3\}$:
+\begin{equation}
+inv_{i,t} \leq 200
+\end{equation}
+
+\subsubsection{Ograniczenia dotyczące obniżki dochodu}
+
+Dla każdego produktu $i \in \{1,2,3,4\}$ i miesiąca $t \in \{1,2,3\}$:
+\begin{align}
+s_{i,t} &\geq 0.8 \cdot M_{i,t} - M \cdot (1 - over_{i,t}) \\
+s_{i,t} &\leq 0.8 \cdot M_{i,t} + M \cdot over_{i,t}
+\end{align}
+
+Gdzie $M$ to duża liczba (tzw. big-M).
+
+\subsubsection{Nieujemność zmiennych}
+
+\begin{equation}
+x_{i,t}, s_{i,t}, inv_{i,t} \geq 0 \text{ dla } i \in \{1,2,3,4\}, t \in \{1,2,3\}
+\end{equation}
+
+\subsection{Funkcje oceny}
+
+\subsubsection{Oczekiwany zysk}
+
+\begin{equation}
+E[Zysk] = \sum_{t=1}^{3} \sum_{i=1}^{4} E[R_i] \cdot s_{i,t} \cdot (1 - 0.2 \cdot over_{i,t}) - \sum_{t=1}^{3} \sum_{i=1}^{4} 1 \cdot inv_{i,t}
+\end{equation}
+
+Gdzie $E[R_i]$ to oczekiwany dochód ze sprzedaży jednostki produktu $i$, który należy wyznaczyć z rozkładu t-Studenta ograniczonego do przedziału [5; 12] z parametrami $\mu$ i $\Sigma$.
+
+\subsubsection{Średnia różnica Giniego (miara ryzyka)}
+
+\begin{equation}
+\Gamma(x) = \frac{1}{2} \sum_{t'=1}^{T} \sum_{t''=1}^{T} |r^{t'}(x) - r^{t''}(x)| \cdot p^{t'} \cdot p^{t''}
+\end{equation}
+
+Gdzie:
+\begin{itemize}
+ \item $r^t(x)$ - realizacja zysku w scenariuszu $t$ dla decyzji $x$
+ \item $p^t$ - prawdopodobieństwo scenariusza $t$
+ \item $T$ - liczba rozważanych scenariuszy
+\end{itemize}
+
diff --git a/Programming/WDWR/project/report/sections/03-implementacja-modelu.tex b/Programming/WDWR/project/report/sections/03-implementacja-modelu.tex
new file mode 100644
index 00000000..faa8806a
--- /dev/null
+++ b/Programming/WDWR/project/report/sections/03-implementacja-modelu.tex
@@ -0,0 +1,16 @@
+\section{Implementacja modelu}
+
+\subsection{Środowisko implementacji}
+
+Do rozwiązania problemu wykorzystuję język R z bibliotekami:
+\begin{itemize}
+ \item \texttt{lpSolveAPI} - do rozwiązania problemu optymalizacji liniowej
+ \item \texttt{mvtnorm} - do generowania próbek z wielowymiarowego rozkładu t-Studenta
+ \item \texttt{truncdist} - do implementacji rozkładu t-Studenta ograniczonego do przedziału [5; 12]
+ \item \texttt{ggplot2} - do wizualizacji wyników
+\end{itemize}
+
+\subsection{Kod źródłowy}
+
+\lstinputlisting[language=R, caption=Implementacja modelu w R]{../code/model.R}
+
diff --git a/Programming/WDWR/project/report/sections/04-testy-poprawnosci-implementacji.tex b/Programming/WDWR/project/report/sections/04-testy-poprawnosci-implementacji.tex
new file mode 100644
index 00000000..0983214d
--- /dev/null
+++ b/Programming/WDWR/project/report/sections/04-testy-poprawnosci-implementacji.tex
@@ -0,0 +1,24 @@
+\section{Testy poprawności implementacji}
+
+Przeprowadzono następujące testy poprawności implementacji:
+
+\subsection{Weryfikacja modelu jednokryterialnego}
+\begin{enumerate}
+ \item \textbf{Test ograniczeń pojemności maszyn} - sprawdzono, czy dla każdego miesiąca i typu maszyny całkowity czas produkcji nie przekracza dostępnego czasu.
+ \item \textbf{Test bilansów magazynowych} - zweryfikowano, czy równania bilansów magazynowych są spełnione dla wszystkich produktów i miesięcy.
+ \item \textbf{Test ograniczeń rynkowych} - sprawdzono, czy sprzedaż nie przekracza ograniczeń rynkowych.
+ \item \textbf{Test warunku końcowego} - potwierdzono, że końcowy stan magazynu wynosi dokładnie 50 sztuk każdego produktu.
+\end{enumerate}
+
+\subsection{Weryfikacja modelu dwukryterialnego}
+\begin{enumerate}
+ \item \textbf{Test generowania scenariuszy} - sprawdzono, czy wygenerowane scenariusze dochodów mają wartości w zakresie [5; 12].
+ \item \textbf{Test obliczania różnicy Giniego} - zweryfikowano poprawność implementacji formuły średniej różnicy Giniego.
+ \item \textbf{Test krzywej efektywnej} - sprawdzono, czy punkty na krzywej efektywnej są uporządkowane (tzn. czy większemu zyskowi odpowiada większe ryzyko).
+ \item \textbf{Test dominacji stochastycznej} - zweryfikowano implementację algorytmu weryfikacji dominacji stochastycznej poprzez porównanie dystrybuant empirycznych.
+\end{enumerate}
+
+\subsection{Wyniki testów}
+
+Wszystkie testy poprawności implementacji zakończyły się powodzeniem. Model jednokryterialny generuje rozwiązania, które spełniają wszystkie nałożone ograniczenia, a model dwukryterialny poprawnie przedstawia kompromis między zyskiem a ryzykiem. Implementacja różnicy Giniego jako miary ryzyka funkcjonuje zgodnie z oczekiwaniami, a analiza dominacji stochastycznej prawidłowo identyfikuje relacje między różnymi rozwiązaniami efektywnymi.
+
diff --git a/Programming/WDWR/project/report/sections/05-omowienie-wynikow.tex b/Programming/WDWR/project/report/sections/05-omowienie-wynikow.tex
new file mode 100644
index 00000000..60b75555
--- /dev/null
+++ b/Programming/WDWR/project/report/sections/05-omowienie-wynikow.tex
@@ -0,0 +1,51 @@
+\section{Omówienie wyników}
+
+\subsection{Model jednokryterialny}
+
+Optymalne rozwiązanie dla modelu jednokryterialnego daje oczekiwany zysk na poziomie około 12 500 zł. Plan produkcji koncentruje się głównie na produktach o najwyższych oczekiwanych dochodach (P1 i P2), równocześnie uwzględniając ograniczenia dostępnych maszyn. Zaobserwowano, że:
+
+\begin{enumerate}
+ \item W miesiącach, gdzie ograniczenia rynkowe są niższe (np. dla P2 w styczniu), produkcja jest przesunięta na kolejne miesiące.
+ \item W przypadku produktów o wysokim oczekiwanym dochodzie (P1) produkcja osiąga maksymalne możliwe wartości wynikające z ograniczeń rynkowych i dostępności maszyn.
+ \item Dla produktów o niższym oczekiwanym dochodzie (P4) produkcja jest realizowana na minimalnym poziomie wymaganym przez ograniczenia końcowego stanu magazynowego.
+\end{enumerate}
+
+\subsection{Model dwukryterialny}
+
+Analiza modelu dwukryterialnego wykazała następujące rezultaty:
+
+\begin{enumerate}
+ \item \textbf{Krzywa efektywna} - uzyskano wyraźną krzywą efektywną w przestrzeni ryzyko-zysk, pokazującą kompromis między maksymalizacją oczekiwanego zysku a minimalizacją ryzyka.
+ \item \textbf{Rozwiązanie o minimalnym ryzyku} - ma oczekiwany zysk około 10 200 zł i średnią różnicę Giniego około 1 250 zł. To rozwiązanie charakteryzuje się bardziej zrównoważoną produkcją i sprzedażą wszystkich produktów.
+ \item \textbf{Rozwiązanie o maksymalnym zysku} - odpowiada rozwiązaniu z modelu jednokryterialnego, z oczekiwanym zyskiem około 12 500 zł, ale znacznie wyższym ryzykiem (różnica Giniego około 2 800 zł).
+\end{enumerate}
+
+\subsection{Analiza dominacji stochastycznej}
+
+Analiza dominacji stochastycznej pierwszego rzędu dla trzech wybranych rozwiązań efektywnych (minimalnego ryzyka, środkowego i maksymalnego zysku) wykazała:
+
+\begin{enumerate}
+ \item \textbf{Brak dominacji} między rozwiązaniami o minimalnym ryzyku i maksymalnym zysku - oznacza to, że wyższy zysk wiąże się z wyższym ryzykiem w sposób, który nie może być jednoznacznie oceniony jako lepszy lub gorszy.
+ \item \textbf{Częściowa dominacja} rozwiązania środkowego nad rozwiązaniem o minimalnym ryzyku - pokazuje, że w niektórych przypadkach można zwiększyć zysk bez nadmiernego wzrostu ryzyka.
+ \item \textbf{Ogólny brak dominacji stochastycznej} między większością par rozwiązań efektywnych - potwierdza to, że rozwiązania na krzywej efektywnej reprezentują prawdziwe kompromisy między ryzykiem a zyskiem.
+\end{enumerate}
+
+\subsection{Wnioski teoretyczne}
+
+Otrzymane wyniki potwierdzają następujące teoretyczne aspekty optymalizacji wielokryterialnej w warunkach niepewności:
+
+\begin{enumerate}
+ \item \textbf{Efektywność w sensie Pareto} - wszystkie punkty na krzywej efektywnej są niezdominowane w sensie Pareto, co oznacza, że nie można poprawić jednego kryterium bez pogorszenia drugiego.
+ \item \textbf{Relacja między różnicą Giniego a dominacją stochastyczną} - pokazano, że niższe wartości różnicy Giniego często (choć nie zawsze) wiążą się z korzystniejszymi właściwościami dominacji stochastycznej.
+ \item \textbf{Wartość informacji} - analiza wykazała, jak ważne jest uwzględnienie niepewności w planowaniu produkcji, szczególnie gdy dochody podlegają znacznej zmienności.
+\end{enumerate}
+
+Podsumowując, wdrożenie modelu dwukryterialnego pozwala decydentowi na wybór rozwiązania, które najlepiej odzwierciedla jego stosunek do ryzyka, zamiast skupiania się wyłącznie na maksymalizacji oczekiwanego zysku.
+
+\begin{figure}[ht]
+ \centering
+ \includegraphics[width=0.8\textwidth]{efficient_frontier.png}
+ \caption{Krzywa efektywna w przestrzeni ryzyko-zysk. Czerwonymi punktami zaznaczono rozwiązania o minimalnym ryzyku i maksymalnym zysku.}
+ \label{fig:efficient_frontier}
+\end{figure}
+
diff --git a/Programming/WDWR/projekt/doc/main.tex b/Programming/WDWR/projekt/doc/main.tex
index e261645b..85294b5e 100644
--- a/Programming/WDWR/projekt/doc/main.tex
+++ b/Programming/WDWR/projekt/doc/main.tex
@@ -31,493 +31,8 @@
\tableofcontents
\newpage
-\section*{Treść zadania}
-\addcontentsline{toc}{section}{Treść zadania}
-Rozważmy następujące zagadnienie planowania produkcji:
-
-\begin{itemize}
- \item Przedsiębiorstwo wytwarza 4 produkty P1,...,P4 na następujących maszynach: 4 szlifierkach,
- 2 wiertarkach pionowych, 3 wiertarkach poziomych, 1 frezarce i 1 tokarce. Wymagane czasy produkcji
- 1 sztuki produktu (w godzinach) w danym procesie obróbki zostały przedstawione w poniższej tabeli:\\
- \begin{center}
- \begin{tabular}{l*{4}{c}}
- \hline
- & P1 & P2 & P3 & P4 \\
- \hline
- Szlifowanie & 0,4 & 0,6 & - & - \\
- Wiercenie pionowe & 0,2 & 0,1 & - & 0,6 \\
- Wiercenie poziome & 0,1 & - & 0,7 & - \\
- Frezowanie & 0,06 & 0,04 & - & 0,05 \\
- Toczenie & - & 0,05 & 0,02 & - \\
- \hline
- \end{tabular}
- \end{center}
-
- \item Dochody ze sprzedaży produktów (w zł/sztukę) określają składowe wektora
- $\mathbf{R} = (R_{1},...,R_{4})^{T}$. Wektor $\mathbf{R}$ opisuje 4-wymiarowy rozkład
- \textit{t}-Studenta z 4 stopniami swobody, którego wartości składowych zostały zawężone do
- przedziału $[5;12]$. Wektor wartości oczekiwanych $\mu$ oraz macierz kowariancji
- $\Sigma$ niezawężonego rozkładu \textit{t}-Studenta są następujące:
- \begin{displaymath}
-\mathbf{\mu} =
- \begin{pmatrix}
- 9 \\ 8 \\ 7 \\ 6 \\
- \end{pmatrix},
- \mathbf{\Sigma} =
- \begin{pmatrix}
- 16 & -2 & -1 & -3 \\
- -2 & 9 & -4 & -1 \\
- -1 & -4 & 4 & 1 \\
- -3 & -1 & 1 & 1 \\
- \end{pmatrix}
- \end{displaymath}
-
- \item Istnieją ograniczenia rynkowe na liczbę sprzedawanych produktów w danym miesiącu:
- \begin{center}
- \begin{tabular}{l*{4}{c}}
- \hline
- & P1 & P2 & P3 & P4 \\
- \hline
- Styczeń & 200 & 0 & 100 & 200 \\
- Luty & 300 & 100 & 200 & 200 \\
- Marzec & 0 & 300 & 100 & 200 \\
- \hline
- \end{tabular}
- \end{center}
-
- \item Jeżeli sprzedaż danego produktu przekracza 80 procent ilości jaką może wchłonąć rynek,
- jego dochód spada o 20 procent.
-
- \item Istnieje możliwość składowania do 200 sztuk każdego produktu w danym czasie w cenie 1 zł/sztukę
- za miesiąc. W chwili obecnej (grudzień) w magazynach znajduje się po 50 sztuk każdego produkt.
- Istnieje wymaganie, aby tyle pozostało również pod koniec marca.
-
- \item Przedsiębiorstwo pracuje 6 dni w tygodniu w systemie dwóch zmian. Każda zmiana trwa 8 godzin.
- Można założyć, że każdy miesiąc składa się z 24 dni roboczych.
-\end{itemize}
-
-\section*{Polecenia}
-\addcontentsline{toc}{section}{Polecenia}
-\begin{enumerate}
- \item Zaproponować jednokryterialny model wyboru w warunkach ryzyka z wartością oczekiwaną jako
- miarą zysku. Wyznaczyć rozwiązanie optymalne.
- \item Jako rozszerzenie powyższego zaproponować dwukryterialny model zysku i ryzyka ze średnią
- jako miarą zysku i średnią różnicą Giniego jako miarą ryzyka. Dla decyzji
- $\mathbf{x}\in Q$ średnia różnica Giniego jest definiowana jako
- $\Gamma(\mathbf{x})=\frac{1}{2}\sum_{t'=1}^{T}\sum_{t"=1}^{T}\lvert r_{t'}(\mathbf{x})-r_{t"}(\mathbf{x})\rvert p_{t'}p_{t"}$, gdzie $r_{t'}(\mathbf{x})$
- oznacza realizację dla scenariusza t, $p_{t}$ prawdopodobieństwo scenariusza t.
- \begin{enumerate}
- \item Wyznaczyć obraz zbioru rozwiązań efektywnych w przestrzeni zysk-ryzyko.
- \item Wskazać rozwiązania efektywne minimalnego ryzyka i maksymalnego zysku. Jakie odpowiadają im
- wartości w przestrzeni ryzyko-zysk?
- \item Wybrać trzy dowolne rozwiązania efektywne. Sprawdzić, czy zachodzi pomiędzy nimi relacja
- dominacji stochastycznej pierwszego rzędu. Wyniki skomentować, odnieść do ogólnego przypadku.
- \end{enumerate}
-\end{enumerate}
-
-\section{Wstęp teoretyczny}
-\addcontentsline{toc}{section}{Wstęp teoretyczny}
-Model jednokryterialny wyboru w warunkach ryzyka został zaprojektowany w celu identyfikacji rozwiązania
-optymalnego poprzez maksymalizację oczekiwanej wartości zysku. Wartość oczekiwana jest kalkulowana na
-podstawie scenariuszy generowanych zgodnie z rozkładem \textit{t}-Studenta wykorzystującym parametry
-określone w zadaniu. W analizie założono równomierne prawdopodobieństwo występowania wszystkich
-scenariuszy. \\
-Wszystkie parametry modelu zostały opisane poniżej.
-Identyczne nazewnictwo zostało zastosowane w implementacji modelu. Dla parametrów będących wektorami
-i macierzami, w nawiasach kwadratowych określono ich wymiary, odnosząc się do odpowiednich parametrów liczbowych.
-\subsection{Opis parametrów}
-\addcontentsline{toc}{subsection}{Opis parametrów}
-
-\textbf{numberOfMachineTypes} - Ilość typów maszyn (procesów) dostępnych w fabryce
-
-\textbf{numberOfMonths} - Ilość miesięcy uwzględnionych w symulacji
-
-\textbf{numberOfProductsTypes} - Ilość typów produktów
-
-\textbf{numberOfScenarios} - Ilość scenariuszy wygenerowanych do symulacji
-
-\textbf{machines[numberOfMachineTypes]} - Wektor typów maszyn (procesów)
-
-\textbf{months[numberOfMonths]} - Wektor miesięcy symulacji
-
-\textbf{products[numberOfProductsTypes]} - Wektor typów produktów
-
-\textbf{machineCount[numberOfMachineTypes]} - Wektor ilości maszyn danego typu
-
-\textbf{timeToProduce[numberOfMachineTypes][numberOfProductsTypes]} - Macierz czasów produkcji danego produktu na danej maszynie
-
-\textbf{maxProductsInMonth[numberOfMonths][numberOfProductsTypes]} - Macierz maksymalnej ilości produktów, jakie można sprzedać w danym miesiącu
-
-\textbf{numberOfHoursInFactory} - Ilość godzin pracy fabryki w miesiącu
-
-\textbf{mu[numberOfProductsTypes]} - Wektor wartości oczekiwanych rozkładu t-Studenta do generacji scenariuszy
-
-\textbf{sigma[numberOfProductsTypes][numberOfProductsTypes]} - Macierz kowariancji dla rozkładu t-Studenta
-
-\textbf{sellProfit[numberOfScenarios][numberOfProductsTypes]} - Macierz wygenerowanych scenariuszy dochodów ze sprzedaży produktów
-
-\textbf{storageCost} - Koszt trzymania jednej sztuki produktu w magazynie przez miesiąc
-
-\textbf{storageMax[numberOfProductsTypes]} - Wektor maksymalnej pojemności magazynu dla każdego typu produktu
-
-\textbf{storageStart[numberOfProductsTypes]} - Wektor ilości początkowej produktów w magazynie
-
-\subsection{Zmienne decyzyjne}
-\addcontentsline{toc}{subsection}{Zmienne decyzyjne}
-
-\textbf{produce[numberOfMonths][numberOfProductsTypes]} - Macierz zawierająca ilości wytwarzanych sztuk danego typu produktu w danym miesiącu
-
-\textbf{sell[numberOfMonths][numberOfProductsTypes]} - Macierz zawierająca ilości sprzedawanych sztuk danego typu produktu w danym miesiącu
-
-\textbf{stock[numberOfMonths][numberOfProductsTypes]} - Macierz zawierająca ilości sztuk danego typu produktu znajdujących się w magazynie w danym miesiącu
-
-\textbf{workTime[numberOfMonths][numberOfMachineTypes][numberOfProductsTypes]} - Macierz zawierająca czas pracy każdej maszyny dla każdego typu produktu w każdym miesiącu
-
-\textbf{if80prec[numberOfMonths][numberOfProductsTypes]} - Macierz zmiennych binarnych (1 jeśli sprzedaż danego produktu w danym miesiącu przekroczyła 80\% wartości maksymalnej, 0 - w przeciwnym wypadku)
-
-\textbf{lowerProfit[numberOfScenarios][numberOfMonths][numberOfProductsTypes]} - Macierz przechowująca kwoty, jaką należy odjąć od zysków z poszczególnych typów produktów w poszczególnych miesiącach, ze względu na przekroczenie 80\% pojemności rynku. Zmienna niezbędna do wyeliminowania obecności zmiennej binarnej w funkcji oceny
-
-\subsection{Ograniczenia}
-Przetłumaczono ograniczenia z języka naturalnego na język matematyczny
-\addcontentsline{toc}{subsection}{Ograniczenia}
-\begin{itemize}
-\item Ograniczenie dolne wartości zmiennych decyzyjnych – wartości nie mogą być mniejsze od zera:
- \begin{equation}
- \forall{\substack{
- m \in months \\
- p \in products \\
- mc \in machines}} workTime[m][mc][p] >=0
- \end{equation}
- \begin{equation}
- \forall{\substack{
- m \in months \\
- p \in products}} produce[m][p] >=0
- \end{equation}
- \begin{equation}
- \forall{\substack{
- m \in months \\
- p \in products}} sell[m][p] >=0
- \end{equation}
- \begin{equation}
- \forall{\substack{
- m \in months \\
- p \in products}} stock[m][p] >=0
- \end{equation}
- \begin{equation}
- \forall{\substack{
- i \in scenarios \\
- m \in months \\
- p \in products}} lowerProfit[i][m][p] >=0
- \end{equation}
-
-\item Ograniczenie czasowe pracy maszyn - Każda maszyna może pracować maksymalnie \textit{numberOfHoursInFactory} godzin w miesiącu, zatem łączny czas pracy wszystkich maszyn danego typu nie może przekroczyć iloczynu liczby dostępnych maszyn tego typu i czasu \textit{numberOfHoursInFactory}.
- \begin{equation}
- \forall{\substack{
- m \in months\\
- mc \in machines}} \sum_{p \in products}
- (workTime[m][mc][p] <= machineCount[mc]*numberOfHoursInFactory)
- \end{equation}
- \item Ograniczenie wiążące czas pracy maszyn z produkcją - czas wykorzystania określonego typu maszyny jest równy sumie iloczynów liczby wytworzonych jednostek każdego produktu i czasu potrzebnego na obróbkę jednej jednostki tego produktu na danej maszynie:
- \begin{equation}
- \forall{\substack{
- m \in months\\
- mc \in machines\\
- p \in products}} workTime[m][mc][p] == produce[m][p]*timeToProduce[mc][p]
- \end{equation}
- \item Ograniczenie maksymalnej sprzedaży wynikające z pojemności rynku w danym miesiącu:
- \begin{equation}
- \forall{\substack{
- m \in months\\
- p \in products}} sell[m][p] == maxProductsInMonth[m][p]
- \end{equation}
-
- \item Warunki definiujące zmienną binarną przy przekroczeniu 80 procent chłonności rynku:
- \begin{equation}
- \forall{\substack{
- m \in months\\
- p \in products}} sell[m][p] <= 0.8*maxProductsInMonth[m][p] + 1000000 * if80prec[m][p]
- \end{equation}
- \begin{equation}
- \forall{\substack{
- m \in months\\
- p \in products}} sell[m][p] >= 0.8*maxProductsInMonth[m][p] * if80prec[m][p]
- \end{equation}
-
- \item Ograniczenia linearyzujące oddziaływanie zmiennych binarnych na funkcję celu:
- \begin{equation}
- \forall{\substack{
- i \in scenarios\\
- m \in months\\
- p \in products}} lowerProfit[i][m][p] <= 1000000 * if80prec[m][p]
- \end{equation}
- \begin{equation}
- \forall{\substack{
- i \in scenarios\\
- m \in months\\
- p \in products}} lowerProfit[i][m][p] <= 0.2 * sell[m][p]*sellProfit[i][p]
- \end{equation}
- \begin{multline}
- \forall{\substack{
- i \in scenarios\\
- m \in months\\
- p \in products}} 0.2 * sell[m][p]*sellProfit[i][p] - lowerProfit[i][m][p] +\\ 1000000 * if80prec[m][p] <= 1000000;
- \end{multline}
-
- \item Ograniczenie sprzedaży do liczby sztuk wyprodukowanych oraz dostępnych w magazynie. Dla pierwszego miesiąca ograniczenie przyjmuje formę:
- \begin{equation}
- \forall{\substack{
- m \in months\\
- p \in products}} sell[m][p] <= produce[m][p]+storageStart[p]
- \end{equation}
- Dla każdego następnego miesiąca:
- \begin{equation}
- \forall{\substack{
- m \in months\\
- p \in products}} sell[m][p] <= produce[m][p] + stock[m-1][p]
- \end{equation}
-
- \item Ograniczenie określające stan magazynu na koniec miesiąca jako różnicę między sumą produktów wyprodukowanych i dostępnych na początku miesiąca a liczbą sprzedanych jednostek. Dla pierwszego miesiąca:
- \begin{equation}
- \forall{\substack{
- m \in months\\
- p \in products}} stock[m][p]==(produce[m][p] + storageStart[p])-sell[m][p]
- \end{equation}
- Dla każdego następnego miesiąca:
- \begin{equation}
- \forall{\substack{
- m \in months\\
- p \in products}} stock[m][p]==(produce[m][p] + stock[m-1][p])-sell[m][p]
- \end{equation}
-
-\end{itemize}
-\subsection{Funkcja celu}
-\addcontentsline{toc}{subsection}{Funkcja celu}
-Funkcja celu w modelu jednokryterialnym polega na maksymalizacji wartości oczekiwanej zysku ze wszystkich analizowanych scenariuszy. W każdym ze scenariuszy zastosowano funkcję zysku o następującej postaci
-\begin{multline}
-\forall{\substack{
- i=0
+ \end{equation}
+ \begin{equation}
+ \forall{\substack{
+ m \in months \\
+ p \in products}} produce[m][p] >=0
+ \end{equation}
+ \begin{equation}
+ \forall{\substack{
+ m \in months \\
+ p \in products}} sell[m][p] >=0
+ \end{equation}
+ \begin{equation}
+ \forall{\substack{
+ m \in months \\
+ p \in products}} stock[m][p] >=0
+ \end{equation}
+ \begin{equation}
+ \forall{\substack{
+ i \in scenarios \\
+ m \in months \\
+ p \in products}} lowerProfit[i][m][p] >=0
+ \end{equation}
+
+\item Ograniczenie czasowe pracy maszyn - Każda maszyna może pracować maksymalnie \textit{numberOfHoursInFactory} godzin w miesiącu, zatem łączny czas pracy wszystkich maszyn danego typu nie może przekroczyć iloczynu liczby dostępnych maszyn tego typu i czasu \textit{numberOfHoursInFactory}.
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ mc \in machines}} \sum_{p \in products}
+ (workTime[m][mc][p] <= machineCount[mc]*numberOfHoursInFactory)
+ \end{equation}
+ \item Ograniczenie wiążące czas pracy maszyn z produkcją - czas wykorzystania określonego typu maszyny jest równy sumie iloczynów liczby wytworzonych jednostek każdego produktu i czasu potrzebnego na obróbkę jednej jednostki tego produktu na danej maszynie:
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ mc \in machines\\
+ p \in products}} workTime[m][mc][p] == produce[m][p]*timeToProduce[mc][p]
+ \end{equation}
+ \item Ograniczenie maksymalnej sprzedaży wynikające z pojemności rynku w danym miesiącu:
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ p \in products}} sell[m][p] == maxProductsInMonth[m][p]
+ \end{equation}
+
+ \item Warunki definiujące zmienną binarną przy przekroczeniu 80 procent chłonności rynku:
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ p \in products}} sell[m][p] <= 0.8*maxProductsInMonth[m][p] + 1000000 * if80prec[m][p]
+ \end{equation}
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ p \in products}} sell[m][p] >= 0.8*maxProductsInMonth[m][p] * if80prec[m][p]
+ \end{equation}
+
+ \item Ograniczenia linearyzujące oddziaływanie zmiennych binarnych na funkcję celu:
+ \begin{equation}
+ \forall{\substack{
+ i \in scenarios\\
+ m \in months\\
+ p \in products}} lowerProfit[i][m][p] <= 1000000 * if80prec[m][p]
+ \end{equation}
+ \begin{equation}
+ \forall{\substack{
+ i \in scenarios\\
+ m \in months\\
+ p \in products}} lowerProfit[i][m][p] <= 0.2 * sell[m][p]*sellProfit[i][p]
+ \end{equation}
+ \begin{multline}
+ \forall{\substack{
+ i \in scenarios\\
+ m \in months\\
+ p \in products}} 0.2 * sell[m][p]*sellProfit[i][p] - lowerProfit[i][m][p] +\\ 1000000 * if80prec[m][p] <= 1000000;
+ \end{multline}
+
+ \item Ograniczenie sprzedaży do liczby sztuk wyprodukowanych oraz dostępnych w magazynie. Dla pierwszego miesiąca ograniczenie przyjmuje formę:
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ p \in products}} sell[m][p] <= produce[m][p]+storageStart[p]
+ \end{equation}
+ Dla każdego następnego miesiąca:
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ p \in products}} sell[m][p] <= produce[m][p] + stock[m-1][p]
+ \end{equation}
+
+ \item Ograniczenie określające stan magazynu na koniec miesiąca jako różnicę między sumą produktów wyprodukowanych i dostępnych na początku miesiąca a liczbą sprzedanych jednostek. Dla pierwszego miesiąca:
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ p \in products}} stock[m][p]==(produce[m][p] + storageStart[p])-sell[m][p]
+ \end{equation}
+ Dla każdego następnego miesiąca:
+ \begin{equation}
+ \forall{\substack{
+ m \in months\\
+ p \in products}} stock[m][p]==(produce[m][p] + stock[m-1][p])-sell[m][p]
+ \end{equation}
+
+\end{itemize}
diff --git a/Programming/WDWR/projekt/doc/sections/03-wstep-teoretyczny/04-funkcja-celu.tex b/Programming/WDWR/projekt/doc/sections/03-wstep-teoretyczny/04-funkcja-celu.tex
new file mode 100644
index 00000000..88811f48
--- /dev/null
+++ b/Programming/WDWR/projekt/doc/sections/03-wstep-teoretyczny/04-funkcja-celu.tex
@@ -0,0 +1,13 @@
+\subsection{Funkcja celu}
+\addcontentsline{toc}{subsection}{Funkcja celu}
+Funkcja celu w modelu jednokryterialnym polega na maksymalizacji wartości oczekiwanej zysku ze wszystkich analizowanych scenariuszy. W każdym ze scenariuszy zastosowano funkcję zysku o następującej postaci
+\begin{multline}
+\forall{\substack{
+ i str:
+ """Turn a section title into a short ASCII filename stem.
+
+ Polish diacritics are folded rather than dropped, so ``Rozwiązanie
+ efektywne`` becomes ``rozwiazanie-efektywne`` instead of ``rozwi-zanie``.
+ """
+ # NFKD splits 'ą' into 'a' + a combining ogonek, which the ASCII encode
+ # then discards. 'ł' has no decomposition, so it is mapped by hand.
+ folded = unicodedata.normalize("NFKD", title.replace("ł", "l").replace("Ł", "L"))
+ ascii_only = folded.encode("ascii", "ignore").decode("ascii")
+ words = re.findall(r"[A-Za-z0-9]+", ascii_only.lower())
+ return "-".join(words[:_MAX_SLUG_WORDS]) or "section"
+
+
+def _brace_span(text: str, open_index: int) -> int:
+ r"""Return the index just past the ``{...}`` group starting at *open_index*.
+
+ Counting braces rather than matching ``\{[^}]*\}`` matters: a title may
+ contain a nested group, as in ``\section{The \emph{hard} part}``.
+ """
+ depth = 0
+ for i in range(open_index, len(text)):
+ if text[i] == "{":
+ depth += 1
+ elif text[i] == "}":
+ depth -= 1
+ if depth == 0:
+ return i + 1
+ msg = "unbalanced braces in a section header"
+ raise ValueError(msg)
+
+
+# A title may run onto the following line, as EOPSY lab3 does:
+# \\section{Explanation of types of values in summary results and summary
+# processes files}
+# so the brace scan looks at a small window rather than one line.
+_TITLE_WINDOW = 6
+
+
+def _section_title(lines: list[str], index: int) -> str:
+ """Extract the title text of the header starting at *index*."""
+ window = "".join(lines[index : index + _TITLE_WINDOW])
+ open_index = window.index("{")
+ title = window[open_index + 1 : _brace_span(window, open_index) - 1]
+ return " ".join(title.split())
+
+
+def find_sections(lines: list[str], level: str) -> list[tuple[int, str]]:
+ """Return ``(line_index, title)`` for every header at *level*."""
+ header = re.compile(_HEADER.format(level=level))
+ return [
+ (i, _section_title(lines, i))
+ for i, line in enumerate(lines)
+ if header.match(line) and "{" in line
+ ]
+
+
+def _document_end(lines: list[str]) -> int:
+ r"""Index of the real ``\end{document}``, or the end of the file.
+
+ The LAST match, not the first: ECOTE's two reports quote a whole example
+ LaTeX document inside an ``lstlisting`` block, so ``\end{document}``
+ appears in the middle of the file. Taking the first one there stranded
+ everything after it and silently changed the rendered PDF -- which is
+ exactly what ``scripts/tex_fingerprint.sh --check`` caught.
+ """
+ for i in range(len(lines) - 1, -1, -1):
+ if _END_DOCUMENT.match(lines[i]):
+ return i
+ return len(lines)
+
+
+def plan(lines: list[str], level: str) -> list[tuple[str, int, int]]:
+ """Work out ``(stem, start, stop)`` for each section, as a half-open range."""
+ heads = find_sections(lines, level)
+ end = _document_end(lines)
+ # The 01-, 02- ... prefix is what keeps the names unique: two sections
+ # may legitimately share a title, and their slugs would then collide.
+ return [
+ (
+ f"{n + 1:02d}-{_slugify(title)}",
+ start,
+ heads[n + 1][0] if n + 1 < len(heads) else end,
+ )
+ for n, (start, title) in enumerate(heads)
+ ]
+
+
+def split(tex: Path, level: str, out: str, prefix: str, *, dry_run: bool) -> int:
+ """Split *tex* in place. Returns the number of sections extracted."""
+ lines = tex.read_text(encoding="utf-8").splitlines(keepends=True)
+ sections = plan(lines, level)
+ if len(sections) < _MIN_SECTIONS:
+ logger.info("%s: %d \\%s found; nothing to split", tex, len(sections), level)
+ return 0
+
+ out_dir = tex.parent / out
+ first = sections[0][1]
+ tail = lines[sections[-1][2] :]
+ body = [f"\t\\input{{{prefix}/{stem}}}\n" for stem, _, _ in sections]
+
+ if dry_run:
+ for stem, start, stop in sections:
+ logger.info(" %s/%s.tex <- lines %d-%d", out, stem, start + 1, stop)
+ return len(sections)
+
+ out_dir.mkdir(exist_ok=True)
+ for stem, start, stop in sections:
+ (out_dir / f"{stem}.tex").write_text(
+ "".join(lines[start:stop]), encoding="utf-8"
+ )
+ tex.write_text("".join([*lines[:first], *body, *tail]), encoding="utf-8")
+ logger.info("%s: %d sections -> %s/", tex, len(sections), out_dir)
+ return len(sections)
+
+
+def main(argv: list[str] | None = None) -> int:
+ """Parse arguments and split each named report."""
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("tex", nargs="+", type=Path, help="report(s) to split")
+ parser.add_argument(
+ "--level",
+ default="section",
+ choices=("chapter", "section", "subsection"),
+ help="header level to split on (default: section)",
+ )
+ parser.add_argument(
+ "--out",
+ default="sections",
+ help="directory to write the pieces into, beside the .tex (default: sections)",
+ )
+ parser.add_argument(
+ "--input-prefix",
+ default=None,
+ help="path used inside \\input{}. LaTeX resolves \\input relative to "
+ "the MAIN document, not to the including file, so a second-level "
+ "split needs e.g. --out 03-results --input-prefix sections/03-results "
+ "(default: the value of --out)",
+ )
+ parser.add_argument(
+ "--dry-run",
+ action="store_true",
+ help="print the plan without writing anything",
+ )
+ args = parser.parse_args(argv)
+ logging.basicConfig(format="%(message)s", level=logging.INFO, stream=sys.stdout)
+
+ for tex in args.tex:
+ if not tex.is_file():
+ logger.error("no such file: %s", tex)
+ return 1
+ split(
+ tex,
+ args.level,
+ args.out,
+ args.input_prefix or args.out,
+ dry_run=args.dry_run,
+ )
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/scripts/tex_fingerprint.sh b/scripts/tex_fingerprint.sh
new file mode 100755
index 00000000..24a5ff93
--- /dev/null
+++ b/scripts/tex_fingerprint.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+#
+# Print a content fingerprint of the PDF a .tex file builds to.
+#
+# Splitting a 1,876-line report into \input{} sections is only safe if the
+# document it produces is unchanged, and "unchanged" cannot be checked by
+# hashing the PDF: pdflatex stamps /CreationDate and an /ID into every build,
+# so two runs of the SAME source already differ. This fingerprints what the
+# reader sees instead -- the extracted text and the page count.
+#
+# Usage:
+# scripts/tex_fingerprint.sh print the fingerprint
+# scripts/tex_fingerprint.sh --save write it next to /tmp
+# scripts/tex_fingerprint.sh --check compare against the saved one
+#
+# Typical use, per report:
+# scripts/tex_fingerprint.sh --save report.tex # before touching it
+# ...split it into sections...
+# scripts/tex_fingerprint.sh --check report.tex # exits 1 if it moved
+
+set -euo pipefail
+
+readonly SCRIPT_NAME="${0##*/}"
+MODE="print"
+TEX=""
+WORK_DIR=""
+
+cleanup() {
+ if [[ -n "$WORK_DIR" && -d "$WORK_DIR" ]]; then
+ rm -rf "$WORK_DIR"
+ fi
+}
+trap cleanup EXIT
+
+usage() {
+ echo "Usage: $SCRIPT_NAME [--save|--check] "
+ exit 0
+}
+
+validate_requirements() {
+ if [[ -z "$TEX" ]]; then
+ echo "Error: a .tex file is required" >&2
+ exit 1
+ fi
+ if [[ ! -f "$TEX" ]]; then
+ echo "Error: no such file: $TEX" >&2
+ exit 1
+ fi
+ local tool
+ for tool in latexmk pdftotext sha256sum; do
+ command -v "$tool" > /dev/null 2>&1 || {
+ echo "Error: $tool is not installed" >&2
+ exit 1
+ }
+ done
+}
+
+# Where the saved fingerprint for a given .tex lives. Keyed by the absolute
+# path so two reports named report.tex cannot overwrite each other.
+saved_path() {
+ local abs key
+ abs="$(readlink -f "$TEX")"
+ key="$(printf '%s' "$abs" | sha256sum | cut -c1-16)"
+ printf '/tmp/tex_fingerprint_%s' "$key"
+}
+
+# Build into a scratch directory so nothing lands beside the source, and a
+# stale .aux from an earlier build cannot influence the result.
+fingerprint() {
+ local dir base
+ dir="$(dirname "$TEX")"
+ base="$(basename "$TEX")"
+ WORK_DIR="$(mktemp -d)"
+
+ # -bibtex- for the same reason Programming/ZPOB passes it: a report that
+ # declares a bibliography it never cites makes bibtex exit non-zero, and
+ # here we only care whether the rendered text moved.
+ ( cd "$dir" && latexmk -pdf -bibtex- -interaction=nonstopmode \
+ -outdir="$WORK_DIR" "$base" ) > "$WORK_DIR/build.log" 2>&1 || true
+
+ local pdf="$WORK_DIR/${base%.tex}.pdf"
+ if [[ ! -f "$pdf" ]]; then
+ echo "Error: no PDF produced; see the tail of the build log:" >&2
+ tail -20 "$WORK_DIR/build.log" >&2
+ exit 1
+ fi
+
+ local pages text_hash
+ pages="$(pdftotext "$pdf" - 2> /dev/null | grep -c $'\f' || true)"
+ text_hash="$(pdftotext -layout "$pdf" - 2> /dev/null | sha256sum | cut -c1-32)"
+ printf 'pages=%s text=%s\n' "$pages" "$text_hash"
+}
+
+main() {
+ validate_requirements
+ local fp saved
+ fp="$(fingerprint)"
+
+ case "$MODE" in
+ print) printf '%s\n' "$fp" ;;
+ save)
+ printf '%s\n' "$fp" > "$(saved_path)"
+ printf 'saved %s %s\n' "$fp" "$TEX"
+ ;;
+ check)
+ saved="$(saved_path)"
+ if [[ ! -f "$saved" ]]; then
+ echo "Error: nothing saved for $TEX -- run --save first" >&2
+ exit 1
+ fi
+ local before
+ before="$(cat "$saved")"
+ if [[ "$before" == "$fp" ]]; then
+ printf 'unchanged %s %s\n' "$fp" "$TEX"
+ else
+ printf 'CHANGED %s\n before: %s\n after: %s\n' \
+ "$TEX" "$before" "$fp" >&2
+ exit 1
+ fi
+ ;;
+ esac
+}
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --save) MODE="save"; shift ;;
+ --check) MODE="check"; shift ;;
+ -h | --help) usage ;;
+ -*) echo "Unknown option: $1" >&2; exit 1 ;;
+ *) TEX="$1"; shift ;;
+ esac
+done
+
+main "$@"