\section{A Basic Translation of MAPF to ASP}
We are now ready to describe our compilation of sum-of-costs MAPF to ASP. As we have mentioned above, this is the first compilation to ASP that handles sum-of-costs. Besides that aspect of novelty, the basic compilation that we present here is similar in many aspects to \citeauthor{ErdemKOS13}'s compilation \shortcite{ErdemKOS13} to ASP, and, in some aspects simlar to the MAPF-to-SAT compilation of \acite{Surynek14}. Below we are specific about these similarities.

As most compilations of planning problems into SAT/ASP, the makespan of the compilation is a parameter, which below we call $\mathtt{T}$.
%\begin{itemize}
%    \item $a$ refers to an agent.
%    \item $x,y$ refers to a position in the grid.
%    \item $m$ indicates a move or action. Where $m \in \{up,down,left,right,wait\}$.
%\end{itemize}

\subsubsection{Atoms}
We use the following atoms:
\begin{itemize}
\item $agent(a)$: to express that $A$ is an agent,
\item $goal(a,x,y)$: specifies that the goal cell for agent $a$ is $(x,y)$,
\item $obstacle(x,y)$: specifies that cell $(x,y)$ is an obstacle,
\item $at(a,x,y,t)$: specifies that agent $a$ is at $(x,y)$ at time $t$,
\item $exec(a,m,t)$: specifies that agent $a$ executes move $m$ at time $t$,
\item $at\_goal(a,t)$: specifies that agent $a$ is at the goal at time $t$,
\item $time(t)$: $t$ is a time instant,
\item $move(m)$: $m$ is a move.
\end{itemize}
Finally, we use atoms $rangeX(x)$ and $rangeY(y)$ to specify that $(X,Y)$ is within the limits of the grid.

\subsubsection{Instance Specification}
To specify a particular MAPF instance, we define facts for atoms of the form $agent(a)$, for each $a\in A$, $obstacle(x,y)$ for each $(x,y)$ that is marked as an obstacle in the grid, $rangeX(x)$ for each $x\in\{1,\ldots,w\}$, where $w$ is the width of the grid, and $rangeY(y)$ for each $y\in\{1,\ldots,h\}$, where $h$ is the height of the grid. Additionally, we define the initial cells for each agent, adding one fact of the form $at(a,x_a,y_a,0)$ for each agent $a\in \mathcal{A}$, where $(x_a,y_a)=init(a)$. Furthermore, we add an atom of the form $time(t)$ for every $t\in\{1,\dots,\mathtt{T}\}$. The number of rules needed to encode a MAPF instance is therefore in $\Theta(|\mathcal{A}| + \mathtt{T} + |V|)$.

\subsubsection{Effects}
To encode the effects of the five actions, we use a single rule written as follows:
\begin{equation}\small\label{encoding:effectsone}
\begin{split}
at(A,X,Y,T) \leftarrow &exec(A,M,T-1),\\&at(A,X',Y',T-1), \\&delta(M,X',Y',X,Y).
\end{split}
\end{equation}
which specifies that if agent $A$ is at position $(X',Y')$ in time instant $T-1$, then it will be in position $(X,Y)$ in time instant $T$ iff $(X,Y)$ and $(X',Y')$ satisfy predicate $delta$. Auxiliary predicate $delta$ is used to establish a relation between $(X,Y)$ and $(X',Y')$ given a certain move $M$ in the following way:
\begin{equation}\small\label{encoding:delta}
\begin{split}
&delta(\Right,X,Y,X+1,Y) \leftarrow rangeX(X), rangeY(Y),\\
&delta(\Left,X,Y,X-1,Y) \leftarrow rangeX(X), rangeY(Y),\\
&delta(\Up,X,Y,X,Y+1) \leftarrow rangeX(X), rangeY(Y),\\
&delta(\Down,X,Y,X,Y-1) \leftarrow rangeX(X), rangeY(Y),\\
&delta(\Wait,X,Y,X,Y) \leftarrow rangeX(X),rangeY(Y).
\end{split}
\end{equation}
A grounding time predicate $delta$ results in 5 rules per each position of the grid. This defines that the total number of grounded instances for rule \eqref{encoding:effectsone} is proportional to the size of the grid, the number of agents and the number of time instants. The total number of instances for rules of the form \eqref{encoding:effectsone} and \eqref{encoding:delta} is in $\Theta(|\mathcal{A}|\cdot |V| \cdot \mathtt{T})$.

\subsubsection{Parallel move execution}
We need to encode that each agent performs exactly one move at each time instant. To do this we write the following rule:
\begin{equation}\small\label{encoding:delta}
\begin{split}
|\{exec(A,M,T-1) : move(M) \}| = 1 \leftarrow &time(T),\\&agent(A).
\end{split}
\end{equation}
Upon grounding the number of instances of this rule is in $\Theta(|\mathcal{A}|\cdot \mathtt{T})$.
\subsubsection{Legal positions}
We need to express that the agents move through the vertices in the graph; that is, they cannot exit the grid or visit an obstacle cell. We do so using the following three rules:
\begin{equation}\label{encoding:legal}\small
    \begin{split}
&\leftarrow at(A,X,Y,T), not\: rangeX(X),\\
&\leftarrow at(A,X,Y,T), not\: rangeY(Y),\\
&\leftarrow at(A,X,Y,T), obstacle(X,Y). %no hay robots encima de obstaculos
    \end{split}
\end{equation}
The total number of grounded rules for the rules of form \eqref{encoding:legal} is in $\Theta(|\mathcal{A}| \cdot |V| \cdot \mathtt{T})$, since it depends on the number of atoms of the form $at$, $obstacle$, $rangeX$, and $rangeY$.

