mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-10 20:27:08 +01:00
Split 19 over-cap LaTeX reports, proving each PDF is unchanged
The 250-line cap applies to prose too, and the reports were the worst
offenders -- ENUME's projectA.tex alone was 1,876 lines. Each is now a
preamble plus one \input{} per section, which is how a long LaTeX document is
normally organised; not one byte of prose was rewritten.
"The PDF is unchanged" is checked by a script rather than by eye, because
hashing the PDF cannot work: pdflatex stamps a /CreationDate and an /ID into
every build, so two runs of the SAME source already differ. tex_fingerprint.sh
compares what a reader sees instead -- page count plus a hash of the extracted
text -- and it is stable across rebuilds of untouched sources, which is the
property that makes it usable as a gate.
It earned its keep immediately. Both ECOTE reports quote an example LaTeX
document inside an lstlisting block, so \end{document} appears in the middle
of the file; splitting on the FIRST one stranded everything after it. Same
page count, different text, caught automatically. EOPSY lab3 exposed a second
bug: a \section{} title that runs onto the next line.
Result: 19 .tex over the cap -> 1. The survivor,
ELAC/.../03-building-nfa-...tex, is 418 lines of consecutive tikz figures
with no subsection to split on and needs a hand-placed boundary.
Verified: 29 splits across two passes (section, then subsection for the
pieces still over), every one reporting `unchanged` from
scripts/tex_fingerprint.sh --check.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172dj34FDpao6wsix8ZuCzE
This commit is contained in:
parent
6479773e41
commit
ffa5dad02a
@ -16,602 +16,9 @@
|
|||||||
\begin{document}
|
\begin{document}
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
\section{Regular expression}
|
\input{sections/01-regular-expression}
|
||||||
We are given following regular expression:
|
\input{sections/02-examples-of-accepted-strings}
|
||||||
\[ a^* + ba^*b + bba^*\]
|
\input{sections/03-building-nfa-using-thompson-construction-algorithm}
|
||||||
|
\input{sections/04-transforming-nfa-into-dfa-using-subset}
|
||||||
\section{Examples of accepted strings}
|
\input{sections/05-constructing-minimal-state-dfa}
|
||||||
\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}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
\section{Regular expression}
|
||||||
|
We are given following regular expression:
|
||||||
|
\[ a^* + ba^*b + bba^*\]
|
||||||
|
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
\section{Examples of accepted strings}
|
||||||
|
\begin{enumerate}
|
||||||
|
\item $ \varepsilon $
|
||||||
|
\item a
|
||||||
|
\item bab
|
||||||
|
\item bba
|
||||||
|
\item bb
|
||||||
|
\end{enumerate}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
2
NotProgramming/ENUME/projectA/sections/01-problem.tex
Normal file
2
NotProgramming/ENUME/projectA/sections/01-problem.tex
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
\section{Problem}
|
||||||
|
Write a program finding macheps in the MATLAB environment
|
||||||
@ -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
|
||||||
5
NotProgramming/ENUME/projectA/sections/03-solution.tex
Normal file
5
NotProgramming/ENUME/projectA/sections/03-solution.tex
Normal file
@ -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
|
||||||
24
NotProgramming/ENUME/projectA/sections/04-results.tex
Normal file
24
NotProgramming/ENUME/projectA/sections/04-results.tex
Normal file
@ -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}
|
||||||
|
|
||||||
3
NotProgramming/ENUME/projectA/sections/05-problem.tex
Normal file
3
NotProgramming/ENUME/projectA/sections/05-problem.tex
Normal file
@ -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).
|
||||||
|
|
||||||
@ -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
|
||||||
100
NotProgramming/ENUME/projectA/sections/07-results.tex
Normal file
100
NotProgramming/ENUME/projectA/sections/07-results.tex
Normal file
@ -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
|
||||||
@ -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}
|
||||||
|
|
||||||
13
NotProgramming/ENUME/projectA/sections/09-problem.tex
Normal file
13
NotProgramming/ENUME/projectA/sections/09-problem.tex
Normal file
@ -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.
|
||||||
|
|
||||||
|
|
||||||
@ -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
|
||||||
236
NotProgramming/ENUME/projectA/sections/11-results.tex
Normal file
236
NotProgramming/ENUME/projectA/sections/11-results.tex
Normal file
@ -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
|
||||||
@ -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}
|
||||||
|
|
||||||
2
NotProgramming/ENUME/projectA/sections/13-problem.tex
Normal file
2
NotProgramming/ENUME/projectA/sections/13-problem.tex
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
\section{Problem}
|
||||||
|
We must find eigenvalues of 5x5 matrices. Both without shifts and with shifts.
|
||||||
@ -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
|
||||||
80
NotProgramming/ENUME/projectA/sections/15-results.tex
Normal file
80
NotProgramming/ENUME/projectA/sections/15-results.tex
Normal file
@ -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
|
||||||
@ -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}
|
||||||
|
|
||||||
29
NotProgramming/ENUME/projectA/sections/17-task-1-code.tex
Normal file
29
NotProgramming/ENUME/projectA/sections/17-task-1-code.tex
Normal file
@ -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
|
||||||
217
NotProgramming/ENUME/projectA/sections/18-task-2-code.tex
Normal file
217
NotProgramming/ENUME/projectA/sections/18-task-2-code.tex
Normal file
@ -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}
|
||||||
|
|
||||||
|
|
||||||
222
NotProgramming/ENUME/projectA/sections/19-task-3-code.tex
Normal file
222
NotProgramming/ENUME/projectA/sections/19-task-3-code.tex
Normal file
@ -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
|
||||||
@ -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}
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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
|
||||||
@ -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}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
12
NotProgramming/ENUME/projectB/Report/sections/03-problem.tex
Normal file
12
NotProgramming/ENUME/projectB/Report/sections/03-problem.tex
Normal file
@ -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.
|
||||||
@ -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.
|
||||||
|
|
||||||
@ -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}
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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.
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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.
|
||||||
|
|
||||||
|
|
||||||
@ -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.
|
||||||
|
|
||||||
174
NotProgramming/ENUME/projectB/Report/sections/08-results.tex
Normal file
174
NotProgramming/ENUME/projectB/Report/sections/08-results.tex
Normal file
@ -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}
|
||||||
|
|
||||||
230
NotProgramming/ENUME/projectB/Report/sections/09-task-1.tex
Normal file
230
NotProgramming/ENUME/projectB/Report/sections/09-task-1.tex
Normal file
@ -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
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
\section{Task 2}
|
||||||
|
|
||||||
|
\input{sections/10-task-2/01-task2mm1-m}
|
||||||
|
\input{sections/10-task-2/02-task2mm2-m}
|
||||||
@ -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
|
||||||
@ -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}
|
||||||
|
|
||||||
121
NotProgramming/ENUME/projectB/Report/sections/11-task-3.tex
Normal file
121
NotProgramming/ENUME/projectB/Report/sections/11-task-3.tex
Normal file
@ -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}
|
||||||
@ -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
|
||||||
@ -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
|
||||||
@ -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}
|
||||||
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
36
NotProgramming/ENUME/projectC/sections/01-problem.tex
Normal file
36
NotProgramming/ENUME/projectC/sections/01-problem.tex
Normal file
@ -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.
|
||||||
|
|
||||||
@ -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 \]
|
||||||
|
|
||||||
50
NotProgramming/ENUME/projectC/sections/03-results.tex
Normal file
50
NotProgramming/ENUME/projectC/sections/03-results.tex
Normal file
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
|
|
||||||
@ -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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
13
NotProgramming/ENUME/projectC/sections/07-results.tex
Normal file
13
NotProgramming/ENUME/projectC/sections/07-results.tex
Normal file
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
133
NotProgramming/ENUME/projectC/sections/10-task1-m.tex
Normal file
133
NotProgramming/ENUME/projectC/sections/10-task1-m.tex
Normal file
@ -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}
|
||||||
|
|
||||||
177
NotProgramming/ENUME/projectC/sections/11-task2-m.tex
Normal file
177
NotProgramming/ENUME/projectC/sections/11-task2-m.tex
Normal file
@ -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}
|
||||||
|
|
||||||
120
NotProgramming/ENUME/projectC/sections/12-adamspcmethod-m.tex
Normal file
120
NotProgramming/ENUME/projectC/sections/12-adamspcmethod-m.tex
Normal file
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
74
NotProgramming/ENUME/projectC/sections/14-rk4-m.tex
Normal file
74
NotProgramming/ENUME/projectC/sections/14-rk4-m.tex
Normal file
@ -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}
|
||||||
|
|
||||||
159
NotProgramming/ENUME/projectC/sections/15-rk4automatic-m.tex
Normal file
159
NotProgramming/ENUME/projectC/sections/15-rk4automatic-m.tex
Normal file
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
25
NotProgramming/ENUME/projectC/sections/17-rk4phi-m.tex
Normal file
25
NotProgramming/ENUME/projectC/sections/17-rk4phi-m.tex
Normal file
@ -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}
|
||||||
|
|
||||||
|
|
||||||
@ -12,793 +12,8 @@
|
|||||||
\begin{document}
|
\begin{document}
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
\section{Zadanie 1. Sieć przepływowa}
|
\input{sections/01-zadanie-1-siec-przeplywowa}
|
||||||
|
\input{sections/02-zadanie-2-zadanie-przydzialu}
|
||||||
\subsection{Model sieciowy}
|
\input{sections/03-zadanie-3}
|
||||||
\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}
|
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|
||||||
|
|||||||
@ -9,290 +9,8 @@
|
|||||||
\setcounter{section}{-1}
|
\setcounter{section}{-1}
|
||||||
\begin{document}
|
\begin{document}
|
||||||
\maketitle
|
\maketitle
|
||||||
\section{Wstęp}
|
\input{sections/01-wstep}
|
||||||
2 Fabryki, F1, F2 \\
|
\input{sections/02-model-dwukryterialny}
|
||||||
4 Magazyny, M1, M2, M3, M4 \\
|
\input{sections/03-implementacja}
|
||||||
6 Klientów, K1, K2, K3, K4, K5, K6 \\
|
\input{sections/04-rozwiazanie-efektywne}
|
||||||
\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}
|
|
||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
37
NotProgramming/MOM/report_three/sections/01-wstep.tex
Normal file
37
NotProgramming/MOM/report_three/sections/01-wstep.tex
Normal file
@ -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}
|
||||||
@ -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}
|
||||||
|
|
||||||
104
NotProgramming/MOM/report_three/sections/03-implementacja.tex
Normal file
104
NotProgramming/MOM/report_three/sections/03-implementacja.tex
Normal file
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -11,353 +11,12 @@
|
|||||||
\date{\today}
|
\date{\today}
|
||||||
\begin{document}
|
\begin{document}
|
||||||
\maketitle
|
\maketitle
|
||||||
\section{Parametry}
|
\input{sections/01-parametry}
|
||||||
z - stan początkowy \\
|
\input{sections/02-zmienne-decyzyjne}
|
||||||
S - zakupione surowce (S = \{S1, S2\}) \\
|
\input{sections/03-zmienne-pomocnicze}
|
||||||
G1 - surowiec S1 załadowany do wagonów \\
|
\input{sections/04-funkcja-celu}
|
||||||
P - surowce w przygotowywalni (P = \{P1, P2\}) \\
|
\input{sections/05-ograniczenia}
|
||||||
O2 - surowiec S2 w zakładzie obróbki cieplnej \\
|
\input{sections/06-model-sieciowy}
|
||||||
D - półprodukty (D = \{D1, D2\}) \\
|
\input{sections/07-implementacja-modelu}
|
||||||
W - wyroby (W = \{W1, W2\}) \\
|
\input{sections/08-wyniki}
|
||||||
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}
|
|
||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
13
NotProgramming/MOM/report_two/sections/01-parametry.tex
Normal file
13
NotProgramming/MOM/report_two/sections/01-parametry.tex
Normal file
@ -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'
|
||||||
|
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
\section{Zmienne decyzyjne}
|
||||||
|
$f_{ij}$ = przepływ pomiędzy stanem i a stanem j [t] \\
|
||||||
@ -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
|
||||||
@ -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*}
|
||||||
|
|
||||||
96
NotProgramming/MOM/report_two/sections/05-ograniczenia.tex
Normal file
96
NotProgramming/MOM/report_two/sections/05-ograniczenia.tex
Normal file
@ -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}
|
||||||
|
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
\section{Model sieciowy}
|
||||||
|
\includepdf{mom2.drawio.pdf}
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
53
NotProgramming/MOM/report_two/sections/08-wyniki.tex
Normal file
53
NotProgramming/MOM/report_two/sections/08-wyniki.tex
Normal file
@ -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}
|
||||||
|
|
||||||
@ -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}
|
||||||
@ -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}
|
||||||
|
|
||||||
@ -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 \]
|
||||||
|
|
||||||
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -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}
|
||||||
@ -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} \\
|
||||||
@ -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} \\
|
||||||
@ -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} \\
|
||||||
42
NotProgramming/MOM/sections/03-zadanie-3.tex
Normal file
42
NotProgramming/MOM/sections/03-zadanie-3.tex
Normal file
@ -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}
|
||||||
@ -52,284 +52,7 @@
|
|||||||
\tableofcontents
|
\tableofcontents
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
\section{Teoria}
|
\input{sections/01-teoria}
|
||||||
\begin{frame}
|
\input{sections/02-narzedzia}
|
||||||
\frametitle{Gra komputerowa}
|
\input{sections/03-zrodla}
|
||||||
\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}
|
|
||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|||||||
@ -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}
|
||||||
@ -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}
|
||||||
|
|
||||||
|
|
||||||
@ -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}
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user