\subsubsection{Simulations for Fourier-Collocation Method}

	Following the same ideas from the previous section for Fourier-Collocation, we will seek solutions in the space given by $S_N = \widetilde{B}_N \cap H^2_p [0, 2 \pi]$, and using the discrete expansion to the problem (\ref{IVP_Burgers}) as follows
	\begin{align*}
		\mathcal{J}_N u (x, t) =  \displaystyle \sum_{|n| \leq \frac{N}{2}} \widetilde{u}_n (t) e^{inx}, \hspace{2mm}
		\widetilde{u}_n (t) =  \displaystyle \sum_{j=0}^{2N} u (x_j, t)  e^{-in x_j}
	\end{align*}
	or equivalently
	\begin{align*}
		\mathcal{J}_N u (x, t) =  \displaystyle \sum_{j=0}^{2N} u (x_j, t) \psi_j (x)
	\end{align*}
	where $x_j$ are given by
	\begin{align*}
		xj = \frac{2 \pi j}{2N + 1}, \hspace{2mm} j = 0, 1, \dots, 2N.
	\end{align*}

	For this case, the Fourier-Collocation method will be given by the following problem
	\begin{align}
	\label{Collocation_Nonlinear}
		R_{N} (x_j, t) = \frac{\partial u_N}{\partial t} (x_j, t) - \frac{\partial^2 u_N }{\partial x^2} (x_j, t) + \frac{1}{2} \frac{\partial \left[ u_N \right]^2}{\partial x} (x_j, t) = 0
	\end{align}
	which is a system of $2N + 1$ ordinary differential equations that can be solved using the initial condition given by
	\begin{align*}
		\mathcal{J}_N u (x_j, t) =  u_0 (x_j), , \hspace{2mm} j = 0, 1 \dots, 2N
	\end{align*}

	By Setting a vector as follows
	\begin{align*}
		u_N (t) &= (u_N (x_0 , t), u_N (x_1 , t), \dots , u_N (x_{2N} , t))^T,
	\end{align*}
	and the above system of ordinary differential equations can be written as follows
	\begin{align*}
		\frac{d u_N (t)}{dt} =  \alpha D_N^2 u_N (t) - \frac{1}{2} D_N u^2_N (t)
	\end{align*}
	where $D_N$ is the matrix given by (\ref{matrix_DN_odd}), that represents discrete Fourier differentiation, which can be rewrite as
	\begin{align}
		D_N = \displaystyle C^{-1} \Lambda^2_N C
	\end{align}
	where $\Lambda_N = diag \{ ik \}_{|k|\leq N}$, $C$ represents the discrete Fourier transform and $C^{-1}$ the inverse. \\

	Note that the situation here is very different compared to the systems obtained with Fourier-Galerkin. The representation of the non-linear term is more practical to handle with implicit methods, for example, an implicit approach is as follows
	\begin{align*}
		u_N (t_{i + 1} ) =  C^{-1} \Lambda_N C u_N (t_{i}) - \frac{\Delta t}{2} D_N u^2_N (t_{i+1})
	\end{align*}

	It is possible to formulate the above problem as
	\begin{align*}
		W(u_N (t_{i + 1})) =  C^{-1} \Lambda_N C u_N (t_{i}) - u_N (t_{i + 1} ) - \frac{\Delta t}{2} D_N u^2_N (t_{i+1}),
	\end{align*}
	and then we must find $u_N(t_{i + 1})$ that satisfies $W(u_N(t_{i + 1})) = 0$, for example, using the Newton-Raphson method. However, this formulation may require many calculations because the differentiation matrix increases as a function of $N$, and therefore the number of operations. Here we are going to develop a numerical solution that is more practical to implement, implicitly approaching as we did with Fourier-Galerkin on the linear term as follows
	\begin{align*}
		\left[I_N + \frac{\Delta t}{2} u_{0} \Lambda_N \right] u_N (t_{i + 1} ) =  \displaystyle e^{-\Delta t \Lambda^0_N} \left[ u_N (t_{i}) - \frac{\Delta t}{2} D_N u^2_N (t_{i}) \right]
	\end{align*}
	where $\Lambda^0_N = diag \{ \alpha k^2 + \frac{ik}{2} u_0 \}_{|k|\leq N}$, and solving for $u_N (t_{i + 1})$ gives us
	\begin{align}
	\label{Collocation_Euler}
		u_N (t_{i + 1} ) =  \displaystyle \left[I_N + \frac{\Delta t}{2} u_{0} \Lambda_N \right]^{-1} e^{-\Delta t \Lambda^0_N} \left[ u_N (t_{i})  - \frac{\Delta t}{2} D_N u^2_N (t_{i}) \right]
	\end{align}
	which is very similar to \ref{Galerkin_Euler}, except for the nonlinear term. \\

	This formulation will be used for its implementation, and we will present some numerical results that were obtained using the same information that was used with Fourier-Galerkin, the difference is that the calculations are performed in real space using the differentiation matrix $D_N$, and in this case, we have the advantage of approximating the second derivative with $D^2_N = D_N \cdot D_N$. \\

	The description of the following results is as follows. In the figure \ref{Collocation_alphas} shows the maximum distance over every $t \in [0, 100]$ between the exact solution and its approximations given by (\ref{Collocation_Euler}) for $N = 2^m$, $m = 4, \dots, 12$, $\Delta t = 1.0 \times 10^{-5}$, and different values of $\alpha$. Furthermore, in Tables \ref{Collocation_tabla_L2_alpha=1} and \ref{Collocation_tabla_max_alpha=1}, we can see the numerical values of these distances for different configurations of $N$ and $\Delta t$. Similarly, in Tables \ref{Collocation_tabla_L2_alpha=005} and \ref{Collocation_tabla_max_alpha=005} but for $\alpha = 0.005$.

	\newpage
	\begin{figure}[H]
		\centering
		\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/alphas_Error_N.png}
		\caption{(a) $L^2$-norm between the exact solution and its approximations using Collocation method. (b) Max norm between the exact solution and its approximations.}
		\label{Collocation_alphas}
	\end{figure}

	\newpage
	\begin{figure}[H]
		\centering
		\caption{Numerical solution for (\ref{IVP_Burgers}) using (\ref{Collocation_Euler}) with $\alpha = 1.0$, $N=2048$, and $\Delta t = 1.0 \times 10^{-5}$.}
		\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/Numerical_Solution_alpha=1.png}
		\label{Collocation_alpha=1}
		\caption{Numerical solution for (\ref{IVP_Burgers}) using (\ref{Collocation_Euler}) at the time $T = 100$ with $\alpha = 1.0$, and $\Delta t = 1.0 \times 10^{-5}$. (b) Point-wise error of approximation}
		\includegraphics[width=12.5cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/Numerical_Solution_alpha=1_T=100.png}
		\label{Collocation_alpha=1_T}
	\end{figure}
	\begin{table}[H]
		\begin{tabular}{lcccc}
			\toprule
			\multicolumn{1}{c}{\textbf{Expansion}} & \multicolumn{4}{c}{\textbf{Error}} \\
			$\hspace{9mm}N$ & $\Delta t=1\times 10^{-2}$ & $\Delta t=1\times 10^{-3}$ & $\Delta t=1\times 10^{-4}$ & $\Delta t=1\times 10^{-5}$ \\
			\midrule
			\hspace{7mm} 16 & 0.721112    & 0.721112    & 0.721112    & 0.721112    \\
			\midrule
			\hspace{7mm} 32 & 4.71797 $\times 10^{-2}$   & 4.72892 $\times 10^{-2}$   & 4.73004 $\times 10^{-2}$   & 4.73015 $\times 10^{-2}$   \\
			\midrule
			\hspace{7mm} 64 & 1.17954 $\times 10^{-3}$  & 7.35344 $\times 10^{-4}$ & 7.27561 $\times 10^{-4}$ & 7.27283 $\times 10^{-4}$  \\
			\midrule
			\hspace{7mm} 128 & 9.43454 $\times 10^{-4}$ & 1.75152 $\times 10^{-4}$ & 1.74583 $\times 10^{-4}$ & 1.74574 $\times 10^{-4}$ \\
			\midrule
			\hspace{7mm} 256 & 9.43454 $\times 10^{-4}$ & 1.15509 $\times 10^{-4}$ & 1.14669 $\times 10^{-4}$ & 1.14659 $\times 10^{-4}$ \\
			\midrule
			\hspace{7mm} 512 & 9.43454 $\times 10^{-4}$ & 9.41793 $\times 10^{-5}$ & 7.78847 $\times 10^{-5}$ & 7.78707 $\times 10^{-5}$ \\
			\midrule
			\hspace{7mm} 1024 & $\ast$         & 9.41793 $\times 10^{-5}$ & 5.32213 $\times 10^{-5}$ & 5.32019 $\times 10^{-5}$ \\
			\midrule
			\hspace{7mm} 2048 & $\ast$           & $\ast$           & 3.56779 $\times 10^{-5}$ & 3.56498 $\times 10^{-5}$ \\
			\\
			\bottomrule
		\end{tabular}
		\caption{Error using $L^2$-norm with $\alpha=1.0$}
		\label{Collocation_tabla_L2_alpha=1}
		\vspace{1cm}
		\begin{tabular}{lcccc}
			\toprule
			\multicolumn{1}{c}{\textbf{Expansion}} & \multicolumn{4}{c}{\textbf{Error}} \\
			$\hspace{9mm}N$ & $\Delta t=1\times 10^{-2}$ & $\Delta t=1\times 10^{-3}$ & $\Delta t=1\times 10^{-4}$ & $\Delta t=1\times 10^{-5}$ \\
			\midrule
			\hspace{7mm} 16 & 0.317617    & 0.317617    & 0.317617    & 0.317617    \\
			\midrule
			\hspace{7mm} 32 & 1.95279 $\times 10 ^{-2}$  & 1.96812 $\times 10 ^{-2}$   & 1.96965 $\times 10 ^{-2}$   & 1.96981 $\times 10 ^{-2}$   \\
			\midrule
			\hspace{7mm} 64 & 6.21793 $\times 10 ^{-4}$ & 2.9813 $\times 10 ^{-4}$  & 2.80086 $\times 10 ^{-4}$ & 2.78934 $\times 10 ^{-4}$ \\
			\midrule
			\hspace{7mm} 128 & 4.74952 $\times 10 ^{-4}$ & 1.64746 $\times 10 ^{-4}$ & 1.6473 $\times 10 ^{-4}$  & 1.64728 $\times 10 ^{-4}$ \\
			\midrule
			\hspace{7mm} 256 & 4.74936 $\times 10 ^{-4}$ & 1.52482 $\times 10 ^{-4}$ & 1.52467 $\times 10 ^{-4}$ & 1.52465 $\times 10 ^{-4}$ \\
			\midrule
			\hspace{7mm} 512 & 4.74936 $\times 10 ^{-4}$ & 1.47249 $\times 10 ^{-4}$ & 1.47234 $\times 10 ^{-4}$ & 1.47232 $\times 10 ^{-4}$ \\
			\midrule
			\hspace{7mm} 1024 & $\ast$           & 1.45032 $\times 10 ^{-4}$ & 1.45017 $\times 10 ^{-4}$ & 1.45016 $\times 10 ^{-4}$ \\
			\midrule
			\hspace{7mm} 2048 & $\ast$           & $\ast$           & 1.43941 $\times 10 ^{-4}$ & 1.4394 $\times 10 ^{-4}$ \\
			\\
			\bottomrule
		\end{tabular}
		\caption{Error using Max norm with $\alpha=1.0$}
		\label{Collocation_tabla_max_alpha=1}
	\end{table}

	\begin{figure}[H]
		\centering
		\caption{Numerical solution for (\ref{IVP_Burgers}) using (\ref{Collocation_Euler}) with $\alpha = 0.005$, $N=2048$, and $\Delta t = 1.0 \times 10^{-5}$.}
		\includegraphics[width=12cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/Numerical_Solution_alpha=0005.png}
		\label{Collocation_alpha=005}
		\caption{Numerical solution for (\ref{IVP_Burgers}) using (\ref{Collocation_Euler}) at the time $T = 100$ with $\alpha = 0.005$, and $\Delta t = 1.0 \times 10^{-5}$. (b) Point-wise error of approximation.}
		\includegraphics[width=12.5cm]{burgers_equation/deterministic/numerical_experiments/viscid/figures/collocation/Numerical_Solution_alpha=0005_T=100.png}
		\label{Collocation_alpha=005_T}
	\end{figure}
	%L2

	\begin{table}[H]
	\begin{tabular}{lcccc}
		\toprule
		\multicolumn{1}{c}{\textbf{Expansion}} & \multicolumn{4}{c}{\textbf{Error}} \\
		$\hspace{9mm}N$ & $\Delta t=1\times 10^{-2}$ & $\Delta t=1\times 10^{-3}$ & $\Delta t=1\times 10^{-4}$ & $\Delta t=1\times 10^{-5}$ \\
		\midrule
		\hspace{7mm} 16 & 1.36189   & 1.35883    & 1.35852   & 1.35849   \\
		\midrule
		\hspace{7mm} 32 & 2.67506   & 2.65305    & 2.65078   & 2.65055   \\
		\midrule
		\hspace{7mm} 64 & 2.50365   & 2.45855    & 2.45432   & 2.45387   \\
		\midrule
		\hspace{7mm} 128 & 2.15795   & 2.0632     & 2.05589   & 2.05497   \\
		\midrule
		\hspace{7mm} 256 & 1.362     & 1.18393    & 1.16697   & 1.16532   \\
		\midrule
		\hspace{7mm} 512 & 0.350775  & 0.304595   & 0.300865  & 0.300499  \\
		\midrule
		\hspace{7mm} 1024 & 0.168462  & 0.140332   & 0.13803   & 0.137804  \\
		\midrule
		\hspace{7mm} 2048 & 6.56161 $\times 10^{-2}$ & 4.63808 $\times 10^{-2}$  & 4.49226 $\times 10^{-2}$ & 4.47813 $\times 10^{-2}$ \\
		\\
		\bottomrule
	\end{tabular}
	\caption{Error using $L^2$-norm with $\alpha=0.005$}
	\label{Collocation_tabla_L2_alpha=005}
	\vspace{1cm}
	\begin{tabular}{lcccc}
		\toprule
		\multicolumn{1}{c}{\textbf{Expansion}} & \multicolumn{4}{c}{\textbf{Error}} \\
		$\hspace{9mm}N$ & $\Delta t=1\times 10^{-2}$ & $\Delta t=1\times 10^{-3}$ & $\Delta t=1\times 10^{-4}$ & $\Delta t=1\times 10^{-5}$ \\
		\midrule
		\hspace{7mm} 16 & 0.695784 & 0.695659  & 0.695646  & 0.695645 \\
		\midrule
		\hspace{7mm} 32 & 1.20278  & 1.19418   & 1.19329   & 1.1932   \\
		\midrule
		\hspace{7mm} 64 & 1.22454  & 1.18903   & 1.18507   & 1.18467  \\
		\midrule
		\hspace{7mm} 128 & 1.11999  & 1.0238    & 1.01754   & 1.01701  \\
		\midrule
		\hspace{7mm} 256 & 0.927954 & 0.877058  & 0.872508  & 0.87201  \\
		\midrule
		\hspace{7mm} 512 & 0.664133 & 0.415288  & 0.39714   & 0.395563 \\
		\midrule
		\hspace{7mm} 1024 & 0.247742 & 0.259451  & 0.260605  & 0.26072  \\
		\midrule
		\hspace{7mm} 2048 & 0.126824 & 0.103297  & 0.107102  & 0.10748  \\
		\\
		\bottomrule
	\end{tabular}
	\caption{Error using Max norm with $\alpha=0.005$}
	\label{Collocation_tabla_max_alpha=005}
	\end{table}