\subsubsection{Vertex Conflicts}
To express that no agents can be at the same vertex we use the following constraint, which is similar to those used in the encodings to ASP by \acite{ErdemKOS13,GebserOOS18} and \acite{SurynekFSB16}.
\begin{equation}\small\label{encoding:vertexone}
    \leftarrow at(A,X,Y,T), at(A',X,Y,T)
\end{equation}
The number of instances for this rule \eqref{encoding:vertexone} after grounding is $\Theta(|\mathcal{A}|^2 \cdot |V| \cdot \mathtt{T})$. Note that this is the first rule so far whose instantiation is quadratic on the number of agents. This motivates the improvement we present later in the following section.
\subsubsection{Swap Conflicts}
No pair of agents can swap their positions. We express this avoiding horizontal and vertical swaps using the following constraints.
\begin{equation}\small\label{encoding:swapone}
  \begin{split}
        \leftarrow &at(A,X+1,Y,T-1), at(A',X,Y,T-1),\\
        &at(A,X,Y,T), at(A',X+1,Y,T). \text{\% horizontal swap} \\
        \leftarrow &at(A,X,Y+1,T-1), at(A',X,Y,T-1),\\
        &at(A,X,Y,T), at(A',X,Y+1,T). \text{\% vertical swap}
  \end{split}
\end{equation}
The number of ground rules for \eqref{encoding:swapone} is in $\Theta(|\mathcal{A}|^2 \cdot |V| \cdot \mathtt{T})$.

\subsubsection{Goal Achievement}
We specify with a constraint that no agent is away from its goal at time $\mathtt{T}$:
\begin{equation}\small\label{encoding:goal}
  \begin{split}
&at\_goal(A,T) \leftarrow at(A,X,Y,T), goal(A,X,Y),\\
&\leftarrow agent(A), not \; at\_goal(A,\mathtt{T}).
\end{split}
\end{equation}
The number of instances for rules \eqref{encoding:goal} is $\Theta(\mathcal{A} \cdot |V| \cdot \mathtt{T})$.
\subsubsection{Size of Basic Encoding}
After grounding, it follows that the size of the total encoding is in $\Theta(|\mathcal{A}|^2 \cdot |V| \cdot \mathtt{T})$. That is, it is quadratic in the number of agents, linear in the size of the grid, and linear in the makespan parameter $\mathtt{T}$.


\subsection*{Source}

\url{http://evgenii.com/blog/basic-trigonometric-identities}

Basic triginometric identities by Evgenii Neumerzhitckii is licensed under a Creative Commons Attribution 4.0 International License.


\chapter{Collective Communication}
\label{chapter:coll}

\input{operations}

When the nodes of a distributed-memory architecture collaborate
to solve a given problem, inherently computation previously
performed on a single node is now distributed among the nodes,
and communication is performed when data is shared, or contributions from
different nodes must be consolidated.
Communication operations that simultaneously involve a group of nodes
are called {\em collective communication} operations.
In our discussions, we will assume that the group includes all nodes.
\plapack makes heavy use of collective communication,
so its efficient implementation is crucial to attaining
scalable and high performance.

The most typically encountered collective communications, discussed
in this section, fall into two categories:
\begin{itemize}
\item
{\bf Data redistribution operations:}
broadcast, scatter, gather, and allgather.
These operations move data between processors.
\item
{\bf Data consolidation operations:}
reduce(-to-one), reduce-scatter, and allreduce.
These operations consolidate contributions from different processors
by applying a reduction operation.
We will only consider reduction operations that are both commutative
and associative.
\end{itemize}
The operations discussed are illustrated in Fig.~\ref{fig:operations}.
In that figure, $ x $ indicates a vector of data of length $ n $.
For some operations, $ x $ is subdivided into subvectors
$ x_i $, $ i = 0, \cdots, p-1 $, where $ p $ equals the number of nodes.
A superscript is used to indicate a vector that must be reduced
with other vectors from other nodes.  $ \sum_{j} x^{(j)} $ indicates the
result of that reduction.
The summation sign is used because summation is the
most commonly encountered reduction operation.

We present these collective communications as pairs of
{\em dual} operation.  We will show later that an implementation
of one of the dual operations can be transformed into that of the other dual
operation by reversing the communication (and adding to or deleting
reduction operations from the implementation).  These dual pairs are indicated
by the groupings in Fig.~\ref{fig:operations} (separated by the thick lines):
{broadcast and reduce(-to-one)},
{scatter and gather}, and
{allgather and reduce-scatter}.
{Allreduce} is the only operation that does not have a dual
(or it can be viewed as its own dual).


\documentclass[compress,9pt]{beamer} % TALK

\usepackage{pgfpages}

%\setbeameroption{hide notes} % solo muestra la presentación.
%\setbeameroption{show only notes} % solo muestras las notas.
%\setbeameroption{show notes on second screen=right} % presentación el doble de ancha que contiene las diapositivas y las notas.

\usepackage{tikz}   %TikZ is required for this to work.  Make sure this exists before the next line

\usepackage{tikz-3dplot} %requires 3dplot.sty to be in same directory, or in your LaTeX installation

\usetikzlibrary{babel}

% tikz-3dplot-circleofsphere: To draw 3D spheres ----------
\usepackage{tikz-3dplot-circleofsphere} %requires tikz-3dplot-circleofsphere to be in same directory, or in your LaTeX installation

\begin{document}

	\section{Physics: Newton's and Kepler's dynamics.}
	\begin{frame}[fragile,label={frm:newtonGravit}]{Newton's law of universal gravitation}
		%requires tikz-3dplot-circleofsphere to be in same directory, or in your LaTeX installation
		% Figure: Universal gravity law
		\begin{figure}[H]
			\centering
			% Select a perspective
			\tdplotsetmaincoords{75}{115}
			\begin{tikzpicture}[scale=1,tdplot_main_coords,>=latex,line join=bevel]
			% Parameters ---------------------
			% Coordinates parameters
			\pgfmathsetmacro{\sizeCoordX}{5.2*.6}
			\pgfmathsetmacro{\sizeCoordY}{5.2*.6}
			\pgfmathsetmacro{\sizeCoordZ}{4.2*.6}
			\coordinate (O) at (0,0,0);

			% m satellite position parameters
			\pgfmathsetmacro{\mx}{.7 * \sizeCoordX}
			\pgfmathsetmacro{\my}{0.9 * \sizeCoordY}
			\pgfmathsetmacro{\mz}{0.7 * \sizeCoordZ}

			% It is very important to get redundant parenthesis
			% Radius = rho
			\pgfmathsetmacro{\mr}{sqrt{((\mx)^2 + (\my)^2 + (\mz)^2)}}
			% theta = epsilon
			% \pgfmathsetmacro{\mEpsilon}{acos{ ( (\mz)/(\mr) ) }}
			\pgfmathsetmacro{\mEpsilon}{atan{(sqrt{((\mx)^2 + (\my)^2)}/(\mz))}}
			% phi = alpha
			\pgfmathsetmacro{\mAlpha}{atan{((\my) / (\mx))}}
			% polar angle = beta
			\pgfmathsetmacro{\mBeta}{atan{((\mz) / (sqrt{((\mx)^2 + (\my)^2)}))}}

			% Debug info
			% \node [label={right:\mr}] at (0, 0, -3) {mr};
			% \node [label={right:\mEpsilon}] at (0, 0, -4) {mEpsilon};
			% \node [label={right:\mAlpha}] at (0, 0, -5) {mAlpha};
			% \node [label={right:\mBeta}] at (0, 0, -6) {mBeta};

			% Little mass size
			\pgfmathsetmacro{\mSize}{15}

			% M Earth parameters
			\pgfmathsetmacro{\radiusXY}{.22 * \sizeCoordX}
			\pgfmathsetmacro{\radiusZ}{.19 * \sizeCoordX}

			% Fg parameters
			\pgfmathsetmacro{\FgX}{.3 * \mx}
			\pgfmathsetmacro{\FgY}{.3 * \my}
			\pgfmathsetmacro{\FgZ}{.3 * \mz}

			% Figures ---------------------
			% Circle M Earth.
			\begin{scope}
			\filldraw[tdplot_screen_coords, gray!30] (0,0,0) circle (\radiusXY);
			\tdplotCsDrawLatCircle[gray]{\radiusXY}{0}
			\end{scope}
			%\node [label={left:$M_\oplus$}] at (0,-\radiusXY,\radiusZ) {};
			\node [anchor=south east] {$M_\oplus$};

			% Circle m satellite.
			\node [draw, circle, fill=gray!30, minimum size = \mSize, label=above:$m$] at (\mx, \my, \mz) {};

			% Satellite trajectory
			\tdplotCsDrawCircle[blue]{\mr}{\mAlpha}{-\mBeta}{0}
			\node [label={[blue]south east:Orbital plane}] at (0,\my,\mz) {};
			% Coordinates
			\draw[thick,->] (O) -- (\sizeCoordX,0,0) node[anchor=north east]{$x$};
			\draw[thick,->] (O) -- (0,\sizeCoordY,0) node[anchor=north west]{$y$};
			\draw[thick,->] (O) -- (0,0,0.8
			7*\sizeCoordZ) node[anchor=south]{$z$};
			\draw[dashed] (O) -- (-0.7*\sizeCoordX,0,0);
			\draw[dashed] (O) -- (0,-0.7*\sizeCoordY,0);
			% \draw[dashed] (O) -- (0,0,-\sizeCoordZ);

			% Satellite
			% r vector
			\draw[-stealth,color=blue,very thick] (0,0,0) -- (\mx,\my,\mz);
			\node [label={[blue]left:$\mathbf{r}$}] at (\mx/2, \my/2, \mz/2) {};
			% r Projection
			\draw[dotted] (0,0,0) -- (\mx,\my,0) --  (\mx,\my,\mz);
			\draw[dotted] (\mx,0,0) -- (\mx,\my,0) node[anchor=north east]{Equatorial plane};
			\draw[dotted] (\mx,\my,0) -- (0,\my,0);

			% F_g vector
			\draw[-stealth,color=blue,very thick]
			(\FgX+\mx, \FgY+\my, \FgZ+\mz) -- (\mx, \my, \mz);
			% \node [label={[shift={(\mx+\Fg/2, \my+\Fg/2, \mz+\Fg/2)}]$\mathbf{F_g}$}] {};
			% \node [label={[blue]right:$\mathbf{F_g}$}] at (\mx+\FgX,\my+\FgY,\mz+\FgZ) {};
			\node [label={[blue]$\mathbf{F_g}$}] at (\mx+\FgX,\my+\FgY,\mz+\FgZ) {};
			\end{tikzpicture}
			%\caption{Newton's law of universal gravitation.} \label{fig:NewtonLaw}
		\end{figure}
		% Show equation
		\begin{equation}\label{eq:newton_gravity}
		\text{Newton's law of universal gravitation: } \mathbf{F_g} = -G\frac{{M_\oplus}{m}}{{r^2}}\left(\frac{\mathbf{r}}{r}\right)
		\end{equation}
	\end{frame}

	\begin{frame}[fragile]{Kepler's second law}
		\begin{figure}[H]
			\centering
			% Author: https://tex.stackexchange.com/questions/122122/best-way-to-illustrate-keplers-2nd-law-with-tikz
			% We define the orbit as a macro because we will use it twice, first for clipping and then
			% to actually draw the ellipse. This way we avoid inconsistencies.
			\def\orbit{(1.5,0) ellipse(2.5cm and 2cm)}

			\begin{tikzpicture}
			\fill (3,0) coordinate (O) circle (5pt) node[below left =7pt] {$M_\oplus$};%

			\coordinate (m1) at (0.90,2.30);
			\coordinate (m2) at (0.65,1.90);
			\coordinate (m3) at (3.5,-2.2);
			\coordinate (m4) at (4.0,-0.4);
			% Show m
			\fill (m2) circle (2pt) node[above left] {$m$};%

			% The gray shaded regions
			\begin{scope}
			\clip \orbit;
			\filldraw[fill=gray!40,opacity=0.5] (O) -- (m1) -- (m2) -- cycle;
			\filldraw[fill=gray!40,opacity=0.5] (O) -- (m3) -- (m4) -- cycle;
			\end{scope}

			% The ellipse
			\draw \orbit;
			% major and minor axis
			\draw[dashed] (1.5,0) coordinate (M) --node[above]{$a$}  (-1.0,0);
			\draw[dashed] (1.5,-2.0) -- (M) node[below left]{$b$};
			% true anomaly: nu
			\draw[-stealth,blue] (3.5,0) arc (0:140:0.5)node[above right]{$\nu$};
			\draw[dotted] (3,0) -- (4,0);
			\end{tikzpicture}
			\caption{Kepler's second law.}%\label{fig:Kepler2Law}
		\end{figure}
	\end{frame}

	% Orbital elements or Keplerian elements
	\begin{frame}[fragile,label={frm:elipse+}]
		%
		\begin{figure}[H]
			\centering
			\def\r{3.5}
			\pgfmathsetmacro{\inclination}{35}
			\pgfmathsetmacro{\nuSatellite}{55}
			\pgfmathsetmacro{\gammaAngle}{290}

			\tdplotsetmaincoords{70}{165}
			\begin{tikzpicture}[tdplot_main_coords]
			\onslide<1->{
				\fill (0,0) coordinate (O) circle (5pt) node[left =7pt] {$M_\oplus$};

				% Draw equatorial ellipse
				%\tdplotdrawarc[thin]{(0,0,0)}{\r}{-90}{205}{label={[xshift=-3.7cm, yshift=0.9cm]Equatorial plane}}{}
				%\tdplotdrawarc[dotted]{(0,0,0)}{\r}{205}{270}{}{}
				% Draw equatorial plane
				\draw[] (0,-\r,0) -- (\r,-\r,0)  node[below]{Equatorial plane} -- (\r,\r,0) -- (-\r,\r,0) -- (-\r,-0.65*\r,0);
				\draw[dotted] (-\r,-0.65*\r,0) -- (-\r,-\r,0) -- (0,-\r,0);

				% Draw ellipses intersection. Line of nodes
				\draw[dashed] (0,-1.3*\r,0) -- (0,1.3*\r,0) node[right] {Line of nodes};
				% Draw gamma direction
			}

			\onslide<2->{
				% Set gamma direction
				\tdplotsetcoord{Pg}{1.3*\r}{90}{\gammaAngle}
				\draw[->] (0,0,0) -- (Pg) node[anchor=east] {Direcc. de referencia $\boldsymbol{\gamma}$};
			}
			\onslide<1->{
				% Create a new rotated system in the center
				\tdplotsetrotatedcoords{0}{\inclination}{90}

				% Draw orbital ellipse
				\tdplotdrawarc[tdplot_rotated_coords,thin,blue]{(0,0,0)}{\r}{-125}{180}{label={[xshift=-5.7cm, yshift=-2.2cm]Orbital plane}}{}
				\tdplotdrawarc[tdplot_rotated_coords,dotted,blue]{(0,0,0)}{\r}{180}{235}{}{}

				% Define m position
				\pgfmathsetmacro{\omegaSatellite}{90}
				\pgfmathsetmacro{\xmRot}{\r*cos(\omegaSatellite+\nuSatellite)}
				\pgfmathsetmacro{\ymRot}{\r*sin(\omegaSatellite+\nuSatellite)}
				\pgfmathsetmacro{\zmRot}{0}
				% Draw a vector to m
				\draw[tdplot_rotated_coords,thin,->,blue] (0,0,0) -- (\xmRot,\ymRot,\zmRot);
				% Draw a mass
				\filldraw[tdplot_rotated_coords, blue] (\xmRot,\ymRot,\zmRot) circle (2pt) node[above left] {$m$};
			}
			\onslide<5->{
				% Draw periapsis line
				\draw[dashed,tdplot_rotated_coords,blue] (0,0,0) -- (0,\r,0) node[anchor=south west] {Periapsis};
			}
			\onslide<5->{
				% Draw omega angle
				\tdplotdrawarc[tdplot_rotated_coords,thick,-stealth,blue]{(0,0,0)}{0.4*\r}{0}{\omegaSatellite}{anchor=south west}{$\omega$}
				% Draw nu angle
				\tdplotdrawarc[tdplot_rotated_coords,thick,-stealth,blue]{(0,0,0)}{0.4*\r}{\omegaSatellite}{\omegaSatellite+\nuSatellite}{anchor=south west}{$\nu$}
			}
			\onslide<3->{
				% Create rotated shifted system at (0,\r,0)
				\tdplotresetrotatedcoordsorigin
				\tdplotsetrotatedcoords{0}{0}{180}
				% Draw \Omega
				% Hidden part of the arc
				%% \tdplotdrawarc[tdplot_rotated_coords,dashed,thick,brown]{(0,0,0)}{0.4*\r}{0}{90}{anchor=south}{}%{$\Omega$}
				% Visible part of the arc
				\tdplotdrawarc[tdplot_rotated_coords,thick,-stealth,brown]{(0,0,0)}{0.4*\r}{\gammaAngle-180}{270}{anchor=north east}{$\Omega$}
				% Shift the rotated coordinates
				\coordinate (Shift) at (0,\r,0);
				\tdplotsetrotatedcoordsorigin{(Shift)}
				% \draw[thick,tdplot_rotated_coords,->,blue] (0,0,0) -- (.5,0,0) node[anchor=north west]{$x_2$};
				% \draw[thick,tdplot_rotated_coords,->,blue] (0,0,0) -- (0,.5,0) node[anchor=north]{$y_2$};
				% \draw[thick,tdplot_rotated_coords,->,blue] (0,0,0) -- (0,0,.5) node[anchor=south west]{$z_2$};
			}
			\onslide<4->{
				% Draw inclination angle
				\tdplotsetrotatedthetaplanecoords{0}
				\tdplotdrawarc[tdplot_rotated_coords,thick,-stealth,brown]{(Shift)}{0.3*\r}{90}{90-\inclination}{anchor=west}{$i$}
			}
			\end{tikzpicture}
			\caption{Orbital elements or Keplerian elements}\label{fig:elipseNodos2}
		\end{figure}
	\end{frame}

	\section{Rotate a box around some axes.}
	\begin{frame}{Rotate box around $X$ axis.}
		\begin{figure}[h]
			\centering
			\def\r{3.5}
			\pgfmathsetmacro{\alphaNextBox}{90}
			\pgfmathsetmacro{\betaNextBox}{-55}
			\pgfmathsetmacro{\gammaNextBox}{-90}
			%%% \pgfmathsetmacro{\inclination}{70}
			\pgfmathsetmacro{\alphaEuler}{0}
			\pgfmathsetmacro{\betaEuler}{0}
			\pgfmathsetmacro{\gammaEuler}{47}

			\tdplotsetmaincoords{70}{120}
			\begin{tikzpicture}[tdplot_main_coords]
			% Drawing XYZ coordinates system
			\def \lenX {1.0*\r}
			\def \lenY {1.3*\r}
			\def \lenZ {1.0*\r}
			\def \boxX{.7*\r}
			\def \boxY{.9*\r}
			\def \boxZ{.2*\r}
			% Calculate box corner length
			\pgfmathsetmacro{\boxCornerLen}{sqrt{((\boxX)^2 + (\boxY)^2 + (\boxZ)^2)}}
			% Draw coordinate system
			\draw[dashed] (0,0,0) -- (\boxX,0,0);
			\draw[->,thick] (\boxX,0,0) -- (\lenX,0,0) node[left] {$X$};
			\draw[dashed] (0,0,0) -- (0,\boxY,0);
			\draw[->,thick] (0,\boxY,0) -- (0,\lenY,0) node[anchor=north west] {$Y$};
			\draw[dashed] (0,0,0) -- (0,0,0.6*\lenZ);
			\draw[->,thick] (0,0,0.6*\lenZ) -- (0,0,\lenZ) node[anchor=south] {$Z$};
			% Draw gravity vector
			\draw[-stealth,thin] (-0.8*\r,1.1*\r,0) -- (-0.8*\r,1.1*\r,-.3*\r) node[anchor=south west] {$\mathbf{g}$};

			% Drawing horizontal box:
			% Get corner polar coordinate
			\tdplotgetpolarcoords{\boxX}{\boxY}{\boxZ}
			\tdplotsetcoord{Box}{\boxCornerLen}{\tdplotrestheta}{\tdplotresphi}
			% Draw a box
			% \draw[] (O) -- (Boxx);
			% \draw[] (O) -- (Boxy);
			% \draw[] (O) -- (Boxz);
			\draw[] (Boxx) -- (Boxxy);
			\draw[] (Boxy) -- (Boxxy);
			\draw[] (Boxx) -- (Boxxz);
			\draw[] (Boxz) -- (Boxxz);
			\draw[] (Boxy) -- (Boxyz);
			\draw[] (Boxz) -- (Boxyz);
			\draw[] (Boxxy) -- (Box);
			\draw[] (Boxxz) -- (Box);
			\draw[] (Boxyz) -- (Box);
			\pause
			% Create a new rotated system in the center
			\tdplotsetrotatedcoords{\alphaEuler}{\betaEuler}{\gammaEuler}
			% Draw new coordinates system
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (1.4*\boxX,0,0);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (1.4*\boxX,0,0) -- (1.3*\lenX,0,0) node[anchor=north east]{$E$};
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (0,0.7*\boxY,0);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (0,0.7*\boxY,0) -- (0,0.8*\lenY,0) node[anchor=south west]{$\mathbf{N}$};
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (0,0,0.6*\lenZ);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (0,0,0.6*\lenZ) -- (0,0,0.8*\lenZ) node[anchor=north east]{$Z$};
			\pause
			% Rotating box around X axis:
			% Create a new rotated system in the center.
			\tdplotsetrotatedcoords{\alphaNextBox}{\betaNextBox}{\gammaNextBox}
			% Draw a box in the  new coordinates system
			\draw[tdplot_rotated_coords,gray] (\boxX,0,0) -- (\boxX,\boxY,0);
			\draw[tdplot_rotated_coords,gray] (\boxX,\boxY,0) -- (0,\boxY,0);
			\draw[tdplot_rotated_coords,gray] (0,\boxY,0) -- (0,\boxY,\boxZ);
			\draw[tdplot_rotated_coords,dashed,gray] (0,\boxY,\boxZ) -- (0,0,\boxZ);
			\draw[tdplot_rotated_coords,dashed,gray] (0,0,\boxZ) -- (\boxX,0,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,0,\boxZ) -- (\boxX,0,0);
			\draw[tdplot_rotated_coords,gray] (\boxX,0,0) -- (\boxX,0,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,0,\boxZ) -- (\boxX,\boxY,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,\boxY,\boxZ) -- (0,\boxY,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,\boxY,\boxZ) -- (\boxX,\boxY,0);
			\draw[tdplot_rotated_coords,dashed,gray] (0,0,\boxZ) -- (0,0,0);
			\draw[tdplot_rotated_coords,gray] (0,0,0) -- (0,\boxY,0);

			\tdplotsetrotatedcoordsorigin{(Shift)}
			% Shift the rotated coordinates
			\coordinate (Shift) at (\boxX,0,0);
			% Draw rotation
			\tdplotsetthetaplanecoords{90}
			% \tdplotdrawarc[coordinate system, draw styles]{center}{r}{angle start}{angle end}{label options}{label}
			\tdplotdrawarc[tdplot_rotated_coords,gray,thick,dotted,<->]{(Shift)}{\boxY}{90}{90+\betaNextBox}{anchor=west}{}

			% Resets the origin of the rotated coordinate system back to the origin of the main coordinate system.
			%\tdplotresetrotatedcoordsorigin
			\coordinate (Shift) at (0,0,0);
			\end{tikzpicture}
		\end{figure}
	\end{frame}

	\begin{frame}[fragile]{Rotate box around $Y$ axis.}
		\begin{figure}[h]
			\centering
			\def\r{3.5}
			\pgfmathsetmacro{\alphaNextBox}{0}%{90}
			\pgfmathsetmacro{\betaNextBox}{-50}%{-55}
			\pgfmathsetmacro{\gammaNextBox}{0}%{-90}
			%%% \pgfmathsetmacro{\inclination}{70}
			\pgfmathsetmacro{\alphaEuler}{0}
			\pgfmathsetmacro{\betaEuler}{0}
			\pgfmathsetmacro{\gammaEuler}{47}

			\tdplotsetmaincoords{70}{120}
			\begin{tikzpicture}[tdplot_main_coords]
			% Drawing XYZ coordinates system
			\def \lenX {1.0*\r}
			\def \lenY {1.3*\r}
			\def \lenZ {1.0*\r}
			\def \boxX{.7*\r}
			\def \boxY{.9*\r}
			\def \boxZ{.2*\r}
			% Calculate box corner length
			\pgfmathsetmacro{\boxCornerLen}{sqrt{((\boxX)^2 + (\boxY)^2 + (\boxZ)^2)}}
			% Draw coordinate system
			\draw[dashed] (0,0,0) -- (\boxX,0,0);
			\draw[->,thick] (\boxX,0,0) -- (\lenX,0,0) node[left] {$X$};
			\draw[dashed] (0,0,0) -- (0,\boxY,0);
			\draw[->,thick] (0,\boxY,0) -- (0,\lenY,0) node[anchor=north west] {$Y$};
			\draw[dashed] (0,0,0) -- (0,0,0.6*\lenZ);
			\draw[->,thick] (0,0,0.6*\lenZ) -- (0,0,\lenZ) node[anchor=south] {$Z$};
			% Draw gravity vector
			\draw[-stealth,thin] (-0.8*\r,1.1*\r,0) -- (-0.8*\r,1.1*\r,-.3*\r) node[anchor=south west] {$\mathbf{g}$};

			% Drawing horizontal box:
			% Get corner polar coordinate
			\tdplotgetpolarcoords{\boxX}{\boxY}{\boxZ}
			\tdplotsetcoord{Box}{\boxCornerLen}{\tdplotrestheta}{\tdplotresphi}
			% Draw a box
			% \draw[] (O) -- (Boxx);
			% \draw[] (O) -- (Boxy);
			% \draw[] (O) -- (Boxz);
			\draw[] (Boxx) -- (Boxxy);
			\draw[] (Boxy) -- (Boxxy);
			\draw[] (Boxx) -- (Boxxz);
			\draw[] (Boxz) -- (Boxxz);
			\draw[] (Boxy) -- (Boxyz);
			\draw[] (Boxz) -- (Boxyz);
			\draw[] (Boxxy) -- (Box);
			\draw[] (Boxxz) -- (Box);
			\draw[] (Boxyz) -- (Box);
			\pause
			% Create a new rotated system in the center
			\tdplotsetrotatedcoords{\alphaEuler}{\betaEuler}{\gammaEuler}
			% Draw new coordinates system
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (1.4*\boxX,0,0);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (1.4*\boxX,0,0) -- (1.3*\lenX,0,0) node[anchor=north east]{$E$};
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (0,0.7*\boxY,0);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (0,0.7*\boxY,0) -- (0,0.8*\lenY,0) node[anchor=south west]{$\mathbf{N}$};
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (0,0,0.6*\lenZ);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (0,0,0.6*\lenZ) -- (0,0,0.8*\lenZ) node[anchor=north east]{$Z$};
			\pause
			% Rotating box around one new axis:
			% Create a new rotated system in the center.
			\tdplotsetrotatedcoords{\alphaNextBox}{\betaNextBox}{\gammaNextBox}
			% Draw a box in the  new coordinates system
			\draw[tdplot_rotated_coords,gray] (\boxX,0,0) -- (\boxX,\boxY,0);
			\draw[tdplot_rotated_coords,gray] (\boxX,\boxY,0) -- (0,\boxY,0);
			\draw[tdplot_rotated_coords,gray] (0,\boxY,0) -- (0,\boxY,\boxZ);
			\draw[tdplot_rotated_coords,dashed,gray] (0,\boxY,\boxZ) -- (0,0,\boxZ);
			\draw[tdplot_rotated_coords,dashed,gray] (0,0,\boxZ) -- (\boxX,0,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,0,\boxZ) -- (\boxX,0,0);
			\draw[tdplot_rotated_coords,gray] (\boxX,0,0) -- (\boxX,0,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,0,\boxZ) -- (\boxX,\boxY,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,\boxY,\boxZ) -- (0,\boxY,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,\boxY,\boxZ) -- (\boxX,\boxY,0);
			\draw[tdplot_rotated_coords,dashed,gray] (0,0,\boxZ) -- (0,0,0);
			\draw[tdplot_rotated_coords,gray] (0,0,0) -- (0,\boxY,0);
			\draw[tdplot_rotated_coords,gray] (0,0,0) -- (\boxX,0,0);

			\tdplotsetthetaplanecoords{0}
			\tdplotdrawarc[tdplot_rotated_coords,gray,thick,dotted,<->]{(0,0,0)}{\boxX}{90}{90+\betaNextBox}{anchor=west}{}
			\end{tikzpicture}
			%\caption{Giros en torno al eje $X$ para comprobar el comportamiento distorsionado de la brújula.}\label{fig:rollRotation}
		\end{figure}
	\end{frame}

	\begin{frame}[fragile]{Rotate a box around $Z$ axis}
		\begin{figure}[H]
			\centering
			\def\r{3.5}
			\pgfmathsetmacro{\alphaEuler}{0}
			\pgfmathsetmacro{\betaEuler}{0}
			\pgfmathsetmacro{\gammaEuler}{47}

			\pgfmathsetmacro{\nuSatellite}{55}
			\pgfmathsetmacro{\gammaAngle}{290}

			%\tdplotsetmaincoords{70}{155}
			\tdplotsetmaincoords{70}{120}
			\begin{tikzpicture}[tdplot_main_coords]
			% Draw ENZ coordinates system
			\def \lenX {1.0*\r}
			\def \lenY {1.3*\r}
			\def \lenZ {0.5*\r}
			\def \boxX{.7*\r}
			\def \boxY{.9*\r}
			\def \boxZ{.2*\r}

			% Calculate box corner length
			\pgfmathsetmacro{\boxCornerLen}{sqrt{((\boxX)^2 + (\boxY)^2 + (\boxZ)^2)}}
			% Draw coordinate system
			\draw[dashed] (0,0,0) -- (\boxX,0,0);
			\draw[->,thick] (\boxX,0,0) -- (\lenX,0,0) node[left] {$E$};
			\draw[dashed] (0,0,0) -- (0,\boxY,0);
			\draw[->,thick] (0,\boxY,0) -- (0,\lenY,0) node[anchor=north west] {$\mathbf{N}$};
			\draw[dashed] (0,0,0) -- (0,0,0.6*\lenZ);
			\draw[->,thick] (0,0,0.6*\lenZ) -- (0,0,\lenZ) node[anchor=south] {$Z$};
			% Draw gravity vector
			\draw[-stealth,thin] (-0.8*\r,1.1*\r,0) -- (-0.8*\r,1.1*\r,-.3*\r) node[anchor=south west] {$\mathbf{g}$};

			% Drawing horizontal box:
			% Get corner polar coordinate
			\tdplotgetpolarcoords{\boxX}{\boxY}{\boxZ}
			\tdplotsetcoord{Box}{\boxCornerLen}{\tdplotrestheta}{\tdplotresphi}
			% Draw a box
			% \draw[] (O) -- (Boxx);
			% \draw[] (O) -- (Boxy);
			% \draw[] (O) -- (Boxz);
			\draw[] (Boxx) -- (Boxxy);
			\draw[] (Boxy) -- (Boxxy);
			\draw[] (Boxx) -- (Boxxz);
			\draw[] (Boxz) -- (Boxxz);
			\draw[] (Boxy) -- (Boxyz);
			\draw[] (Boxz) -- (Boxyz);
			\draw[] (Boxxy) -- (Box);
			\draw[] (Boxxz) -- (Box);
			\draw[] (Boxyz) -- (Box);

			\pause
			% Create a new rotated system in the center
			\tdplotsetrotatedcoords{\alphaEuler}{\betaEuler}{\gammaEuler}
			% Draw a box in the  new coordinates system
			\draw[tdplot_rotated_coords,gray] (\boxX,0,0) -- (\boxX,\boxY,0) -- (0,\boxY,0) -- (0,\boxY,\boxZ) -- (0,0,\boxZ) -- (\boxX,0,\boxZ) -- (\boxX,0,0);
			\draw[tdplot_rotated_coords,gray] (\boxX,0,\boxZ) -- (\boxX,\boxY,\boxZ) -- (0,\boxY,\boxZ);
			\draw[tdplot_rotated_coords,gray] (\boxX,\boxY,\boxZ) -- (\boxX,\boxY,0);
			% Draw new coordinates system
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,gray] (0,0,0) -- (\boxX,0,0);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,gray] (\boxX,0,0) -- (1.3*\lenX,0,0) node[anchor=north east]{$X$};
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,gray] (0,0,0) -- (0,\boxY,0);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,gray] (0,\boxY,0) -- (0,1.3*\lenY,0) node[anchor=south west]{$Y$};
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,gray] (0,0,0) -- (0,0,\boxZ);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,gray] (0,0,\boxZ) -- (0,0,0.8*\lenZ) node[anchor=north west]{$Z$};
			% Draw rotation
			% \tdplotdrawarc[coordinate system, draw styles]{center}{r}{angle start}{angle end}{label options}{label}
			\tdplotdrawarc[thick,dotted,<->]{(0,0,0.5*\lenZ)}{0.5*\r}{-270}{0}{anchor=west}{}
			\end{tikzpicture}
		\end{figure}
	\end{frame}

	\begin{frame}[fragile]{Rotate a box aroud any axis}
		\begin{figure}[h]
			\centering
			\def\r{3.5}
			\pgfmathsetmacro{\alphaNorth}{40}
			\pgfmathsetmacro{\betaNorth}{0}
			\pgfmathsetmacro{\gammaNorth}{0}

			\pgfmathsetmacro{\alphaNewAxis}{-35}
			\pgfmathsetmacro{\betaNewAxis}{0}
			\pgfmathsetmacro{\gammaNewAxis}{0}

			\pgfmathsetmacro{\alphaNextBox}{\alphaNewAxis}
			\pgfmathsetmacro{\betaNextBox}{-40}
			\pgfmathsetmacro{\gammaNextBox}{0}
			%%% \pgfmathsetmacro{\inclination}{70}

			\tdplotsetmaincoords{70}{160}
			\begin{tikzpicture}[tdplot_main_coords]
			% Drawing XYZ coordinates system
			\def \lenX {1.0*\r}
			\def \lenY {1.3*\r}
			\def \lenZ {1.0*\r}
			\def \boxX{.7*\r}
			\def \boxY{.9*\r}
			\def \boxZ{.2*\r}
			% Calculate box corner length
			\pgfmathsetmacro{\boxCornerLen}{sqrt{((\boxX)^2 + (\boxY)^2 + (\boxZ)^2)}}
			% Draw coordinate system
			\draw[dashed] (0,0,0) -- (\boxX,0,0);
			\draw[->,thick] (\boxX,0,0) -- (\lenX,0,0) node[left] {$X$};
			\draw[dashed] (0,0,0) -- (0,\boxY,0);
			\draw[->,thick] (0,\boxY,0) -- (0,\lenY,0) node[anchor=north west] {$Y$};
			\draw[dashed] (0,0,0) -- (0,0,0.6*\lenZ);
			\draw[->,thick] (0,0,0.6*\lenZ) -- (0,0,\lenZ) node[anchor=south] {$Z$};
			% Draw gravity vector
			\draw[-stealth,thin] (-0.8*\r,1.1*\r,0) -- (-0.8*\r,1.1*\r,-.3*\r) node[anchor=south west] {$\mathbf{g}$};

			% Drawing horizontal box:
			% Get corner polar coordinate
			\tdplotgetpolarcoords{\boxX}{\boxY}{\boxZ}
			\tdplotsetcoord{Box}{\boxCornerLen}{\tdplotrestheta}{\tdplotresphi}
			% Draw a box
			% \draw[] (O) -- (Boxx);
			% \draw[] (O) -- (Boxy);
			% \draw[] (O) -- (Boxz);
			\draw[] (Boxx) -- (Boxxy);
			\draw[] (Boxy) -- (Boxxy);
			\draw[] (Boxx) -- (Boxxz);
			\draw[] (Boxz) -- (Boxxz);
			\draw[] (Boxy) -- (Boxyz);
			\draw[] (Boxz) -- (Boxyz);
			\draw[] (Boxxy) -- (Box);
			\draw[] (Boxxz) -- (Box);
			\draw[] (Boxyz) -- (Box);
			\pause
			% Create a new rotated system in the center for North direction
			\tdplotsetrotatedcoords{\alphaNorth}{\betaNorth}{\gammaNorth}
			% Draw new coordinates system
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (1.4*\boxX,0,0);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (1.4*\boxX,0,0) -- (1.3*\lenX,0,0) node[anchor=north east]{$E$};
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (0,0.3*\boxY,0);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (0,0.3*\boxY,0) -- (0,0.8*\lenY,0) node[anchor=south west]{$\mathbf{N}$};
			% Hidden line
			\draw[dashed,tdplot_rotated_coords,red] (0,0,0) -- (0,0,1.1*\boxZ);
			% Visible line
			\draw[thick,tdplot_rotated_coords,->,red] (0,0,1.1*\boxZ) -- (0,0,0.8*\lenZ) node[anchor=north east]{$Z$};

			\pause
			% Create a new rotated system in the center
			\tdplotsetrotatedcoords{\alphaNewAxis}{\betaNewAxis}{\gammaNewAxis}
			% Draw new coordinates system
			%\draw[dashed,tdplot_rotated_coords,orange] (0,0,0) --  (1.3*\lenX,0,0) node[anchor=north east]{$x$};
			\draw[dashed,tdplot_rotated_coords,blue] (0,0,0) -- (0,1.6*\lenY,0) node[anchor=north east]{Rotation axis};
			%\draw[dashed,tdplot_rotated_coords,orange] (0,0,0) -- (0,0,1.3*\lenZ) node[anchor=north east]{$z$};
			%
			% Calculate Box coordinates in rotated system {\boxX}{\boxY}{\boxZ}
			\tdplottransformmainrot{\boxX}{0}{0}
			\pgfmathsetmacro{\BoxNewXoox}{\tdplotresx}
			\pgfmathsetmacro{\BoxNewXooy}{\tdplotresy}
			\pgfmathsetmacro{\BoxNewXooz}{\tdplotresz}
			%\coordinate (BoxNewX00) at (\tdplotresx,\tdplotresy,\tdplotresz);
			\tdplottransformmainrot{0}{\boxY}{0}
			\pgfmathsetmacro{\BoxNewoYox}{\tdplotresx}
			\pgfmathsetmacro{\BoxNewoYoy}{\tdplotresy}
			\pgfmathsetmacro{\BoxNewoYoz}{\tdplotresz}
			%\coordinate (BoxNew0Y0) at (\tdplotresx,\tdplotresy,\tdplotresz);
			\tdplottransformmainrot{0}{0}{\boxZ}
			\pgfmathsetmacro{\BoxNewooZx}{\tdplotresx}
			\pgfmathsetmacro{\BoxNewooZy}{\tdplotresy}
			\pgfmathsetmacro{\BoxNewooZz}{\tdplotresz}
			%\coordinate (BoxNew00Z) at (\tdplotresx,\tdplotresy,\tdplotresz);

			\tdplottransformmainrot{\boxX}{\boxY}{0}
			\pgfmathsetmacro{\BoxNewXYox}{\tdplotresx}
			\pgfmathsetmacro{\BoxNewXYoy}{\tdplotresy}
			\pgfmathsetmacro{\BoxNewXYoz}{\tdplotresz}
			%\coordinate (BoxNewXY0) at (\tdplotresx,\tdplotresy,\tdplotresz);

			\tdplottransformmainrot{\boxX}{0}{\boxZ}
			\pgfmathsetmacro{\BoxNewXoZx}{\tdplotresx}
			\pgfmathsetmacro{\BoxNewXoZy}{\tdplotresy}
			\pgfmathsetmacro{\BoxNewXoZz}{\tdplotresz}
			%\coordinate (BoxNewX0Z) at (\tdplotresx,\tdplotresy,\tdplotresz);
			\tdplottransformmainrot{0}{\boxY}{\boxZ}
			\pgfmathsetmacro{\BoxNewoYZx}{\tdplotresx}
			\pgfmathsetmacro{\BoxNewoYZy}{\tdplotresy}
			\pgfmathsetmacro{\BoxNewoYZz}{\tdplotresz}
			%\coordinate (BoxNew0YZ) at (\tdplotresx,\tdplotresy,\tdplotresz);
			\tdplottransformmainrot{\boxX}{\boxY}{\boxZ}
			\pgfmathsetmacro{\BoxNewXYZx}{\tdplotresx}
			\pgfmathsetmacro{\BoxNewXYZy}{\tdplotresy}
			\pgfmathsetmacro{\BoxNewXYZz}{\tdplotresz}
			%\coordinate (BoxNewXYZ) at (\tdplotresx,\tdplotresy,\tdplotresz);

			\coordinate (0) at (0,0,0);

			%\draw[tdplot_rotated_coords, orange] (0) -- (\BoxNewXoox,\BoxNewXooy,\BoxNewXooz) -- (\BoxNewXYox,\BoxNewXYoy,\BoxNewXYoz) -- (\BoxNewoYox,\BoxNewoYoy,\BoxNewoYoz) -- (0);
			%
			%\draw[tdplot_rotated_coords, orange] (\BoxNewooZx,\BoxNewooZy,\BoxNewooZz) -- (\BoxNewXoZx,\BoxNewXoZy,\BoxNewXoZz) -- (\BoxNewXYZx,\BoxNewXYZy,\BoxNewXYZz) -- (\BoxNewoYZx,\BoxNewoYZy,\BoxNewoYZz) -- (\BoxNewooZx,\BoxNewooZy,\BoxNewooZz);
			%
			%\draw[tdplot_rotated_coords, orange] (\BoxNewooZx,\BoxNewooZy,\BoxNewooZz) -- (0);
			%\draw[tdplot_rotated_coords, orange] (\BoxNewXoZx,\BoxNewXoZy,\BoxNewXoZz) -- (\BoxNewXoox,\BoxNewXooy,\BoxNewXooz);
			%\draw[tdplot_rotated_coords, orange] (\BoxNewXYZx,\BoxNewXYZy,\BoxNewXYZz) -- (\BoxNewXYox,\BoxNewXYoy,\BoxNewXYoz);
			%\draw[tdplot_rotated_coords, orange] (\BoxNewoYZx,\BoxNewoYZy,\BoxNewoYZz) -- (\BoxNewoYox,\BoxNewoYoy,\BoxNewoYoz);

			%\draw[tdplot_rotated_coords,green] (0) -- (BoxNewX00) -- (BoxNewXY0) -- (BoxNew0Y0) -- (0);
			%\draw[tdplot_rotated_coords, green] (BoxNew00Z) -- (BoxNewX0Z) -- (BoxNewXYZ) -- (BoxNew0YZ) -- (BoxNew00Z);

			%%%\foreach \stepNumber in {1,2,3}
			\foreach \slideNumber in {4,5,6}
			%%%\foreach \betaNextBox in {-15,-30,-45}
			{
				\pause
				%%%\pgfmathsetmacro{\betaNextBox}{(-15)*\stepNumber}
				\pgfmathsetmacro{\betaNextBox}{(-15)*(\slideNumber-3)}
				%%%\pgfmathsetmacro{\slideNumber}{3+\stepNumber}
				\only<\slideNumber>{
					% Rotating box around one new axis:
					% Create a new rotated system in the center.
					\tdplotsetrotatedcoords{\alphaNextBox}{\betaNextBox}{\gammaNextBox}

					%\draw[dashed,tdplot_rotated_coords,gray] (0,0,0) --  (1.3*\lenX,0,0) node[anchor=north east]{$x$};
					%\draw[dashed,tdplot_rotated_coords,gray] (0,0,0) -- (0,1.3*\lenY,0) node[anchor=south east]{$y$};
					%\draw[dashed,tdplot_rotated_coords,gray] (0,0,0) -- (0,0,1.3*\lenZ) node[anchor=north east]{$z$};

					% Draw a box in the  new coordinates system
					\draw[dashed,tdplot_rotated_coords, gray] (0) -- (\BoxNewXoox,\BoxNewXooy,\BoxNewXooz);
					\draw[tdplot_rotated_coords, gray] (\BoxNewXoox,\BoxNewXooy,\BoxNewXooz) -- (\BoxNewXYox,\BoxNewXYoy,\BoxNewXYoz) -- (\BoxNewoYox,\BoxNewoYoy,\BoxNewoYoz);
					\draw[dashed,tdplot_rotated_coords, gray] (\BoxNewXYox,\BoxNewXYoy,\BoxNewXYoz) -- (\BoxNewoYox,\BoxNewoYoy,\BoxNewoYoz) -- (0);

					\draw[tdplot_rotated_coords, gray] (\BoxNewooZx,\BoxNewooZy,\BoxNewooZz) -- (\BoxNewXoZx,\BoxNewXoZy,\BoxNewXoZz) -- (\BoxNewXYZx,\BoxNewXYZy,\BoxNewXYZz) -- (\BoxNewoYZx,\BoxNewoYZy,\BoxNewoYZz) -- (\BoxNewooZx,\BoxNewooZy,\BoxNewooZz);

					\draw[tdplot_rotated_coords, gray] (\BoxNewooZx,\BoxNewooZy,\BoxNewooZz) -- (0);
					\draw[tdplot_rotated_coords, gray] (\BoxNewXoZx,\BoxNewXoZy,\BoxNewXoZz) -- (\BoxNewXoox,\BoxNewXooy,\BoxNewXooz);
					\draw[tdplot_rotated_coords, gray] (\BoxNewXYZx,\BoxNewXYZy,\BoxNewXYZz) -- (\BoxNewXYox,\BoxNewXYoy,\BoxNewXYoz);
					\draw[tdplot_rotated_coords, gray] (\BoxNewoYZx,\BoxNewoYZy,\BoxNewoYZz) -- (\BoxNewoYox,\BoxNewoYoy,\BoxNewoYoz);

					\tdplotsetthetaplanecoords{0}
					\tdplotdrawarc[tdplot_rotated_coords,gray,thick,dotted,<->]{(0,0,0)}{\boxX}{90}{90+\betaNextBox}{anchor=west}{}
				}
			} % end \foreach

			\end{tikzpicture}
		\end{figure}
	\end{frame}

	\section{Area aproximation: Rectangles + Triangles }
	\begin{frame}[fragile]{Area $\approxeq$ Rectangles + Triangles}
		\begin{figure}[h]
			\centering
			\pgfmathsetmacro{\circleRadius}{4}
			\resizebox{0.5\textwidth}{!}{
				\begin{tikzpicture}
				% Draw X axis
				\draw[thick,->] (0,0) -- (\circleRadius+0.3,0) node[anchor=north west]{$t$};
				% Draw X axis labels
				\foreach \x in {0,...,\circleRadius}
				{
					\draw (\x,0) -- (\x,-3pt) node[anchor=north] {$t_\x$};
				}
				% Draw Y axis
				\draw[thick,->] (0,0) -- (0,\circleRadius+0.3) node[anchor=south east]{$\omega$};
				% Draw a quarter of circle
				\draw[red,thick] (0,0\circleRadius) arc[start angle=90, end angle=0, radius=\circleRadius];
				% Draw trapeziums
				\foreach \thisX in {1,...,\circleRadius}
				{
					% Calculate rectangle points
					\pgfmathsetmacro{\thisAngle}{acos((\thisX)/\circleRadius)}
					\pgfmathsetmacro{\thisY}{\circleRadius*sin(\thisAngle)}
					% Calculate triangle points
					\pgfmathsetmacro{\previousAngle}{acos((\thisX-1)/\circleRadius)}
					\pgfmathsetmacro{\previousY}{\circleRadius*sin(\previousAngle)}
					% Draw triangle
					\draw[dashed, fill=blue!30] (\thisX-1,\previousY) -- (\thisX-1,\thisY) -- (\thisX,\thisY) -- cycle;
					% Draw rectangle
					\draw[fill=gray!30] (\thisX-1,0) rectangle (\thisX,\thisY);
					% draw y axis labels
					\draw (0,\thisY) -- (-3pt,\thisY) node[anchor=east] {$\omega_\thisX$};
				}
				\end{tikzpicture}
			}
		\end{figure}

		\begin{equation}\label{eq:omega2phiTrapezIni}
		\boldsymbol{\theta}_k \approx \boldsymbol{\theta}_{k-1} + (t_k - t_{k-1}) \boldsymbol{\omega}_{k-1} + \frac{1}{2} (t_k - t_{k-1}) (\boldsymbol{\omega}_{k} - \boldsymbol{\omega}_{k-1}),\quad k \ge 1
		\end{equation}
	\end{frame}

	\section{Magnetic Roll, Pitch and Yaw}
	\begin{frame}[fragile]
		\begin{figure}[H]
			\centering
			% Select a perspective
			%\tdplotsetmaincoords{65}{105}
			%\tdplotsetmaincoords{65}{235}
			\tdplotsetmaincoords{65}{205}
			\begin{tikzpicture}[scale=1,tdplot_main_coords,>=latex,line join=bevel]
			% Parameters ---------------------
			% Coordinates parameters
			\pgfmathsetmacro{\sizeCoordX}{4.2}
			\pgfmathsetmacro{\sizeCoordY}{4.2}
			\pgfmathsetmacro{\sizeCoordZ}{4.2}
			\coordinate (O) at (0,0,0);

			% Figures ---------------------
			% Coordinates
			\draw[->] (O) -- (\sizeCoordX,0,0) node[anchor=east]{$X$};
			\draw[->] (O) -- (0,\sizeCoordY,0) node[anchor=north]{$Y$};
			\draw[->] (O) -- (0,0,\sizeCoordZ) node[anchor=south]{$Z$};
			% \draw[dashed] (O) -- (-0.7*\sizeCoordX,0,0);
			% \draw[dashed] (O) -- (0,-0.7*\sizeCoordY,0);
			% \draw[dashed] (O) -- (0,0,-\sizeCoordZ);
			\pause
			% Create a new rotated system in the center
			%\tdplotsetrotatedcoords{45}{-60}{-30}
			\tdplotsetrotatedcoords{65}{-40}{-30}
			\draw[thick,tdplot_rotated_coords,->, color=darkgray] (0,0,0) -- (\sizeCoordX,0,0) node[anchor=north east]{$\mathbf{e_E}$};
			\draw[very thick,tdplot_rotated_coords,->, color=darkgray] (0,0,0) -- (0,\sizeCoordY,0) node[anchor=north]{$\mathbf{e_N}$};
			\draw[thick,tdplot_rotated_coords,->, color=darkgray] (0,0,0) -- (0,0,\sizeCoordZ) node[anchor=south east]{$\mathbf{e_Z}$};

			\pause
			% Draw a box around East direction
			\tdplottransformrotmain{\sizeCoordX}{0}{0}
			% Draw box
			\draw[dotted] (\tdplotresx,\tdplotresy,\tdplotresz) -- (\tdplotresx,\tdplotresy,0);
			\draw[dotted] (\tdplotresx,\tdplotresy,\tdplotresz) -- (\tdplotresx,0,\tdplotresz);
			\draw[dotted] (\tdplotresx,\tdplotresy,\tdplotresz) -- (0,\tdplotresy,\tdplotresz);
			\draw[dotted] (\tdplotresx,\tdplotresy,0) -- (\tdplotresx,0,0);
			\draw[dotted] (\tdplotresx,\tdplotresy,0) -- (0,\tdplotresy,0);
			\draw[dotted] (\tdplotresx,0,\tdplotresz) -- (0,0,\tdplotresz);
			\draw[dotted] (\tdplotresx,0,\tdplotresz) -- (\tdplotresx,0,0);
			\draw[dotted] (0,\tdplotresy,\tdplotresz) -- (0,0,\tdplotresz);
			\draw[dotted] (0,\tdplotresy,\tdplotresz) -- (0,\tdplotresy,0);
			\draw[dotted] (0,0,0) -- (\tdplotresx,0,0);

			% Transforms a coordinate from the rotated coordinate frame to the main coordinate frame. Results at (\tdplotresx,\tdplotresy,\tdplotresz)
			\tdplottransformrotmain{0}{\sizeCoordY}{0}
			% Draw North box
			\draw[dotted] (\tdplotresx,\tdplotresy,\tdplotresz) -- (\tdplotresx,\tdplotresy,0);
			\draw[dotted] (\tdplotresx,\tdplotresy,\tdplotresz) -- (\tdplotresx,0,\tdplotresz);
			\draw[dotted] (\tdplotresx,\tdplotresy,\tdplotresz) -- (0,\tdplotresy,\tdplotresz);
			\draw[dotted] (\tdplotresx,\tdplotresy,0) -- (\tdplotresx,0,0);
			\draw[dotted] (\tdplotresx,\tdplotresy,0) -- (0,\tdplotresy,0);
			\draw[dotted] (\tdplotresx,0,\tdplotresz) -- (0,0,\tdplotresz);
			\draw[dotted] (\tdplotresx,0,\tdplotresz) -- (\tdplotresx,0,0) node[anchor= north west]{$x_N$};
			\draw[dotted] (0,\tdplotresy,\tdplotresz) -- (0,0,\tdplotresz) node[anchor= south west]{$z_N$};
			\draw[dotted] (0,\tdplotresy,\tdplotresz) -- (0,\tdplotresy,0) node[anchor= south east]{$y_N$};
			\draw[dotted] (0,0,0) -- (\tdplotresx,0,0);

			% Draw arcs ---------------------------------
			%
			\pause
			\draw[dashed] (0,0,0) -- (0,\tdplotresy,\tdplotresz);
			% Calculate (0,y,z) polar coordinates
			\tdplotgetpolarcoords{0.001}{\tdplotresy}{\tdplotresz}
			\pgfmathsetmacro{\radius}{sqrt{((\tdplotresy)^2 + (\tdplotresz)^2)}}
			%syntax: \tdplotdrawarc[coordinate frame, draw options]{center point}{r}{angle start}{angle end}{label options}{label}
			\tdplotsetthetaplanecoords{90}
			\tdplotdrawarc[thick,tdplot_rotated_coords,thick,-stealth,blue]{(0,0,0)}{\radius}{0}{\tdplotrestheta}{anchor=north west}{$\theta_{x}$}
			%
			\pause
			\draw[dashed] (0,0,0) -- (\tdplotresx,0,\tdplotresz);
			% Calculate (x,0,z) polar coordinates
			\tdplotgetpolarcoords{\tdplotresx}{0}{\tdplotresz}
			\pgfmathsetmacro{\radius}{sqrt{((\tdplotresx)^2 + (\tdplotresz)^2)}}
			%syntax: \tdplotdrawarc[coordinate frame, draw options]{center point}{r}{angle start}{angle end}{label options}{label}
			\tdplotsetthetaplanecoords{180}
			\tdplotdrawarc[thick,tdplot_rotated_coords,thick,-stealth,blue]{(0,0,0)}{\radius}{90}{\tdplotrestheta}{anchor=north west}{$\theta_{y}$}
			%
			\pause
			\draw[dashed] (0,0,0) -- (\tdplotresx,\tdplotresy,0);
			% Calculate (x,y,0) polar coordinates
			\tdplotgetpolarcoords{\tdplotresx}{\tdplotresy}{0}
			\pgfmathsetmacro{\radius}{sqrt{((\tdplotresx)^2 + (\tdplotresy)^2)}}
			%%%% %syntax: \tdplotdrawarc[coordinate frame, draw options]{center point}{r}{angle start}{angle end}{label options}{label}
			\tdplotsetthetaplanecoords{0}
			\tdplotdrawarc[thick,thick,-stealth,blue]{(0,0,0)}{\radius}{90}{\tdplotresphi}{anchor=north west}{$\theta_{z}$}
			\end{tikzpicture}
		\end{figure}
		\pause
		\onslide<7->{
			%\begin{equation}\label{eq:compass_b_rpy}
			\begin{align}
			&\textit{Roll}({\mathbf{b}}): &\quad \theta_{x} =& \arctan{({Y_N}/{Z_N})} - 90 ^{\circ} \\
			&\textit{Pitch}({\mathbf{b}}): &\quad \theta_{y} =& \arctan{({Z_N}/{-X_N})}\\
			&\textit{Yaw}({\mathbf{b}}): &\quad \theta_{z} =& \arctan{({-X_N}/{Y_N})}\label{eq:yawHoriz}
			\end{align}
			%\end{equation}
		}
	\end{frame}

	\begin{frame}[fragile]{}
		\begin{figure}[H]
			%\centering
			%\resizebox{0.5\textwidth}{!}{}
			\begin{tikzpicture}
			\def \accX {3}
			\def \accY {2}
			\def \sigmaAccX {1}
			\def \sigmaAccY {1}
			\def \Xaxis {\accX+\sigmaAccX+0.7}
			\def \Yaxis {\accY+\sigmaAccY+0.7}
			%
			% Define angles
			% It is very important to get redundant parenthesis
			\pgfmathsetmacro{\bottomAngle}{atan(((\accY-\sigmaAccY)) / ((\accX+\sigmaAccX)))}
			\pgfmathsetmacro{\mediumAngle}{atan(((\accY)) / ((\accX)))}
			\pgfmathsetmacro{\upperAngle}{atan(((\accY+\sigmaAccY)) / ((\accX-\sigmaAccX)))}
			%
			% Draw coordinate system
			\draw[thick,->](0,0) -- (\Xaxis,0) node[right]{$X$};
			\draw[thick,->](0,0) -- (0,\Yaxis) node[above]{$Y$};
			%
			% Draw arrow medium position
			\draw[thick,-stealth](0,0) -- (\accX,\accY) node[right]{$\theta$};
			% Draw medium point
			\draw[dashed] (\accX,\accY) -- (\accX,0) node[below] {$x_k$};
			\draw[dashed] (\accX,\accY) -- (0,\accY) node[left] {$y_k$};
			% Draw angle
			\def \radiusMediumAngle {1.5}
			\draw[thick,black] ([shift=(0:\radiusMediumAngle)]0,0) arc (0:\mediumAngle:\radiusMediumAngle)node[below right]{$\theta$};
			\pause
			% Draw horizontal SD
			\draw[dotted] (\accX+\sigmaAccX,\accY-\sigmaAccY) -- (\accX+\sigmaAccX,0) node[rotate=90,left]{$(x_k+\sigma_x)$};
			\node[rotate=90,left] at (\accX-\sigmaAccX,0) {$(x_k-\sigma_x)$};
			\pause
			% Draw vertical SD
			\node[left] at (0,\accY-\sigmaAccY) {$(y_k-\sigma_y)$};
			\draw[dotted] (\accX-\sigmaAccX,\accY+\sigmaAccY) -- (0,\accY+\sigmaAccY) node[left]{$(y_k+\sigma_y)$};
			\pause
			% Draw arrow bottom position
			\draw[-stealth,blue](0,0) -- (\accX+\sigmaAccX, \accY-\sigmaAccY) node[right]{$(\theta-\sigma_{\theta -})$};
			% Angle. Syntax: (startingPointX,startingPointY) arc (startAngle:stopAngle:radius)
			% ([shift=(t:r)] x, y) is the proper starting point, where (x,y) is the center and (t:r) is the polar coordinate of starting point.
			\def \radiusBottomAngle {2.5}
			\draw[thick,blue] ([shift=(\bottomAngle:\radiusBottomAngle)]0,0) arc (\bottomAngle:\mediumAngle:\radiusBottomAngle)node[below right]{$\sigma_{\theta -}$};
			\pause
			% Draw arrow upper position
			\draw[-stealth,red](0,0) -- (\accX-\sigmaAccX, \accY+\sigmaAccY) node[right]{$(\theta+\sigma_{\theta +})$};
			% Angle
			\def \radiusUpperAngle {2.6}
			\draw[thick,red] ([shift=(\mediumAngle:\radiusUpperAngle)]0,0) arc (\mediumAngle:\upperAngle:\radiusUpperAngle)node[right]{$\sigma_{\theta +}$};
			\end{tikzpicture}
		\end{figure}
		\onslide<6->{
			\begin{equation}
			(\theta_z - \sigma_{\theta -}) = \arctan \frac{y_k-\sigma_y}{x_k+\sigma_x}
			,\quad
			(\theta_z + \sigma_{\theta +}) = \arctan \frac{y_k+\sigma_y}{x_k-\sigma_x}
			\end{equation}}
		\onslide<7->{
			\begin{equation}\label{eq:sigmaPlusMinus}
			\sigma_k =(\sigma_{\theta +} + \sigma_{\theta -}) = \arctan \frac{y_k+\sigma_y}{x_k-\sigma_x} - \arctan \frac{y_k-\sigma_y}{x_k+\sigma_x}
			\end{equation}
		}
	\end{frame}

\end{document}


\subsection{Introduction}

Trade-off between parameter accuracy and prediction accuracy.


\section{Figures that might be useful}
\begin{figure}[ht]
    \centering
    \begin{tikzpicture}[>=latex]
        % the rectangle with vertical rules (Queue 1)
        \draw (0,0) -- ++(2cm,0) -- ++(0,-1.5cm) -- ++(-2cm,0);
        \foreach \i in {1,...,4}
        \draw (2cm-\i*10pt,0) -- +(0,-1.5cm);

        % the circle (Queue 1)
        \draw (2.75,-0.75cm) circle [radius=0.75cm];

        % the rectangle with vertical rules (Queue 2)
        \draw (5,1.25) -- ++(2cm,0) -- ++(0,-1.5cm) -- ++(-2cm,0);
        \foreach \i in {1,...,4}
        \draw (7cm-\i*10pt,1.25) -- +(0,-1.5cm);

        % the circle (Queue 2)
        \draw (7.75,0.5) circle [radius=0.75cm];

        % the arrows and labels (Queue 1+2)
        \draw[-] (3.5,-0.75) -- +(20pt,0);
        \draw[<-] (0,-0.75) -- +(-50pt,0) node[left] {\( \lambda_2 \)};
        \draw[->] (8.5,0.525) -- +(20pt,0);
        \node[align=center] at (1cm,-2cm) {Buffer \\ Area};
        \node[align=center] at (2.75cm,-2cm) {Dummy \\ Service};
        \node[align=center] at (6cm,-0.75cm) {Waiting \\ Area};
        \node[align=center] at (7.8cm,-0.75cm) {Treatment \\ };

        \draw (4.2, 1.8) -- +(-169.5pt,0) node[left] {\( \lambda_1 \)};
        \draw (4.2, 1.8) -- (4.2, -0.75);
        \draw[->] (4.2, 0.525) -- (5, 0.525);

    \end{tikzpicture}
\end{figure}

\begin{figure}[ht]
    \input{Miscellaneous/Useful_tikz/Example-with-python/main.tex}
\end{figure}

\newpage
\begin{figure}
    \centering
    \begin{tikzpicture}[-, node distance = 1cm, auto, every node/.style={scale=0.5}]

        % Variables
        \tikzmath{
            let \altdist = 1.5cm;
            let \minsz = 1.5cm;
        }

        % First Line
        \node[state, minimum size=1.5cm] (zero) {(0,0)};
        \node[state, minimum size=1.5cm,  right=of zero] (one) {(0,1)};
        \node[draw=none, minimum size=1.5cm, right=of one] (two) {\dots};
        \node[state, minimum size=1.5cm, right=of two] (three) {(0,T)};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of three]
        (four) {(0,T+1)};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, right=of four]
        (five) {\dots};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of five]
        (six) {(0,C)};
        \node[draw=none, minimum size=\minsz, right=of six] (seven) {\dots};

        % Second Line
        \node[state, minimum size=\minsz, below=of three] (three_one) {(1,T)};
        \node[state, minimum size=\minsz, below=of four] (four_one) {(1,T+1)};
        \node[draw=none, minimum size=\minsz, below=of five] (five_one) {\dots};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of five_one]
        (six_one) {(1,C)};
        \node[draw=none, minimum size=\minsz, right=of six_one] (seven_one) {\dots};

        % Third Line
        \node[state, minimum size=\minsz, below=of three_one] (three_two) {(2,T)};
        \node[state, minimum size=\minsz, below=of four_one] (four_two) {(2,T+1)};
        \node[draw=none, minimum size=\minsz, below=of five_one] (five_two) {\dots};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of five_two]
        (six_two) {(2,C)};
        \node[draw=none, minimum size=\minsz, right=of six_two] (seven_two) {\dots};

        % Fourth line
        \node[draw=none, minimum size=\minsz, below=of three_two] (three_three) {\vdots};
        \node[draw=none, minimum size=\minsz, below=of four_two] (four_three) {\vdots};
        \node[draw=none, minimum size=\minsz, below=of five_two] (five_three) {};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, right=of five_three]
        (six_three) {\vdots};

        \draw[every loop]
            % First Horizontal Edges
            (zero) edge[bend left] node {\( \Lambda \)} (one)
            (one) edge[bend left] node [above] {\( \mu \)} (zero)
            (one) edge[bend left] node {\( \Lambda \)} (two)
            (two) edge[bend left] node [above] {\( 2 \mu \)} (one)
            (two) edge[bend left] node {\( \Lambda \)} (three)
            (three) edge[bend left] node [above] {\( T \mu \)} (two)
            (three) edge[bend left] node {\( \lambda_1 \)} (four)
            (four) edge[bend left] node [above] {\( (T+1) \mu \)} (three)
            (four) edge[bend left] node {\( \lambda_1 \)} (five)
            (five) edge[bend left] node [above] {\( (T+2) \mu \)} (four)
            (five) edge[bend left] node {\( \lambda_1 \)} (six)
            (six) edge[bend left] node [above] {\( C\mu \)} (five)
            (six) edge[bend left] node {\( \lambda_1 \)} (seven)
            (seven) edge[bend left] node [above] {\( C\mu \)} (six)

            % Second Horizontal Edges
            (three_one) edge[bend left] node {\( \lambda_1 \)} (four_one)
            (four_one) edge[bend left] node [above] {\( (T+1) \mu \)} (three_one)
            (four_one) edge[bend left] node {\( \lambda_1 \)} (five_one)
            (five_one) edge[bend left] node [above] {\( (T+2) \mu \)} (four_one)
            (five_one) edge[bend left] node {\( \lambda_1 \)} (six_one)
            (six_one) edge[bend left] node [above] {\( C\mu \)} (five_one)
            (six_one) edge[bend left] node {\( \lambda_1 \)} (seven_one)
            (seven_one) edge[bend left] node [above] {\( C\mu \)} (six_one)

            % Third Horizontal Edges
            (three_two) edge[bend left] node {\( \lambda_1 \)} (four_two)
            (four_two) edge[bend left] node [above] {\( (T+1) \mu \)} (three_two)
            (four_two) edge[bend left] node {\( \lambda_1 \)} (five_two)
            (five_two) edge[bend left] node [above] {\( (T+2) \mu \)} (four_two)
            (five_two) edge[bend left] node {\( \lambda_1 \)} (six_two)
            (six_two) edge[bend left] node [above] {\( C\mu \)} (five_two)
            (six_two) edge[bend left] node {\( \lambda_1 \)} (seven_two)
            (seven_two) edge[bend left] node [above] {\( C\mu \)} (six_two)

            % First Vertical Edges
            (three) edge[bend left] node {\( \lambda_2 \)} (three_one)
            (three_one) edge[bend left] node {\( T \mu \)} (three)
            (three_one) edge[bend left] node {\( \lambda_2 \)} (three_two)
            (three_two) edge[bend left] node {\( T\mu \)} (three_one)
            (three_two) edge[bend left] node {\( \lambda_2 \)} (three_three)
            (three_three) edge[bend left] node {\( T\mu \)} (three_two)

            % Second Vertical Edges
            (four) edge node {\( \lambda_2 \)} (four_one)
            (four_one) edge node {\( \lambda_2 \)} (four_two)
            (four_two) edge node {\( \lambda_2 \)} (four_three)

            %Third Vertical Edges
            (six) edge node {\( \lambda_2 \)} (six_one)
            (six_one) edge node {\( \lambda_2 \)} (six_two)
            (six_two) edge node {\( \lambda_2 \)} (six_three)
            ;
    \end{tikzpicture}
    \caption{Markov chains}
    \label{Markov_2}
\end{figure}

\newpage
\begin{figure}[ht]
    \centering
    \begin{tikzpicture}[-, node distance = 1cm, auto, every node/.style={scale=0.4}]

        % Variables
        \tikzmath{
            let \altdist = 1cm;
            let \minsz = 1.5cm;
        }

        % First Line
        \node[state, minimum size=1.5cm] (zero) {(0,0)};
        \node[state, minimum size=1.5cm,  right=of zero] (one) {(0,1)};
        \node[draw=none, minimum size=1.5cm, right=of one] (two) {\dots};
        \node[state, minimum size=1.5cm, right=of two] (three) {(0,T)};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of three]
        (four) {(0,T+1)};
        \node[draw=none, minimum size=\minsz, right=of four] (five) {\dots};
        \node[draw=none, minimum size=\minsz, right=of five] (six) {\vdots};
        \node[draw=none, minimum size=\minsz, right=of six] (seven) {\dots};
        \node[state, minimum size=\minsz, right=of seven] (eight) {(0,C)};
        \node[draw=none, minimum size=\minsz, right=of eight] (nine) {\dots};

        % Second Line
        \node[state, minimum size=\minsz, below=of three] (three_one) {(1,T)};
        \node[state, minimum size=\minsz, below=of four] (four_one) {(1,T+1)};
        \node[draw=none, minimum size=\minsz, below=of five] (five_one) {\dots};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of five_one]
        (six_one) {\( (u_i, v_i) \)};
        \node[draw=none, minimum size=\minsz, right=of six_one] (seven_one) {\dots};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of seven_one]
        (eight_one) {(1,C)};
        \node[draw=none, minimum size=\minsz, right=of eight_one] (nine_one) {\dots};

        % Third Line
        \node[state, minimum size=\minsz, below=of three_one] (three_two) {(2,T)};
        \node[state, minimum size=\minsz, below=of four_one] (four_two) {(2,T+1)};
        \node[draw=none, minimum size=\minsz, below=of five_one] (five_two) {\dots};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, right=of five_two]
        (six_two) {\vdots};
        \node[draw=none, minimum size=\minsz, right=of six_two] (seven_two) {\dots};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of seven_two]
        (eight_two) {(2,C)};
        \node[draw=none, minimum size=\minsz, right=of eight_two] (nine_two) {\dots};

        % Fourth line
        \node[draw=none, minimum size=\minsz, below=of three_two] (three_three) {\vdots};
        \node[draw=none, minimum size=\minsz, below=of four_two] (four_three) {\vdots};
        \node[draw=none, minimum size=\minsz, below=of five_two] (five_three) {};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, right=of five_three]
        (six_three) {};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of eight_two]
        (eight_three) {\vdots};

        \draw[every loop]
            % First Horizontal Edges
            (zero) edge[bend left] node {\( \Lambda \)} (one)
            (one) edge[bend left] node {\( \mu \)} (zero)
            (one) edge[bend left] node {\( \Lambda \)} (two)
            (two) edge[bend left] node {\( 2 \mu \)} (one)
            (two) edge[bend left] node {\( \Lambda \)} (three)
            (three) edge[bend left] node {\( T \mu \)} (two)
            (three) edge[bend left] node {\( \lambda_1 \)} (four)
            (four) edge[bend left] node {\( (T+1) \mu \)} (three)
            (four) edge[bend left] node {\( \lambda_1 \)} (five)
            (five) edge[bend left] node {\( (T+2) \mu \)} (four)
            % (five) edge[bend left] node {\( \lambda_1 \)} (six)
            % (six) edge[bend left] node [above] {\( C\mu \)} (five)
            % (six) edge[bend left] node {\( \lambda_1 \)} (seven)
            % (seven) edge[bend left] node [above] {\( C\mu \)} (six)
            (seven) edge[bend left] node {\( \lambda_1 \)} (eight)
            (eight) edge[bend left] node {\( C\mu \)} (seven)
            (eight) edge[bend left] node {\( \lambda_1 \)} (nine)
            (nine) edge[bend left] node {\( C\mu \)} (eight)

            % Second Horizontal Edges
            (three_one) edge[bend left] node {\(\lambda_1\)} (four_one)
            (four_one) edge[bend left] node {\( (T+1) \mu \)} (three_one)
            (four_one) edge[bend left] node {\( \lambda_1 \)} (five_one)
            (five_one) edge[bend left] node {\( (T+2) \mu \)} (four_one)
            (five_one) edge[bend left] node {\( \lambda_1 \)} (six_one)
            (six_one) edge[bend left] node {\( v_i\mu \)} (five_one)
            (six_one) edge[bend left] node {\( \lambda_1 \)} (seven_one)
            (seven_one) edge[bend left] node {\( (v_i+1)\mu \)} (six_one)
            (seven_one) edge[bend left] node {\( \lambda_1 \)} (eight_one)
            (eight_one) edge[bend left] node {\( C\mu \)} (seven_one)
            (eight_one) edge[bend left] node {\( \lambda_1 \)} (nine_one)
            (nine_one) edge[bend left] node {\( C\mu \)} (eight_one)

            % Third Horizontal Edges
            (three_two) edge[bend left] node {\( \lambda_1 \)} (four_two)
            (four_two) edge[bend left] node {\( (T+1) \mu \)} (three_two)
            (four_two) edge[bend left] node {\( \lambda_1 \)} (five_two)
            (five_two) edge[bend left] node {\( (T+2) \mu \)} (four_two)
            % (five_two) edge[bend left] node {\( \lambda_1 \)} (six_two)
            % (six_two) edge[bend left] node [above] {\( C\mu \)} (five_two)
            % (six_two) edge[bend left] node {\( \lambda_1 \)} (seven_two)
            % (seven_two) edge[bend left] node [above] {\( C\mu \)} (six_two)
            (seven_two) edge[bend left] node {\( \lambda_1 \)} (eight_two)
            (eight_two) edge[bend left] node {\( C\mu \)} (seven_two)
            (eight_two) edge[bend left] node {\( \lambda_1 \)} (nine_two)
            (nine_two) edge[bend left] node {\( C\mu \)} (eight_two)

            % First Vertical Edges
            (three) edge[bend left] node {\( \lambda_2 \)} (three_one)
            (three_one) edge[bend left] node {\( T \mu \)} (three)
            (three_one) edge[bend left] node {\( \lambda_2 \)} (three_two)
            (three_two) edge[bend left] node {\( T\mu \)} (three_one)
            (three_two) edge[bend left] node {\( \lambda_2 \)} (three_three)
            (three_three) edge[bend left] node {\( T\mu \)} (three_two)

            % Second Vertical Edges
            (four) edge node {\( \lambda_2 \)} (four_one)
            (four_one) edge node {\( \lambda_2 \)} (four_two)
            (four_two) edge node {\( \lambda_2 \)} (four_three)

            % Third Vertical Edges
            (six) edge node {\( \lambda_2 \)} (six_one)
            (six_one) edge node {\( \lambda_2 \)} (six_two)
            % (six_two) edge node {\( \lambda_2 \)} (six_three)

            % Fourth Vertical Edges
            (eight) edge node {\( \lambda_2 \)} (eight_one)
            (eight_one) edge node {\( \lambda_2 \)} (eight_two)
            (eight_two) edge node {\( \lambda_2 \)} (eight_three)
            ;
    \end{tikzpicture}
    \caption{Markov chains}
    \label{Markov_3}