In \texttt{MoveUrBody} code there are various implementations: some of them simulate colliding bodies.
In this section we try to explain what kind of collisions are used if the implementation considers colliding bodies.

\subsection{Collisions detection}
We choose \textit{a posteriori} method in order to detect collisions: this is a discrete and easy to implement method.
We detect the collisions after they append.
This is less expensive in term of computations than \textit{a priori} method (continuous).
In \texttt{MoveUrBody} we consider that \textbf{the shape of all the bodies is a sphere}, so two bodies $i$ and $j$ are colliding if:
\begin{equation}
\label{eq:collsDetection}
	||\vec{r_{ij}}|| - (r_i + r_j) \leq 0,
\end{equation}
where $r_i$ and $r_j$ are respectively the radii of body $i$ and body $j$.

\subsection{Elastic collisions}
Notation: Throughout this section, $m$ is the mass and $v$ is the velocity.
Be aware that $v = ||\vec{v}||$.
Subscripts $i$ and $j$ distinguish between the two colliding bodies.
An apostrophe after a variable means that the value is taken after the collision (called prime; i.e., $v$' is "$v$ prime").\\

In \texttt{MoveUrBody} we consider that \textbf{all collisions are perfectly elastic}.
An elastic collision is a collision in which kinetic energy is conserved.
That means no energy is lost as heat or sound during the collision.
In the real world, there are no perfectly elastic collisions on an everyday scale of size.
But you can get the sense of an elastic collision by imagining a perfect pool ball which doesn't waste any energy when it collides.
In an elastic collision, both kinetic energy and momentum are conserved (the total before and after the collision remains the same).
Momentum is the product of mass and velocity:
\begin{equation}
\label{eq:momentum}
	\vec{p} = m . \vec{v}.
\end{equation}
The kinetic energy of an object is one-half times its mass times the square of its velocity:
\begin{equation}
\label{eq:kinetic}
	E_k = \frac{1}{2} . m . v^2.
\end{equation}
Now it is easy to write the conservation of momentum and kinetic energy as two equations:
\begin{enumerate}
	\item Conservation of momentum
		\begin{equation}
		\label{eq:momentumCons}
			m_i . \vec{v_i} + m_j . \vec{v_j} = m_i . \vec{v'_i} + m_j . \vec{v'_j}
		\end{equation}

	\item Conservation of kinetic energy
		\begin{equation}
		\label{eq:kineticCons}
			\frac{1}{2} . m_i . (v_i)^2 + \frac{1}{2} . m_j . (v_j)^2 = \frac{1}{2} . m_i . (v'_i)^2 + \frac{1}{2} . m_j . (v'_j)^2
		\end{equation}
\end{enumerate}

\subsubsection{1-Dimensional elastic collisions}
Combining the two previous equations (Eq.~\ref{eq:momentumCons} and \ref{eq:kineticCons}) and doing a lot of algebra gives the final (after collision) velocities of body $i$ and $j$:
\begin{equation}
\label{eq:1DelasticSols}
	v'_i = \frac{v_i(m_i-m_j) + 2.m_j.v_j}{m_i + m_j},~~v'_j = \frac{v_j(m_j-m_i) + 2.m_i.v_i}{m_j + m_i}.
\end{equation}
This result allows us to find the velocity of two objects after undergoing a one-dimensional elastic collision.
We will use this result later in the 3-dimensional case.

\subsubsection{3-Dimensional elastic collisions}
In previous sub-section (1D elastic collisions) vectors representation was not very important.
Now in 3D, we will use the component representation of a vector: $\vec{v} = \left\{ v_x, v_y, v_z \right\}$.\\

We will follow a 7-step process to find the new velocities of two objects after a collision.
The basic goal of the process is to project the velocity vectors of the two objects onto the vectors which are normal (perpendicular) and tangent to the plan of the collision.
This gives us a normal component and two tangential components (defining a plan) for each velocity.
The tangential components of the velocities are not changed by the collision because there is no force along the tangent plan to the collision surface.
The normal components of the velocities undergo a one-dimensional collision, which can be computed using the one-dimensional collision formulas presented above.
Next the unit normal vector is multiplied by the scalar (plain number, not a vector) normal velocity after the collision to get a vector which has a direction normal to the collision surface and a magnitude which is the normal component of the velocity after the collision.
The same is done with the unit tangent vectors and the tangential velocity components.
Finally the new velocity vectors are found by adding the normal velocity and the two tangential velocity vectors for each object.

\paragraph{Step 1}
~\\
Find the unit normal and the two unit tangent vectors.
The unit normal vector is a vector which has a magnitude of 1 and a direction that is normal (perpendicular) to the surfaces of the objects at the point of collision.
The two unit tangent vectors are vectors with a magnitude of 1 which are forming a tangent plan to the circle's surfaces at the point of collision.

First find a normal vector.
This is done by taking a vector whose components are the difference between the coordinates of the centers of the spheres.
Let $q_i = \left\{q_{ix}, q_{iy}, q_{iz}\right\}$, $q_j = \left\{q_{jx}, q_{jy}, q_{jz}\right\}$ coordinates of the centers of the spheres (it does not matter which spheres is labelled $i$ or $j$; the end result will be the same).
Then the normal vector $\vec{n}$ is:
\begin{equation*}
	\vec{n} = \left\{ q_{jx} - q_{ix},~q_{jy} - q_{iy},~q_{jz} - q_{iz}  \right\}.
\end{equation*}
Next, we have to find the unit vector of $\vec{n}$, which we will call $\vec{un}$. This is done by dividing by the magnitude of $\vec{n}$:
\begin{equation*}
	\vec{un} = \frac{\vec{n}}{||\vec{n}||} = \frac{\vec{n}}{\sqrt{n_x^2 + n_y^2 + n_z^2}}.
\end{equation*}
Once it's done we need to find the two unit tangent vectors which are forming the collision tangent plan.
Those two unit tangent vectors ($\vec{ut_1}$ and $\vec{ut_2}$) are perpendicular to the unit normal vector $\vec{un}$ and there are also perpendicular between themselves (in order to form a Cartesian coordinate system).
Before trying to determine two unit tangent vectors $\vec{ut_1}$ and $\vec{ut_2}$ we will try to find a tangent vector $\vec{t_1}$.
If $\vec{t_1}$ is perpendicular to $\vec{un}$ then the scalar product (alias dot product) of the two should be null:
\begin{equation*}
	\vec{t_1} . \vec{un} = 0 \Leftrightarrow	(t_{1x} . un_x) + (t_{1y} . un_y) + (t_{1z} . un_z) = 0.
\end{equation*}
The first and easy solution to this previous equation is the null vector $\vec{0}$ but we obviously want to avoid it.
An idea is to fix one of the three components to 0 and an other to 1 in order to determine a perpendicular vector $\vec{t_1}$ (be aware that there is an infinity of perpendicular vectors to $\vec{un}$ and we just need to find one of them).\\
If $un_x \neq 0$:
\begin{equation*}
	\vec{t_1} = \left\{ -\frac{un_y}{un_x}, 1, 0 \right\}.
\end{equation*}
If $un_y \neq 0$:
\begin{equation*}
	\vec{t_1} = \left\{ 1, -\frac{un_x}{un_y}, 0 \right\}.
\end{equation*}
If $un_z \neq 0$:
\begin{equation*}
	\vec{t_1} = \left\{ 1, 0, -\frac{un_x}{un_z} \right\}.
\end{equation*}
We have to choose one of the three previous propositions and be sure to avoid to divide by 0.
Now we have to normalize $\vec{t_1}$ in order to find the unitary $\vec{ut_1}$ vector:
\begin{equation*}
	\vec{ut_1} = \frac{\vec{t_1}}{||\vec{t_1}||} = \frac{\vec{t_1}}{\sqrt{t_{1x}^2 + t_{1y}^2 + t_{1z}^2}}.
\end{equation*}
It remains to determine the $\vec{ut_2}$ vector, this can be done by computing the cross product (alias vector product) between $\vec{un}$ and $\vec{ut_1}$:
\begin{equation*}
	\vec{ut_2} = \vec{un} \wedge \vec{ut_1} = \left\{ (un_y . ut_{1z} - un_z . ut_{1y}), (un_z . ut_{1x} - un_x . ut_{1z}), (un_x . ut_{1y} - un_y . ut_{1x})\right\}.
\end{equation*}

\paragraph{Step 2}
~\\
Create the initial (before the collision) velocity vectors, $\vec{v_i}$ and $\vec{v_j}$.
These are just the $x$, $y$ and $z$ components of the velocities put into vectors: $\vec{v_i} = \left\{ v_{ix}, v_{iy} \right\}$ (and similarly for $\vec{v_j}$).
Note that this step really isn't necessary if the velocities are already represented as vectors.
This step is needed only if the velocities are initially represented as separate $x$, $y$ and $z$ values.

\paragraph{Step 3}
~\\
Keep in mind that after the collision the tangential components of the velocities are unchanged and the normal component of the velocities can be found using the one-dimensional collision formulas presented earlier.
So we need to resolve the velocity vectors, $\vec{v_i}$ and $\vec{v_j}$, into normal and tangential components.
To do this, project the velocity vectors onto the unit normal and unit tangent vectors by computing the dot product.
Let $v_{in}$ be the scalar (plain number, not a vector) velocity of body $i$ in the normal direction.
Let $v_{it1}$ and $v_{it2}$ be the scalar velocity of body $i$ in the tangential directions.
Similarly, let $v_{jn}$, $v_{jt1}$ and $v_{jt2}$ be for body $j$.
These values are found by projecting the velocity vectors onto the unit normal and unit tangent vectors, which is done by taking the dot (alias scalar) product:
\begin{equation*}
	v_{in} = \vec{v_i}.\vec{un},~~v_{it1} = \vec{v_i}.\vec{ut_1},~~v_{it2} = \vec{v_i}.\vec{ut_2},
\end{equation*}
\begin{equation*}
	v_{jn} = \vec{v_j}.\vec{un},~~v_{jt1} = \vec{v_j}.\vec{ut_1},~~v_{jt2} = \vec{v_j}.\vec{ut_2}.
\end{equation*}

\paragraph{Step 4}
~\\
Find the new tangential velocities (after the collision).
This is the simplest step of all.
The tangential components of the velocity do not change after the collision because there is no force between the spheres in the tangential direction during the collision.
So, the new tangential velocities are simply equal to the old ones:
\begin{equation*}
	v'_{it1} = v_{it1},~~v'_{it2} = v_{it2},
\end{equation*}
\begin{equation*}
	v'_{jt1} = v_{jt1},~~v'_{jt2} = v_{jt2}.
\end{equation*}

\paragraph{Step 5}
~\\
Find the new normal velocities.
This is where we use the one-dimensional collision formulas (Eq.~\ref{eq:1DelasticSols}).
The velocities of the two spheres along the normal direction are perpendicular to the surfaces
of the spheres at the point of collision, so this really is a one-dimensional collision:
\begin{equation*}
	v'_{in} = \frac{v_{in}(m_i-m_j) + 2.m_j.v_{jn}}{m_i + m_j},
\end{equation*}
\begin{equation*}
	v'_{jn} = \frac{v_{jn}(m_j-m_i) + 2.m_i.v_{in}}{m_j + m_i}.
\end{equation*}

\paragraph{Step 6}
~\\
Convert the scalar normal and tangential velocities into vectors.
This is easy just multiply the unit normal vector by the scalar normal velocity and you get a vector which has a direction that is normal to the surfaces at the point of collision and which has a magnitude equal to the normal component of the velocity.
It is similar for the tangential components:
\begin{equation*}
	\vec{v'_{in}} = v'_{in} . \vec{un},~~\vec{v'_{it1}} = v'_{it1} . \vec{ut_1},~~\vec{v'_{it2}} = v'_{it2} . \vec{ut_2},
\end{equation*}
\begin{equation*}
	\vec{v'_{jn}} = v'_{jn} . \vec{un},~~\vec{v'_{jt1}} = v'_{jt1} . \vec{ut_1},~~\vec{v'_{jt2}} = v'_{jt2} . \vec{ut_2}.
\end{equation*}

\paragraph{Step 7}
~\\
Find the final velocity vectors by adding the normal and tangential components for each body:
\begin{equation*}
	\vec{v'_i} = \vec{v'_{in}} + \vec{v'_{it1}} + \vec{v'_{it2}},
\end{equation*}
\begin{equation*}
	\vec{v'_j} = \vec{v'_{jn}} + \vec{v'_{jt1}} + \vec{v'_{jt2}}.
\end{equation*}
Now we have the final (after collision) velocity of each body as a vector.


\appendix
\chapter{Gaussian Integrals}
\section{Basic Gaussians}
Lots of Gaussian integrals happen in this subject. In the interests of not getting stuck, here are the results.

The basic Gaussian integral for \( a \in \mathbb{R}^+\) is
\[ \int_\mathbb{R} e^{-ax^2} \dd{x} = \sqrt\frac{\pi}{a} \] which we can then use Feynman's trick of differentiation with respect to the parameter and symmetry arguments to find
\begin{align*}
  \int_\mathbb{R} x^n e^{-ax^2} \dd{x} &= \begin{cases}
    \pdv[\nicefrac{n}{2}]{a} \sqrt\frac{\pi}{a} & \text{if \(n\) even}\\
    0 & \text{otherwise}
  \end{cases}.
\end{align*}

If there is an \(e^{bx} \) power, this may be taken care of using completing the square, given
\begin{align*}
  \int_\mathbb{R} e^{-ax^2+bx} \dd{x} &= \int_\mathbb{R} e^{-a(x - \nicefrac{b}{2a})^2+\nicefrac{b^2}{4a}} \dd{x}\\
  &= \sqrt\frac{\pi}{a} e^{\nicefrac{b^2}{4a}}
\end{align*}
and if we make \(b = ik\) this still works, which shows that the fourier transform of a Gaussian is still a Gaussian.
With these, Feynman's trick still works, and works even better than before as we now have single \(x\) powers to play with --- just keep differentiating.

By closing one's contour cleverly, one can also solve Fresnel (and similar) integrals with a complex integrand. This gives
\begin{align*}
  \int_\mathbb{R} e^{-iax^2+ikx} \dd{x}
  &= \sqrt\frac{i\pi}{a} e^{\nicefrac{-k^2}{4a}}
\end{align*}
which is the same as what you get if you just substitute into the previous result, but it's not obvious that that should be the case.

\section{Nested Gaussians}\label{sec:nested-gaussians}
When it is said that there are a lot of Gaussians, what makes it all the harder is that they all happen \emph{all at once}.

Firstly, we look at a double Gaussian, in the form
\begin{align*}
  I &= \int_{-\infty}^\infty e^{\nicefrac{i}{a} {(x-u)^2}}e^{ \nicefrac{i}{b}(u-y)^2}\dd{u}
\end{align*}
which is a bit tricky because they're coupled.
We use a clever trick, by which we use the translational invariance of these integrals, making a mapping \( u \mapsto u + y \) which makes the whole thing a function of \( z = x - y \).
Utilising this gives us
\begin{align*}
  \frac{i}{a}(z-u)^2 + \frac{i}{b}u^2 &= \frac{i}{a}(z^2 - 2zu + u^2) + \frac{i}{b}u^2\\
  &= i\qty(\frac{1}{a} + \frac{1}{b})\qty(u - \frac{z}{a \qty(\frac{1}{a} + \frac{1}{b})})^2 + \frac{i}{a}z^2 + i \frac{z^2}{a^2 \qty(\frac{1}{a}  + \frac{1}{b})}\\
  &= i\qty(\frac{1}{a} + \frac{1}{b})\qty(u - \frac{z}{ia \qty(\frac{1}{a} + \frac{1}{b})})^2 + iz^2\frac{1}{a + b}
\end{align*}
which with another translation gives us the really nice answer that \[ I = e^{i\frac{z^2}{a + b}} \sqrt{\frac{iab\pi}{a+b}}.\]

The $N$-th nested Gaussian, \( I_N \), is the logical extension of this, and telescopes rather nicely.
We set
\begin{align*}
  I_N &= \idotsint \dd{x_1} \cdots \dd{x_N} e^{i \qty[ (x_1 - x_0 )^2 + (x_2 - x_1)^2 + \ldots + (x_{N+1} - x_{N})^2]}\\
      &= \sqrt{\frac{i\pi}{2}}\idotsint \dd{x_2} \cdots \dd{x_N} \exp[i \qty[ \nicefrac{1}{2}(x_2 - x_0 )^2 + (x_2 - x_1)^2 + \ldots + (x_{N+1} - x_{N})^2]]\\
      &= \sqrt{\frac{i\pi}{N+1}}\exp[i \nicefrac{(x_{N+1} - x_0)^2}{N+1}]
\end{align*}
which is a nice enough statement.

\chapter{Functional Derivatives}
A functional derivative generalises the derivative from
\begin{align*}
  \pdv{J_i}\sum_j J_j x_j &= x_i & \pdv{J_i} &= \delta_{ij}
\end{align*}
to cover a smooth function on a continuous domain such that
\begin{align*}
  \pdv{J(t)}J(t^\prime) &= \delta(t-t^\prime) & \fdv{J(t)}  \int_{t_a}^{t_b} J(t^\prime) x(t^\prime) \dd{t^\prime} &= \int_{t_a}^{t_b} \delta(t - t^\prime) x(t^\prime) \dd{t^\prime}\\
  &&&= \begin{cases}
    x(t) & t_a < t^\prime < t_b\\
    0 & \text{otherwise}.
  \end{cases}
\end{align*}

Functional derivatives have the following properties:
\begin{description}
  \item [Linearity] \[ \fdv{(\lambda F + \mu G)[\rho]}{\rho(x)} = \lambda \fdv{F[\rho]}{\rho(x)} + \mu \fdv{G[\rho]}{\rho(x)}\]
  for \(\lambda, \mu\) constant,
  \item [Chain Rule] \[ \fdv{(FG)[\rho]}{\rho} = \fdv{F[\rho]}{\rho(x)}G[\rho] + F[\rho]\fdv{F[\rho]}{\rho(x)} \]
  \item [Product Rules] These are logical. Look them up if you need them.
\end{description}

We can use an equivalent of the Euler-Lagrange equation to find the functional derivative, \[ \fdv{F}{\rho(r)} = \pdv{f}{\rho} - \partial^\mu \pdv{f}{\qty(\partial^\mu \rho)}.\]


% arara: pdflatex
% arara: pdflatex

\documentclass[letterpaper,10pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{siunitx}
\usepackage{physics}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}

\begin{document}

\section{Introduction}

Simpson's rule is a method for performing numerical integration. While there are several different approximations under the name ``Simpson's rule'', the most
common version, Simpson's 1/3 rule, is equivalent fitting a 2'nd degree polynomial to three points so that the integration can be carried out analytically.
It is usually written as:
\begin{equation}
  \label{eq:simpsons}
  \int_a^b f(x) \dd x \approx \frac{b-a}{6}\left[ f(a) + 4f\qty(\frac{a+b}{2}) + f(b)\right]
\end{equation}
This can be extended to larger domains with more function evaluations by breaking the domain into sub-domains and applying
\ref{eq:simpsons} to each.
However, equation \ref{eq:simpsons} assumes that the function $f(x)$ is evaluated at equally spaced points. If we have a discretized
function that is \emph{not} evaluated at equally spaced points, equation \ref{eq:simpsons} cannot be used.

\section{Generalizing to Non-Uniform Spacing}

To generalize equation \ref{eq:simpsons} to non-equally spaced points, we just need to perform the polynomial fit using non-equally spaced points an
perform the integration on the new fit. Using Lagrange polynomial interpolation, we have
\begin{equation}
  f(x) \approx f(x_1) \frac{ (x-x_2)(x-x_3) }{ (x_1 - x_2)(x_1 - x_3) }
             + f(x_2) \frac{ (x-x_1)(x-x_3) }{ (x_2 - x_1)(x_2 - x_3) }
             + f(x_3) \frac{ (x-x_1)(x-x_2) }{ (x_3 - x_1)(x_3 - x_2) }
\end{equation}
where $x_1$, $x_2$, and $x_3$ are the points at which the function is evaluated.

The Lagrange basis polynomials can be written as
\begin{equation}
  \label{eq:lagrange}
  l(x,A,B,C) = \frac{(x-A)(x-B)}{(C-A)(C-B)}
\end{equation}
and we can rewrite the interpolation as
\begin{equation}
  f(x) \approx
    f(x_1) l(x,x_2,x_3,x_1)
  + f(x_2) l(x,x_1,x_3,x_2)
  + f(x_3) l(x,x_1,x_2,x_3)
\end{equation}

\subsection{Method 1: Integrating the Lagrange polynomials directly}
Integrating the Lagrrange basis polynomials from $a$ to $b$ gives
\begin{equation}
  L(A,B,C,a,b) = \int_a^b l(x,A,B,C) \dd x = \frac{1}{(C-A)(C-B)} \left[ \frac{1}{3} \qty(b^3 - a^3) + \frac{A+B}{2}\qty(b^2 - a^2) + AB(b-a)  \right]
\end{equation}
and the integral of $f(x)$ is then approximated as
\begin{equation}
  \int_a^b f(x) \dd x \approx
    f(x_1) L(x_2,x_3,x_1,a,b)
  + f(x_2) L(x_1,x_3,x_2,a,b)
  + f(x_3) L(x_1,x_2,x_3,a,b)
\end{equation}

To reproduce equation \ref{eq:simpsons}, we let $x_1 = a$, $x_2 = \frac{a+b}{2}$, and $x_3 = b$. For example,
\begin{align}
  L(x_2,x_3,x_1,a,b) = \frac{1}{(a-\frac{a+b}{2})(a-b)} \qty[\frac{1}{3} \qty(b^3 - a^3) + \frac{\frac{a+b}{2} + b}{2}\qty(b^2 - a^2) + \frac{a+b}{2}b\qty(b-a) ]
\end{align}
apparently reduces to $\frac{b-a}{6}$...

\subsection{Method 2: Integrating the Lagrange polynomials by parts}

Integrating the Lagrange polynomials by parts gives
\begin{align}
  L(A,B,C,a,b) &= \int_a^b l(x,A,B,C) \dd x = \frac{1}{(C-A)(C-B)} \int_a^b (x - A)(x - B) \dd x  \\
  \dv{x} \qty[\frac{1}{2}(x-A)(x-B)^2] &= \frac{1}{2}(x - B)^2 + (x-A)(x-B) \\
  \int (x-A)(x-B) \dd x &= \frac{1}{2}(x-A)(x-B)^2 - \frac{1}{2} \int (x-B)^2 \dd x \\
  L(A,B,C,a,b) &= \left. \frac{1}{(C-A)(C-B)} \qty[ \frac{1}{2}(x-A)(x-B)^2 - \frac{1}{6} (x-B)^3] \right|_a^b
\end{align}

\subsection{Interpolating to uniform spacing}

Since Simpon's rule is derived by interpolating a function with a polynomial and integrating, we can use the polynomial to interpolate to the
medpoint of $[a,b]$ and just use the usual formula. Given the function at points $x_1$, $x_2$, and $x_3$, the interpolated function value at $\frac{x_1 + x_2}{2}$ is
\begin{equation}
  f\qty(\frac{x_1 + x_3}{2}) \approx
  f(x_1) l( \frac{x_1+x_2}{2}, x_2,x_3,x_1)
  + f(x_2) l( \frac{x_1+x_2}{2}, x_1,x_3,x_2)
  + f(x_3) l( \frac{x_1+x_2}{2}, x_1,x_2,x_3)
\end{equation}
Once we interpolate to the midpoint, we can use equation \ref{eq:simpsons}.

\end{document}