\end{figure}

\newpage
\begin{figure}[ht]
    \centering
    \begin{tikzpicture}[-, node distance = 0.9cm, auto, every node/.style={scale=0.5}]

        % Variables
        \tikzmath{
            let \initdist = 0.5cm;
            let \altdist = 1.2cm;
            let \minsz = 1.6cm;
            let \leftOne = -0.8;
            let \rightOne = 2.2;
            let \upOne = 0.8;
            let \downOne = -2.2;
            let \leftTwo = 2.25;
            let \rightTwo = 14.2;
            let \upTwo = -2.35;
            let \downTwo = -8.8;
        }

        % % Rectangle for S1
        % \draw[ultra thin, dashed] (\leftOne, \downOne) -- (\leftOne, \upOne);
        % \draw[ultra thin, dashed] (\leftOne, \upOne) -- (\rightOne, \upOne);
        % \draw[ultra thin, dashed] (\rightOne, \upOne) -- node {\Huge{\( \quad S_1 \)}}(\rightOne, \downOne);
        % \draw[ultra thin, dashed] (\rightOne, \downOne) -- (\leftOne, \downOne);

        % % Rectangle for S2
        % \draw[ultra thin, dashed] (\leftTwo, \downTwo) -- node {\Huge{\( S_2 \quad \)}}(\leftTwo, \upTwo);
        % \draw[ultra thin, dashed] (\leftTwo, \upTwo) -- (\rightTwo, \upTwo);
        % \draw[ultra thin, dashed] (\rightTwo, \upTwo) -- (\rightTwo, \downTwo);
        % \draw[ultra thin, dashed] (\rightTwo, \downTwo) -- (\leftTwo, \downTwo);

        % First Line
        \node[state, minimum size=1.5cm] (zero) {(0,0)};
        \node[state, node distance = \initdist, minimum size=\minsz, below right=of zero]
        (one) {(0,1)};
        \node[draw=none, node distance = \initdist, minimum size=\minsz, below right=of one]
        (two) {\textbf{\( \ddots \)}};
        \node[state, node distance = \initdist, minimum size=\minsz, below right=of two]
        (three) {(0,T)};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of three]
        (four) {(0,T+1)};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, right=of four]
        (five) {\textbf{\dots}};
        \node[draw=none, minimum size=\minsz, right=of five] (six) {\textbf{\vdots}};
        \node[draw=none, minimum size=\minsz, right=of six] (seven) {\textbf{\dots}};
        \node[state, minimum size=\minsz, right=of seven] (eight) {(0,C)};
        \node[draw=none, minimum size=\minsz, right=of eight] (nine) {\textbf{\dots}};

        % Second Line
        \node[state, minimum size=\minsz, below=of three] (three_one) {(1,T)};
        \node[state, minimum size=\minsz, below=of four] (four_one) {(1,T+1)};
        \node[draw=none, minimum size=\minsz, below=of five] (five_one) {\textbf{\dots}};
        \node[state, minimum size=\minsz, right=of five_one] (six_one) {\( (u_i, v_i) \)};
        \node[draw=none, minimum size=\minsz, right=of six_one] (seven_one) {\textbf{\dots}};
        \node[state, minimum size=\minsz, right=of seven_one] (eight_one) {(1,C)};
        \node[draw=none, minimum size=\minsz, right=of eight_one] (nine_one) {\textbf{\dots}};

        % Third Line
        \node[state, minimum size=\minsz, below=of three_one] (three_two) {(2,T)};
        \node[state, minimum size=\minsz, below=of four_one] (four_two) {(2,T+1)};
        \node[draw=none, minimum size=\minsz, below=of five_one] (five_two) {\textbf{\dots}};
        \node[draw=none, minimum size=\minsz, right=of five_two] (six_two) {\textbf{\vdots}};
        \node[draw=none, minimum size=\minsz, right=of six_two] (seven_two) {\textbf{\dots}};
        \node[state, minimum size=\minsz, right=of seven_two] (eight_two) {(2,C)};
        \node[draw=none, minimum size=\minsz, right=of eight_two] (nine_two) {\textbf{\dots}};

        % Fourth line
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of three_two]
        (three_three) {\textbf{\vdots}};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of four_two]
        (four_three) {\textbf{\vdots}};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of five_two]
        (five_three) {};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of six_two]
        (six_three) {};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of eight_two]
        (eight_three) {\textbf{\vdots}};

        \draw[every loop]
            % First Horizontal Edges
            (zero) edge[bend left] node {\( \Lambda \)} (one)
            (one) edge[bend left] node {\( \mu \)} (zero)
            (one) edge[bend left] node {\( \Lambda \)} (two)
            (two) edge[bend left] node {\( 2 \mu \)} (one)
            (two) edge[bend left] node {\( \Lambda \)} (three)
            (three) edge[bend left] node {\( T \mu \)} (two)
            (three) edge[bend left] node {\( \lambda_1 \)} (four)
            (four) edge[bend left] node {\( (T+1) \mu \)} (three)
            (four) edge[bend left] node {\( \lambda_1 \)} (five)
            (five) edge[bend left] node {\( (T+2) \mu \)} (four)
            % (five) edge[bend left] node {\( \lambda_1 \)} (six)
            % (six) edge[bend left] node [above] {\( C\mu \)} (five)
            % (six) edge[bend left] node {\( \lambda_1 \)} (seven)
            % (seven) edge[bend left] node [above] {\( C\mu \)} (six)
            (seven) edge[bend left] node {\( \lambda_1 \)} (eight)
            (eight) edge[bend left] node {\( C\mu \)} (seven)
            (eight) edge[bend left] node {\( \lambda_1 \)} (nine)
            (nine) edge[bend left] node {\( C\mu \)} (eight)

            % Second Horizontal Edges
            (three_one) edge[bend left] node {\( \lambda_1 \)} (four_one)
            (four_one) edge[bend left] node {\( (T+1) \mu \)} (three_one)
            (four_one) edge[bend left] node {\( \lambda_1 \)} (five_one)
            (five_one) edge[bend left] node {\( (T+2) \mu \)} (four_one)
            (five_one) edge[bend left] node {\( \lambda_1 \)} (six_one)
            (six_one) edge[bend left] node {\( v_i\mu \)} (five_one)
            (six_one) edge[bend left] node {\( \lambda_1 \)} (seven_one)
            (seven_one) edge[bend left] node {\( (v_i+1)\mu \)} (six_one)
            (seven_one) edge[bend left] node {\( \lambda_1 \)} (eight_one)
            (eight_one) edge[bend left] node {\( C\mu \)} (seven_one)
            (eight_one) edge[bend left] node {\( \lambda_1 \)} (nine_one)
            (nine_one) edge[bend left] node {\( C\mu \)} (eight_one)

            % Third Horizontal Edges
            (three_two) edge[bend left] node {\( \lambda_1 \)} (four_two)
            (four_two) edge[bend left] node [below] {\( (T+1) \mu \)} (three_two)
            (four_two) edge[bend left] node {\( \lambda_1 \)} (five_two)
            (five_two) edge[bend left] node {\( (T+2) \mu \)} (four_two)
            % (five_two) edge[bend left] node {\( \lambda_1 \)} (six_two)
            % (six_two) edge[bend left] node [above] {\( C\mu \)} (five_two)
            % (six_two) edge[bend left] node {\( \lambda_1 \)} (seven_two)
            % (seven_two) edge[bend left] node [above] {\( C\mu \)} (six_two)
            (seven_two) edge[bend left] node {\( \lambda_1 \)} (eight_two)
            (eight_two) edge[bend left] node {\( C\mu \)} (seven_two)
            (eight_two) edge[bend left] node {\( \lambda_1 \)} (nine_two)
            (nine_two) edge[bend left] node {\( C\mu \)} (eight_two)

            % First Vertical Edges
            (three) edge[bend left] node {\( \lambda_2 \)} (three_one)
            (three_one) edge[bend left] node {\( T \mu \)} (three)
            (three_one) edge[bend left] node {\( \lambda_2 \)} (three_two)
            (three_two) edge[bend left] node {\( T\mu \)} (three_one)
            (three_two) edge[bend left] node {\( \lambda_2 \)} (three_three)
            (three_three) edge[bend left] node {\( T\mu \)} (three_two)

            % Second Vertical Edges
            (four) edge node {\( \lambda_2 \)} (four_one)
            (four_one) edge node {\( \lambda_2 \)} (four_two)
            (four_two) edge node {\( \lambda_2 \)} (four_three)

            % Third Vertical Edges
            (six) edge node {\( \lambda_2 \)} (six_one)
            (six_one) edge node {\( \lambda_2 \)} (six_two)
            % (six_two) edge node {\( \lambda_2 \)} (six_three)

            % Fourth Vertical Edges
            (eight) edge node {\( \lambda_2 \)} (eight_one)
            (eight_one) edge node {\( \lambda_2 \)} (eight_two)
            (eight_two) edge node {\( \lambda_2 \)} (eight_three)
            ;
    \end{tikzpicture}
    \caption{Markov chains}
    \label{Markov_4}
\end{figure}

\newpage
\begin{figure}[h!]
    \centering
    \begin{tikzpicture}[-, node distance = 0.9cm, auto, every node/.style={scale=0.7}]

        % Markov chain variables
        \tikzmath{
            let \initdist = 0.5cm;
            let \altdist = 1.2cm;
            let \minsz = 1.6cm;
        }

        % S_1 and S_2 rectangles
        \tikzmath{
            let \leftOne = -0.8;
            let \rightOne = 2.7;
            let \upOne = 0.8;
            let \downOne = -2.7;
            let \leftTwo = 2.8;
            let \rightTwo = 13;
            let \upTwo = -2.95;
            let \downTwo = -16.4;
        }

        % General case variables
        \tikzmath{
            let \GCsmallx = 8.3;
            let \GCsmally = -9.5;
            let \GCbigx = 4.1;
            let \GCbigy = -11.8;
        }

        % % Rectangle for S1
        % \draw[ultra thin, dashed] (\leftOne, \downOne) -- (\leftOne, \upOne);
        % \draw[ultra thin, dashed] (\leftOne, \upOne) -- (\rightOne, \upOne);
        % \draw[ultra thin, dashed] (\rightOne, \upOne) -- node {\Huge{\( \quad S_1 \)}}(\rightOne, \downOne);
        % \draw[ultra thin, dashed] (\rightOne, \downOne) -- (\leftOne, \downOne);

        % % Rectangle for S2
        % \draw[ultra thin, dashed] (\leftTwo, \downTwo) -- node {\Huge{\( S_2 \quad \)}}(\leftTwo, \upTwo);
        % \draw[ultra thin, dashed] (\leftTwo, \upTwo) -- (\rightTwo, \upTwo);
        % \draw[ultra thin, dashed] (\rightTwo, \upTwo) -- (\rightTwo, \downTwo);
        % \draw[ultra thin, dashed] (\rightTwo, \downTwo) -- (\leftTwo, \downTwo);

        % Small square of general case
        \draw [thick] (\GCsmallx, \GCsmally) -- node {} (\GCsmallx + 0.4, \GCsmally);
        \draw [thick] (\GCsmallx + 0.4, \GCsmally) -- node {} (\GCsmallx + 0.4,
        \GCsmally - 0.4);
        \draw [thick] (\GCsmallx + 0.4, \GCsmally - 0.4) -- node {} (\GCsmallx,
        \GCsmally - 0.4);
        \draw [thick] (\GCsmallx, \GCsmally - 0.4) -- node {} (\GCsmallx, \GCsmally);

        % Dashed lines to from small square to big one
        \draw [ultra thin] (\GCsmallx, \GCsmally) -- node {} (\GCbigx, \GCbigy);
        \draw [ultra thin] (\GCsmallx + 0.4, \GCsmally) -- node {} (\GCbigx + 4,
        \GCbigy);
        \draw [ultra thin] (\GCsmallx, \GCsmally - 0.4) -- node {} (7, \GCbigy);
        \draw [ultra thin] (\GCsmallx + 0.4, \GCsmally - 0.4) -- node {} (\GCbigx + 4,
        \GCbigy - 4);

        % Big Square of general case
        \draw [ultra thick] (\GCbigx, \GCbigy) -- node {} (\GCbigx + 4, \GCbigy);
        \draw [ultra thick] (\GCbigx + 4, \GCbigy) -- node {} (\GCbigx + 4, \GCbigy - 4);
        \draw [ultra thick] (\GCbigx + 4, \GCbigy - 4) -- node {General Case} (\GCbigx, \GCbigy - 4);
        \draw [ultra thick] (\GCbigx, \GCbigy - 4) -- node {} (\GCbigx, \GCbigy);

        % First Line
        \node[state, minimum size=1.5cm] (zero) {(0,0)};
        \node[state, node distance = \initdist, minimum size=\minsz, below right=of zero]
        (one) {(0,1)};
        \node[draw=none, node distance = \initdist, minimum size=\minsz, below right=of one]
        (two) {\textbf{\( \ddots \)}};
        \node[state, node distance = \initdist, minimum size=\minsz, below right=of two]
        (three) {(0,T)};
        \node[state, node distance = \altdist, minimum size=\minsz, right=of three]
        (four) {(0,T+1)};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, right=of four]
        (five) {\textbf{\dots}};
        \node[state, minimum size=\minsz, right=of five] (six) {(0,C)};
        \node[draw=none, minimum size=\minsz, right=of six] (seven) {\textbf{\dots}};

        % Second Line
        \node[state, minimum size=\minsz, below=of three] (three_one) {(1,T)};
        \node[state, minimum size=\minsz, below=of four] (four_one) {(1,T+1)};
        \node[draw=none, minimum size=\minsz, below=of five] (five_one) {\textbf{\dots}};
        \node[state, minimum size=\minsz, right=of five_one] (six_one) {(1,C)};
        \node[draw=none, minimum size=\minsz, right=of six_one] (seven_one) {\textbf{\dots}};

        % Third Line
        \node[state, minimum size=\minsz, below=of three_one] (three_two) {(2,T)};
        \node[state, minimum size=\minsz, below=of four_one] (four_two) {(2,T+1)};
        \node[draw=none, minimum size=\minsz, below=of five_one] (five_two) {\textbf{\dots}};
        \node[state, minimum size=\minsz, right=of five_two] (six_two) {(2,C)};
        \node[draw=none, minimum size=\minsz, right=of six_two] (seven_two) {\textbf{\dots}};

        % Fourth line
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of three_two]
        (three_three) {\textbf{\vdots}};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of four_two]
        (four_three) {\textbf{\vdots}};
        \node[draw=none, node distance = 2cm, minimum size=\minsz, below=of five_two]
        (five_three) {};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of six_two]
        (six_three) {\textbf{\vdots}};

        % Fifth line
        % \node[state, node distance = \altdist, minimum size=\minsz, below=of five_three] (general_case_mid) {\( (u_i, v_i) \)};
        \node[draw=none, node distance = 0.3cm, minimum size=\minsz, below=of four_three]
        (general_case_up) {};
        \node[state, node distance = \altdist, minimum size=\minsz, below=of general_case_up]
        (general_case_mid) {\( (u_i, v_i) \)};

        \node[draw=none, node distance = \altdist, minimum size=\minsz, below=of general_case_mid]
        (general_case_down) {};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, left=of general_case_mid]
        (general_case_left) {};
        \node[draw=none, node distance = \altdist, minimum size=\minsz, right=of general_case_mid]
        (general_case_right) {};

        \draw[every loop]
            % First Horizontal Edges
            (zero) edge[bend left] node {\( \Lambda \)} (one)
            (one) edge[bend left] node {\( \mu \)} (zero)
            (one) edge[bend left] node {\( \Lambda \)} (two)
            (two) edge[bend left] node {\( 2 \mu \)} (one)
            (two) edge[bend left] node {\( \Lambda \)} (three)
            (three) edge[bend left] node {\( T \mu \)} (two)
            (three) edge[bend left] node {\( \lambda_1 \)} (four)
            (four) edge[bend left] node {\( (T+1) \mu \)} (three)
            (four) edge[bend left] node {\( \lambda_1 \)} (five)
            (five) edge[bend left] node {\( (T+2) \mu \)} (four)
            (five) edge[bend left] node {\( \lambda_1 \)} (six)
            (six) edge[bend left] node {\( C\mu \)} (five)
            (six) edge[bend left] node {\( \lambda_1 \)} (seven)
            (seven) edge[bend left] node {\( C\mu \)} (six)

            % Second Horizontal Edges
            (three_one) edge[bend left] node {\( \lambda_1 \)} (four_one)
            (four_one) edge[bend left] node {\( (T+1) \mu \)} (three_one)
            (four_one) edge[bend left] node {\( \lambda_1 \)} (five_one)
            (five_one) edge[bend left] node {\( (T+2) \mu \)} (four_one)
            (five_one) edge[bend left] node {\( \lambda_1 \)} (six_one)
            (six_one) edge[bend left] node {\( C\mu \)} (five_one)
            (six_one) edge[bend left] node {\( \lambda_1 \)} (seven_one)
            (seven_one) edge[bend left] node {\( C\mu \)} (six_one)

            % Third Horizontal Edges
            (three_two) edge[bend left] node {\( \lambda_1 \)} (four_two)
            (four_two) edge[bend left] node [below] {\( (T+1) \mu \)} (three_two)
            (four_two) edge[bend left] node {\( \lambda_1 \)} (five_two)
            (five_two) edge[bend left] node {\( (T+2) \mu \)} (four_two)
            (five_two) edge[bend left] node {\( \lambda_1 \)} (six_two)
            (six_two) edge[bend left] node {\( C\mu \)} (five_two)
            (six_two) edge[bend left] node {\( \lambda_1 \)} (seven_two)
            (seven_two) edge[bend left] node {\( C\mu \)} (six_two)

            % First Vertical Edges
            (three) edge[bend left] node {\( \lambda_2 \)} (three_one)
            (three_one) edge[bend left] node {\( T \mu \)} (three)
            (three_one) edge[bend left] node {\( \lambda_2 \)} (three_two)
            (three_two) edge[bend left] node {\( T\mu \)} (three_one)
            (three_two) edge[bend left] node {\( \lambda_2 \)} (three_three)
            (three_three) edge[bend left] node {\( T\mu \)} (three_two)

            % Second Vertical Edges
            (four) edge node {\( \lambda_2 \)} (four_one)
            (four_one) edge node {\( \lambda_2 \)} (four_two)
            (four_two) edge node {\( \lambda_2 \)} (four_three)

            % Fourth Vertical Edges
            (six) edge node {\( \lambda_2 \)} (six_one)
            (six_one) edge node {\( \lambda_2 \)} (six_two)
            (six_two) edge node {\( \lambda_2 \)} (six_three)

            % General Case
            (general_case_left) edge[bend left] node {\( \lambda_1 \)} (general_case_mid)
            (general_case_mid) edge[bend left] node {\( v_i \mu \)} (general_case_left)
            (general_case_right) edge[bend left] node {\( (v_i +1) \mu \)} (general_case_mid)
            (general_case_mid) edge[bend left] node {\( \lambda_1 \)} (general_case_right)
            % (five_three) edge node {\( \lambda_2 \)} (general_case_mid)
            (general_case_up) edge node {\( \lambda_2 \)} (general_case_mid)
            (general_case_mid) edge node {\( \lambda_2 \)} (general_case_down)
            ;
    \end{tikzpicture}
    \caption{Markov chain}
    \label{Markov_5}
\end{figure}


\section{Question 3}
We use lead controller to fix transient mode and solve problem.
\newpage
\begin{itemize}
    \item system step responde
    \begin{figure}[H]
        \caption{system step responde}
        \centering
        \includegraphics[width=12cm]{../Figure/Q3/Q3_system_respond.png}
    \end{figure}
    \item system nichols
    \begin{figure}[H]
        \caption{system nichols plot}
        \centering
        \includegraphics[width=12cm]{../Figure/Q3/Q3_system_nichols.png}
    \end{figure}
    \item system with controller step responde
    \begin{figure}[H]
        \caption{system with controller step responde}
        \centering
        \includegraphics[width=12cm]{../Figure/Q3/Q3_system_controller_respond.png}
    \end{figure}
    \item system with controller nichols
    \begin{figure}[H]
        \caption{system with controller nichols plot}
        \centering
        \includegraphics[width=12cm]{../Figure/Q3/Q3_system_controller_nichols.png}
    \end{figure}
    \item system with and without controller step responde
    \begin{figure}[H]
        \caption{system with and without controller step responde}
        \centering
        \includegraphics[width=12cm]{../Figure/Q3/Q3_respond_all.png}
    \end{figure}
    \item system with and without controller nichols
    \begin{figure}[H]
        \caption{system with and withou controller nichols plot}
        \centering
        \includegraphics[width=12cm]{../Figure/Q3/Q3_nichols.png}
    \end{figure}
\end{itemize}


\documentclass[12pt]{cdblatex}
\usepackage{eqtns}

\begin{document}

\section*{PhysRevD.62.044034 equation (10)}

\begin{cadabra}
   from shared import *
   import cdblib

   jsonfile = 'eqtn10.json'
   cdblib.create (jsonfile)

   DgijDt  = cdblib.get ('adm.DgijDt','adm.json')
   DdetgDt = cdblib.get ('adm.DdetgDt','adm.json')

   # --------------------------------------------------------------------------

   phi   := \phi -> (1/12) \log(detg).
   gdotK := g^{i j} K_{i j} -> trK.

   # --------------------------------------------------------------------------
   # d\phi/dt

   dotphi := \partial_{t}{\phi}.     # cdb (eq10.101,dotphi)

   substitute (dotphi, phi)          # cdb (eq10.102,dotphi)
   substitute (dotphi, dlog)         # cdb (eq10.103,dotphi)
   substitute (dotphi, DdetgDt)      # cdb (eq10.104,dotphi)
   substitute (dotphi, DgijDt)       # cdb (eq10.105,dotphi)
   substitute (dotphi, gdotK)        # cdb (eq10.106,dotphi)
   map_sympy  (dotphi, "simplify")   # cdb (eq10.107,dotphi)

   DphiDt := \partial_{t}{\phi} -> @(dotphi).

   cdblib.put ('DphiDt',DphiDt,jsonfile)
\end{cadabra}

\clearpage

\begin{dgroup*}[spread=5pt]
   \begin{dmath*}
      \cdb{eq10.101}
         = \Cdb*{eq10.102}
         = \Cdb*{eq10.103}
         = \Cdb*{eq10.104}
         = \Cdb*{eq10.105}
         = \Cdb*{eq10.106}
         = \Cdb*{eq10.107}
   \end{dmath*}
\end{dgroup*}

\clearpage

\begin{cadabra}
   # --------------------------------------------------------------------------
   # Check against prd62.

   foo := @(dotphi).                                  # cdb(eq10.lcb,foo)
   bah  = cdblib.get('prd62.eq10.rhs','prd62.json')   # cdb(eq10.prd,bah)

   diff := @(foo) - @(bah).

   diff = product_sort (diff)
   rename_dummies (diff)
   canonicalise   (diff)                              # cdb(eq10.chk,diff)
\end{cadabra}

% \clearpage

\begin{dgroup*}
   \begin{dmath*} \cdb*{eq10.lcb} \end{dmath*}
   \begin{dmath*} \cdb*{eq10.prd} \end{dmath*}
   \begin{dmath*} \cdb*{eq10.chk} \end{dmath*}
\end{dgroup*}

\end{document}


\section{Linear discriminant analysis}


\documentclass[]{article}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{algorithmicx}
\usepackage[noend]{algpseudocode}
\usepackage{tabls}

%opening
\title{Estimation of the heat demand}
\author{Francesco Baldi}

\begin{document}

\maketitle

As the heat demand is not measured, it is necessary to determine it based on the available indirect measurements.

The heat demand and generation can be summarized according to the following equations:
\begin{eqnarray}
\dot{Q}_{gen} & = & \dot{Q}_{EGB} + \dot{Q}_{HTHR} + \dot{Q}_{AB} \\
\dot{Q}_{dem} & = & \dot{Q}_{HVAC,PH} + \dot{Q}_{HVAC,RH} + \dot{Q}_{HWH} + \dot{Q}_{TH} + \dot{Q}_{G} + \dot{Q}_{OT} + \dot{Q}_{HTH} + \dot{Q}_{MSH} \\
\end{eqnarray}

\section{Heat balance parameter estimation}

As not enough information and measurements are available to determine the various components of the heat balance, in this paper we determined them by means of a parameter estimation procedure, using the daily boiler fuel consumption for the calibration of the parameters. The parameter estimation problem is hence written as a minimization problem:
\begin{eqnarray}
	min &  \left(\frac{\sum_i(y(\textbf{p})-\bar{y})^2}{\sum_i \bar{y}^2}\right)^{0.5} \\
\end{eqnarray}

where the vector $\textbf{p}$ includes the calibration parameters that are part of the heat demand and generation estimation model that is explained in detail in the following sections. A list of the parameters $\textbf{p}$ is shown in Table REF, together with the chosen upper and lower boundaries for the calibration procedure.
\begin{table}
	\centering
	\begin{tabular}{p{3cm}ccp{1.6cm}p{1.6cm}p{1.2cm}}
		\hline
		Parameter name & Symbol  & Unit & Lower Boundary & Higher Boundary & Optimal value \\
		\hline
		Constant HTHR heat demand	 & $\dot{Q}_{k,HTHR}$ & kW & 0 & 1000 & 137 \\
		Constant steam demand		 & $\dot{Q}_{k,steam}$ & kW & 0 & 1000 & 177 \\
		Weight factor of the HVAC Re-heater & $f_{HVAC,RH}$ & - & 0.5 & 1 & 0.59 \\
		Weight factor of the HVAC Pre-heater & $f_{HVAC,PH}$ & - & 0 & 1 & 0.98 \\
		Weight factor of hot water heater & $f_{HWH}$ & - & 0.5 & 1 & 0.71 \\
		Weight factor of the galley & $f_{G}$ & - & 0.5 & 1 & 0.55 \\
		Weight factor of the other consumers & $f_{Other}$ & - & 0.5 & 1 & 0.27 \\
		HTHR inlet temperature & $T_{HTHR,ER1,in}$ & K & 343 & 353 & 345 \\
		Effectiveness of the HTHR HEX & $\epsilon_{HTHR} $ & - & 0.5 & 0.9 & 0.72 \\
		Boiler drum steam storage capacity & $Q_{ab,max}$ & MJ & 100 & 100000 & 5580 \\
		Boiler heat rate & $\dot{Q}_{ab,des}$ & kW & 2000 & 8000 & 2920 \\
		\hline
	\end{tabular}
	\caption{Parameters optimized in the parameter estimation for the heat balance}
	\label{tab:ParameterEstimation}
\end{table}

\section{Heat demand}

We calculated the heat demand as the sum of the contributions of the elements listed in the ship's heat balance documentation. As no direct measurement of these quantities was available in the dataset, they had to be estimated based on the following assumptions:
\begin{table}
	\centering
	{\tablinesep=2ex\tabcolsep=10pt
	\begin{tabular}{p{2.8cm}l}
		\hline
		Heat flow name & Equation \\
		\hline
		HVAC Preheater & $\dot{Q}_{HVAC,PH} = f_{HVAC,RH} \dot{Q}_{HVAC,PH,des} \dfrac{\dot{W}_{HVAC}(t)}{\dot{W}_{HVAC,max}} $ \\
		HVAC Reheater &	$\dot{Q}_{HVAC,RH} = f_{HVAC,PH} \dot{Q}_{HVAC,PH,des} \dfrac{T_{in} - T_{air,out}(t)}{T_{in} - T_{air,out,des}}$ \\
		Hot water heater& $\dot{Q}_{HWH} = f_{HWH} \dot{Q}_{HWH,des} \Phi_{HWH}(\hat{t})$ \\
		Galley & $\dot{Q}_{G} = f_{G} \dot{Q}_{G,des} \Phi_G(\hat{t})$ \\
		Low temperature tank heating & $\dot{Q}_{TH} = f_{TH} \dot{Q}_{TH} \dfrac{T_{T} - T_{air,out}(t)}{T_{T} -T_{air,out,des}}$ \\
		HFO tank heating & $\dot{Q}_{HTH} = f_{HTH} \dot{Q}_{HTH} \dfrac{T_{HT} - T_{air,out}(t)}{T_{HT} - T_{air,out,des}}$ \\
		Machinery space heating & $\dot{Q}_{MSH} = f_{MSH} \dot{Q}_{MSH} \dfrac{T_{MS} - T_{air,out}(t)}{T_{MS} - T_{air,out,des}}$ \\
		HFO heater & $\dot{Q}_{HH} = \dot{m}_{HFO}(t) c_{p,HFO} (T_{HFO,inj} - T_{HT})$ \\
		\hline
	\end{tabular}}
	\caption{Summary of the heat demand contributions and their calculation}
	\label{tab:HeatDemand}
\end{table}

where all $f_i$ factors are treated as calibration parameters (see table \ref{tab:ParameterEstimation}). The $\Phi_G(\hat{t})$ and $\Phi_{HWH}(\hat{t})$ functions represent the assumption made on the daily evolution of the heating demand from the galley and the hot water heater respectively. The daily evolutions of the demand are considered to be the same over the whole year of operations and are represented graphically in Figure REF.

\section{Heat generation}

\subsection{Exhaust gas boilers}

The heat recovered in the EGBs is the only contribution to the heat balance that is known with a reasonable certainty. The heat transferred from the exhaust gas to the steam ($\dot{Q}_{EGB}$) is calculated according to equation \ref{eq:egb}:
\begin{equation}
\dot{Q}_{EGB} = \dot{m}_{eg} c_{p,eg} (T_{eg,EGB,in} - T_{eg,EGB,out})
\end{equation}\label{eq:egb}

where $T_{eg,EGB,out}$ and $T_{eg,EGB,in}$ are measured for all EGBs, $c_{p,eg}$ is calculated as a function of the exhaust gas composition and temperature, and $ \dot{m}_{eg} $ is calculated based on the engine energy and mass balance as described in section REF and in the appendix REF

\subsection{High Temperature Heat Recovery}

It is known that the ship heating systems are designed for recovering energy from the high temperature cooling systems of all the ship's engines. However, measurements of this contribution and of other variables that could lead to its straight-forward identification are missing. In this work, we calculated the heat exchanged in the two HTHRs according to equation \label{eqn:HTHR2},

\begin{eqnarray}
\dot{Q}_{HTHR} & = & \dot{Q}_{HTHR,ER1} + \dot{Q}_{HTHR,ER2} \label{eqn:HTHR1} \\
 & = & \sum_{i=ER1,ER2}{\epsilon_{HTHR} * \dot{m}_{min,HTHR,i} * c_{p,w} * (T_{HT,out,i} - T_{HRHT,i,in})} \label{eqn:HTHR2}
\end{eqnarray}

where the effectiveness of the heat exchanger $\epsilon_{HTHR}$ is considered to be constant and its value is part of the parameter estimation problem (see table \ref{tab:ParameterEstimation}). The HT water outlet temperature for each engine room is calculated based on the thermal balance of the engines, and the HR water at the HTHR inlet ($T_{HRHT,ER1,in}$) is considered as a calibration parameter.

\subsection{Auxiliary boilers}

The heat generated by the auxiliary boilers is calculated as to close the heat balance of the ship energy systems. The contribution of the boiler heat storage capacity is taken into account by a calibration parameter $Q_{ab,max}$ that determines the maximum heat deficit. This corresponds, in practice, to assuming that the boiler is started up when the steam pressure inside the boiler drops below a certain value, and stopped once the pressure has achieved its maximum operative value. The calculation can be represented as follows

	\begin{algorithmic}[1]
		\State{Calculate the heat balance with no contribution from oil fired boilers}
		\While{$\int{(\dot{Q}_{HTHR}(t) + \dot{Q}_{EGB}(t) - \dot{Q}_{dem}(t)) dt} < - Q_{ab,max}$}
			\State{Find $ t^* | \int_{t_0}^{t^*}{(\dot{Q}_{HTHR}(t) + \dot{Q}_{EGB}(t) - \dot{Q}_{dem}(t))dt} = 0 $}
			\State{$\dot{Q}_{ab}(t^*:t^*+\frac{Q_{ab,max}}{\dot{Q}_{ab,des}}) = \dot{Q}_{ab,des}$}
		\EndWhile
	\end{algorithmic}

where the calibration parameters are the heat storage capacity ($Q_{ab,max}$) and the fixed heat rate ($\dot{Q}_{ab,des}$) of the auxiliary boilers (see table \ref{tab:ParameterEstimation}).

\section{Parameter estimation and uncertainty quantification}

The results of the parameter estimation are represented graphically and quantitatively in Figure REF and Table REF.

Given the lack of input values for the estimation of the heat demand, the provided estimate based on the procedure described above should be integrated with an estimation of the uncertainty.

In this study, we base the estimation of the uncertainty on the production side, as it is the one that has the largest amount of information available. In these regards, the uncertainty can be reduced to the contribution of three elements: $U(\dot{Q}_{EGB})$, $U(\dot{Q}_{HTHR})$, $U(\dot{Q}_{AB})$.

The uncertainty on the heat generated in the EGBs can be further subdivided based on its definition as a composition of the uncertainty of $T_{eg,EGB,in}$, $T_{eg,EGB,out}$, $\dot{m}_{eg}$, and $c_{p,eg}$. In the case of $T_{eg,EGB,in}$ and $T_{eg,EGB,out}$, measured values are used, where the uncertainty is related to the sensors (K-type thermocouples) that can be as high as 4\% [CIT]. The uncertainty on the $\dot{m}_{eg}$ is related to the calculation assumptions as described in Appendix REF, and can be estimated of being up to 10\%. The uncertainty of the $c_{p,eg}$ value, given that both composition and temperature are accounted for, should be within 5\% of the reference value. These assumptions lead to the following estimation of the uncertainty:
\begin{equation}
\frac{\delta \dot{Q}_{gen}}{\dot{Q}_{gen}} = \sqrt{\frac{\delta \dot{m}_{eg}^2}{\dot{m}_{eg}^2} + \frac{\delta c_{p,eg}^2}{c_{p,eg}^2} + \frac{\delta T_{EGB,in}^2 + \delta T_{EGB,out}^2}{(T_{EGB,in} - T_{EGB,out})^2}}
\end{equation}

That once typical values are assigned can be as high as 30\%, where most of the variability is related to the temperature measurements (result obtained for $\pm 20$ K uncertainty. The uncertainty is reduced to 20\% if the measurement uncertainty on the temperature is reduced to  $\pm 20$ K)

The uncertainty of the heat generated by the ABs can be reduced to the contribution of two elements: the uncertainty on $\dot{m}_{fuel,AB}$ and that on $\eta_{AB}$. The former will be at least as large as the calibration error (35\%) and will be considered equal to 50\% to be conservative and accounting also for errors in the aggregated boiler fuel measurements. In addition, the uncertainty on the efficiency can be considered to be around 10\% based on the discrepancy between the considered sources and on the expected variability of the efficiency with load. Similarly to the previous case, the combination of these efficiencies lead to a total uncertainty of 51\%, where the main contribution comes from the uncertainty of the model output compared to the actual fuel consumption.

The estimation of the uncertainty of $\dot{Q}_{HTHR}$ can be based on \ref{eqn:HTHR2} having assigned an acceptable variation of 20\% to the effectiveness of the heat exchanger, 20\% on the estimation of the reference mass flow, $\pm 5$ K uncertainty on water temperature measurements and considering negligible the uncertainty on $c_{p,w}$, leading to a 145\% uncertainty on this measurement.

\end{document}