\documentclass[12pt, answers]{exam}
%\documentclass[12pt]{exam}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{setspace}
\PassOptionsToPackage{hyphens}{url}
\usepackage{tabu}
\usepackage{lscape}
\onehalfspacing
\setlength{\parindent}{0mm} \setlength{\parskip}{1em}

% packages
\RequirePackage{amssymb, amsfonts, amsmath, latexsym, verbatim, xspace, setspace}
\RequirePackage{tikz}
% The float package HAS to load before hyperref
\usepackage{float} % for psuedocode formatting
\usepackage{amsthm}
\usepackage{epsfig}
\usepackage{times}
\renewcommand{\ttdefault}{cmtt}
\usepackage{amsmath}
\usepackage{graphicx} % for graphics files

% for creating indented blocks
\usepackage{scrextend}
\usepackage{paralist, tabularx}

% from Denovo Methods Manual
\usepackage{mathrsfs}
\usepackage[mathcal]{euscript}
\usepackage{color}
\usepackage{array}

\usepackage[pdftex]{hyperref}
\usepackage[parfill]{parskip}
\usepackage{cancel}

\newcommand{\nth}{n\ensuremath{^{\text{th}}} }
\newcommand{\ve}[1]{\ensuremath{\mathbf{#1}}}
\newcommand{\Macro}{\ensuremath{\Sigma}}
\newcommand{\vOmega}{\ensuremath{\hat{\Omega}}}
\newcommand{\cc}[1]{\ensuremath{\overline{#1}}}
\newcommand{\ccm}[1]{\ensuremath{\overline{\mathbf{#1}}}}

%--------------------------------------------------------------------
%--------------------------------------------------------------------
\begin{document}
\begin{center}
{\bf NE 155, Topic 15, S21 \\
2-D Finite Difference/Volume methods\\
April 8, 2021}
\end{center}

\setlength{\unitlength}{1in}
\begin{picture}(6,.1)
\put(0,0) {\line(1,0){6.25}}
\end{picture}

Much of this can be found in Duderstadt and Hamilton, Chp.\ 5 Section II.B.

%-------------------------------------------------------------
\section*{PDEs}

We'll start by considering PDEs in general, and then move on to the Diffusion Equation specifically.

Recall: a partial differential equation is an equation containing an unknown function of two or more variables and its derivatives with respect to those variables.

If the PDE is linear in $u$ and all derivatives of $u$, then we say that the PDE is linear.
%
\begin{equation}
A\frac{\partial^2 u}{\partial x^2} + B\frac{\partial^2 u}{\partial x \partial  y} + C\frac{\partial^2 u}{\partial y^2} + D\frac{\partial u}{\partial x} + E\frac{\partial u}{\partial y} + Fu = G \nonumber
\end{equation}
%
This equation is a \textbf{2nd order} PDE in two variables. It is \textbf{linear} if $A$ through $G$ do not depend on $u$ (they may depend on $x$ and $y$).

%-------------------------------------------------------------
\vspace*{1em}

Recall that we can classify second order PDEs based on the geometric behavior of their solutions.
%
\begin{itemize}
\item Elliptic if $B^2 - 4 AC < 0$.

\item Hyperbolic if $B^2 - 4 AC > 0$

\item Parabolic if $B^2 - 4 AC = 0$
\end{itemize}

%-------------------------------------------------------------
\subsection*{Elliptic Equations}

Recall that the 2-D Laplacian for the function $u(x,y)$ is
%
\ifprintanswers
\begin{equation}
\nabla^2 u(x,y) = \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} = u_{xx} + u_{yy} \:.\nonumber
\end{equation}
\else
\\ \vspace*{3em} \\
\fi

%
The Laplacian is used in many of the equations that are commonly found in physics:
%
\begin{itemize}
\item Laplace's equation
\[\nabla^2 u(x,y) = 0\]

\item Poisson's equation
\[\nabla^2 u(x,y) = g(x,y)\]

\item Helmholtz's equation (recall that we can make the DE look like this)
\[\nabla^2 u(x,y) +f(x,y)u(x,y) = g(x,y)\]
\end{itemize}

% -----------------------------------------------------
\section*{2-D Finite Difference}

We will use 5 points to define our central-differenced Laplacian:

\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}
\draw (0,0)--(0,7);
\draw (1,0)--(1,7);
\draw (2,0)--(2,7);
\draw (3,0)--(3,7);
\draw (4,0)--(4,7);
\draw (5,0)--(5,7);
\draw (6,0)--(6,7);
\draw (7,0)--(7,7);
\node[below] at (0,-.25) {$x_0$};
\node[below] at (1,-.25) {$x_1$};
\node[below] at (3,-.25) {$x_{i-1}$};
\node[below] at (4,-.25) {$x_i$};
\node[below] at (5,-.25) {$x_{i+1}$};
\node[below] at (7,-.25) {$x_n$};
\node at (3.5, 2.5) {$\Delta x_i$};
% begin y
\draw (0,0)--(7,0);
\draw (0,1)--(7,1);
\draw (0,2)--(7,2);
\draw (0,3)--(7,3);
\draw (0,4)--(7,4);
\draw (0,5)--(7,5);
\draw (0,6)--(7,6);
\draw (0,7)--(7,7);
\node[left] at (-.25, 0) {$y_0$};
\node[left] at (-.25,1) {$y_1$};
\node[left] at (-.25,3) {$y_{j-1}$};
\node[left] at (-.25,4) {$y_j$};
\node[left] at (-.25,5) {$y_{j+1}$};
\node[left] at (-.25,7) {$y_m$};
  \node at (2.5,3.5) {$\Delta y_j$};
% labels
\node at (4,4) [circle,fill=black,scale=0.3] {};
\node[below left] at (4,4) {$i,j$};
\node at (5,4) [circle,fill=black,scale=0.3] {};
\node[below right] at (5,4) {$i+1,j$};
\node at (3,4) [circle,fill=black,scale=0.3] {};
\node[above left] at (3,4) {$i-1,j$};
\node at (4,5) [circle,fill=black,scale=0.3] {};
\node[above right] at (4,5) {$i,j+1$};
\node at (4,3) [circle,fill=black,scale=0.3] {};
\node[below right] at (4,3) {$i,j-1$};
\end{tikzpicture}
\end{minipage} \hfill
%
\begin{minipage}{0.5\textwidth}
  \[u(x_i,y_j) = u_{i,j} \qquad u(x_{i+1},y_j) = u_{i+1,j}\]
  \begin{align}
  \frac{\partial^2 u_{i,j}}{\partial x^2} = \frac{\partial}{\partial x}\bigl(\frac{\partial u_{i,j}}{\partial x}\bigr) =
\frac{u_{i-1,j} - 2u_{i,j} + u_{i+1,j}}{\Delta x_i^2} \nonumber \\
%
  \frac{\partial^2 u_{i,j}}{\partial y^2} = \frac{\partial}{\partial y}\bigl(\frac{\partial u_{i,j}}{\partial y}\bigr) =
\frac{u_{i,j-1} - 2u_{i,j} + u_{i,j+1}}{\Delta y_j^2} \nonumber
\end{align}
\end{minipage}

All together this gives
\ifprintanswers
\[\nabla^2 u_{i,j} =
\frac{\partial^2 u_{i,j}}{\partial x^2} + \frac{\partial^2 u_{i,j}}{\partial y^2} =
\frac{u_{i-1,j} - 2u_{i,j} + u_{i+1,j}}{\Delta x_i^2} + \frac{u_{i,j-1} - 2u_{i,j} + u_{i,j+1}}{\Delta y_j^2}\]
%
If $\Delta x_i = $ constant $= \Delta y_j = h$, then
%
\[ \nabla^2 u_{i,j} = \frac{u_{i+1,j} + u_{i-1,j} + u_{i,j+1} + u_{i,j-1} - 4u_{i,j}}{h^2}\]
\else
\vspace*{9em}
\fi

If we apply this to Laplace's equation and have fixed boundary conditions:
%
\begin{align}
u_{i+1,j} &+ u_{i-1,j} + u_{i,j+1} + u_{i,j-1} - 4u_{i,j} = 0, \quad i = 1, 2, \dots, n-1, \quad j = 1, 2, \dots, m-1 \nonumber \\
%
u_{0,j} &= BC_L , \quad j = 1, 2, \dots, m-1 \nonumber \\
u_{i,0} &= BC_B , \quad i = 1, 2, \dots, n-1 \nonumber \\
u_{n,j} &= BC_R , \quad j = 1, 2, \dots, m-1 \nonumber \\
u_{i.m} &= BC_T , \quad i = 1, 2, \dots, n-1 \nonumber
\end{align}
%
Make sure to check how the corners need to be defined.

We could apply this directly the the 2-D diffusion equation.

%--------------------------------------------------------------------
\section*{2-D Finite Volume Method, Diffusion Equation}

Remember that in 1-D we were solving this
\[-\frac{d}{dx}D(x)\frac{d \phi(x)}{dx} + \Sigma_a(x) \phi(x) = S(x)\]
%
with an equilibrium (reflecting) condition at the centerline ($x_0 = 0$) and vacuum on the right ($x_n = a$):
\begin{align}
\frac{d}{dx}\phi(x) \big|_{x=0} &= 0 \qquad \text{zero net current,} \nonumber\\
\phi(\tilde{a}) &= 0 \qquad \tilde{a} = a + 2D \:.\nonumber
\end{align}

We imposed a spatial mesh and said material discontinuities will coincide with the cell edges, $x_i$. Thus, we can assume that the cross sections and the diffusion coefficient are constant in each cell.
%
%\begin{align}
%D(x) &= D_i \qquad \text{for } x_{i-1} \leq x_i \nonumber \\
%\Sigma_{a}(x) &= \Sigma_{a,i} \qquad \text{for } x_{i-1} \leq x_i \nonumber \\
%h_i &\equiv x_i - x_{i-1} \nonumber
%\end{align}
%
The unknown fluxes and known sources are defined at the mesh or cell edges.
%\begin{align}
%\phi(x_i) &= \phi_i \nonumber \\
%S(x_i) &= S_i \nonumber
%\end{align}
%
We then went on to define things for the finite volume method.
%\begin{center}
%\begin{figure}[h!]
%\includegraphics[height=2.5in]{../figs/FVM-DE}
%\end{figure}
%\end{center}

Now, we're going to extend all of that to two dimensions. We'll start with the multi-D equation:
\[-\nabla \cdot \bigl(D(\vec{r})\nabla \phi(\vec{r})\bigr) + \Sigma_a(\vec{r}) \phi(\vec{r}) = S(\vec{r})\:.\]
%
This equation is elliptic:
\begin{itemize}
\item in general, this is the Helmholtz equation.
\item if $\Sigma_a(\vec{r})=0$ and $D(\vec{r})=$ constant, then this takes the form of the Poisson equation.
\item if $\Sigma_a(\vec{r})=0$ and $S(\vec{r})=0$, then this becomes Laplace's equation.
\end{itemize}

In 2-D:
\ifprintanswers
\[-\frac{\partial}{\partial x}D(x,y)\frac{\partial}{\partial x} \phi(x,y) -\frac{\partial}{\partial y}D(x,y)\frac{\partial}{\partial y} \phi(x,y) + \Sigma_a(x,y) \phi(x,y) = S(x,y)\:.\]
\else
\\ \vspace*{2em} \\
\fi
%
For now we're going to say we have fixed boundary conditions:
\[\phi(-a,y) = \Phi_L\:, \quad \phi(a,y) = \Phi_R\:, \quad \phi(x,-b) = \Phi_B\:, \quad \phi(x,b) = \Phi_T\:,\]
with $x \in [-a,a]$ and $y \in [-b,b]$.

% ---------------------------------------------------------
% ---------------------------------------------------------
\subsection*{Finite Volume}
%
%\begin{figure}[h!]
%\begin{center}
%\includegraphics[height=5in]{../figs/2DfvmGrid}
%\end{center}
%\end{figure}

\begin{center}
\begin{tikzpicture}
% grid
\draw[step=2cm] (2,2) grid (6,6);
% volume labels
\node at (5,3) {$V_{i+1,j}$};
\node at (5,5) {$V_{i+1,j+1}$};
\node at (3,3) {$V_{i,j}$};
\node at (3,5) {$V_{i,j+1}$};
\node at (1,7) {$D_{i,j+1}$};
% surface labels
\node[left] at (1.75,3) {$s_1$};
\node[left] at (1.75,5) {$s_8$};
\node[above] at (3,6.25) {$s_7$};
\node[above] at (5,6.25) {$s_6$};
\node[right] at (6.25,5) {$s_5$};
\node[right] at (6.25,3) {$s_4$};
\node[below] at (3,1.75) {$s_2$};
\node[below] at (5,1.75) {$s_3$};
% surrounding grid and markers
\draw plot[mark=*, mark options={fill=black}] (4,4) node[below] {$(i,j)$};
\draw (4,4) -- plot[mark=*, mark options={fill=black}] (8,4) node[right] {$(i+1,j)$};
\draw (4,4)-- plot[mark=*, mark options={fill=black}] (4,0) node[below] {$(i,j-1)$};
\draw (4,4)-- plot[mark=*, mark options={fill=black}] (4,8) node[above] {$(i,j+1)$};
\draw (4,4)-- plot[mark=*, mark options={fill=black}] (0,4) node[above] {$(i-1,j)$};
% arrows
\draw[<->](7.5,4) -- (7.5,8);
\node[right] at (7.5,6) {$\epsilon_{j+1}$};
\draw[<->](7.5,0) -- (7.5,4);
\node[right] at (7.5,2) {$\epsilon_{j}$};
\draw[<->](1,2) -- (1,4);
\node[left] at (1,3) {$\epsilon_{j}/2$};
\draw[<->](4,0.5) -- (8,0.5);
\node[below] at (6, 0.5) {$\delta_{i+1}$};
\draw[<->](0,0.5) -- (4,0.5);
\node[below] at (2, 0.5) {$\delta_{i}$};
\draw[<->](4,7) -- (6,7);
\node[above] at (5, 7) {$\delta_{i+1}/2$};
\end{tikzpicture}
\end{center}

We assume the diffusion coefficient, absorption cross section, and source are constant in each cell (cell-centered), e.g., for $V_{i,j}$:
\begin{align}
D(x,y) &= D_{i,j}\;, \qquad x_{i-1} \leq x \leq x_i \:\text{ and }\: y_{j-1} \leq y \leq y_j \nonumber \\
%
\Sigma_a(x,y) &= \Sigma_{a,i,j}\;, \qquad x_{i-1} \leq x \leq x_i \:\text{ and }\: y_{j-1} \leq y \leq y_j \nonumber \\
%
S(x,y) &= S_{i,j}\;, \qquad x_{i-1} \leq x \leq x_i \:\text{ and }\: y_{j-1} \leq y \leq y_j \nonumber \\
%
\Delta x_i &\equiv \delta_i = x_{i} - x_{i-1} \nonumber \\
\Delta y_j &\equiv \epsilon_j = y_{j} - y_{j-1} \nonumber
\end{align}
And analogously for the other 3 cells.

We further assume that the fluxes are constant over the interval centered around $(x_i, y_j)$ (edge-centered):
%
\ifprintanswers
\[\phi(x,y) = \phi_{i,j} \qquad \text{for } \bigl(x_i - \frac{\delta_i}{2}\bigr) \leq x \leq \bigl(x_i + \frac{\delta_{i+1}}{2}\bigr) \:\text{ and }\:\bigl(y_j - \frac{\epsilon_j}{2}\bigr) \leq x \leq \bigl(y_j + \frac{\epsilon_{j+1}}{2}\bigr) \]
\else
\\ \vspace*{3em}
\fi

Now, we integrate the 2-D equation over 4 rectangular partial-volumes (well, areas, technically): $V = V_{i,j} + V_{i+1,j} + V_{i,j+1} + V_{i+1,j+1}$.
%
\[\int_V d\vec{r}\:\bigl[-\nabla \cdot \bigl(D(\vec{r})\nabla \phi(\vec{r})\bigr) +\Sigma_a(\vec{r}) \phi(\vec{r}) = S(\vec{r}) \bigr]\]

% ---------------------------------------------------------
\subsubsection*{Streaming Term}
Use Gauss Theorem to replace the first volume integral with a surface integral:
%
\ifprintanswers
\begin{align}
-\int_V d\vec{r}\:\bigl[\nabla \cdot \bigl(D(\vec{r})\nabla \phi(\vec{r})\bigr)\bigr] &= -\int_S d\vec{S} \cdot\bigl(D(\vec{r})\nabla \phi(\vec{r})\bigr) \nonumber \\
%
= -\int_S d\vec{S}\: D(\vec{r})\hat{n} \cdot \nabla \phi(\vec{r}) &= -\int_S d\vec{S} \:D(\vec{r})\frac{\partial}{\partial \hat{n}}\phi(\vec{r})\:. \nonumber
\end{align}
\else
\\ \vspace*{4em} \\
\fi
%
Next, we define the partial derivative w.r.t.\ direction on each surface, using $O(h)$ forward and backward difference schemes since they're simple:

\begin{align}
\frac{\partial}{\partial \hat{n}}\phi(\vec{r}) &= \frac{\phi_{i,j-1} - \phi_{i,j}}{\epsilon_j} \qquad \text{on } S_2 \:, S_3 \quad \text{(bottom)} \nonumber \\
%
&= \frac{\phi_{i,j+1} - \phi_{i,j}}{\epsilon_{j+1}} \qquad \text{on } S_7 \:, S_6 \quad \text{(top)} \nonumber \\
%
&= \frac{\phi_{i-1,j} - \phi_{i,j}}{\delta_{i}} \qquad \text{on } S_1 \:, S_8 \quad \text{(left)} \nonumber \\
%
&= \frac{\phi_{i+1,j} - \phi_{i,j}}{\delta_{i+1}} \qquad \text{on } S_4 \:, S_5 \quad \text{(right)} \nonumber
\end{align}
%
We then use the midpoint rule for the integration and integrate along each surface. Recall that the physics values are cell-centered while the flux is edge-centered. E.g., surfaces $S_2$ and $S_3$:
%
\begin{align*}
-\int_{S_2+S_3} d\vec{S} \:D(\vec{r})\frac{\partial}{\partial \hat{n}}\phi(\vec{r}) &= \boxed{\frac{\phi_{i,j} - \phi_{i,j-1}}{\epsilon_{j}} \biggl(\frac{D_{i,j} \delta_{i} + D_{i+1,j} \delta_{i+1}}{2}\biggr)}\:,\\
%
S_6+S_7 &= \boxed{\frac{\phi_{i,j} - \phi_{i,j+1}}{\epsilon_{j+1}} \biggl(\frac{D_{i,j+1} \delta_{i} + D_{i+1,j+1} \delta_{i+1}}{2}\biggr)}\:,\\
%
S_1+S_8 &= \boxed{\frac{\phi_{i,j} - \phi_{i-1,j}}{\delta_{i}} \biggl(\frac{D_{i,j} \epsilon_{j} + D_{i,j+1} \epsilon_{j+1}}{2}\biggr)}\:,\\
%
S_4+S_5 &= \boxed{\frac{\phi_{i,j} - \phi_{i+1,j}}{\delta_{i+1}} \biggl(\frac{D_{i+1,j} \epsilon_{j} + D_{i+1,j+1} \epsilon_{j+1}}{2}\biggr)}\:,
\end{align*}
%
and we do this for each set of surfaces.

% ---------------------------------------------------------
\subsubsection*{Absorption Term}
To integrate absorption, we do four integrals - one over each sub-volume:
%
\ifprintanswers
\begin{align}
\int_{x_i-\frac{\delta_{i}}{2}}^{x_i+\frac{\delta_{i+1}}{2}} dx \int_{y_j-\frac{\epsilon_{j}}{2}}^{y_j+\frac{\epsilon_{j+1}}{2}}dy\:\Sigma_a(x,y) \phi(x,y) &= \Sigma_{a,i,j}\int\int_{V_{i,j}} dx dy \: \phi(x,y) + \nonumber \\
%
\Sigma_{a,i+1,j}\int\int_{V_{i+1,j}} dx dy \: \phi(x,y) &+ \Sigma_{a,i+1,j+1}\int\int_{V_{i+1,j+1}} dx dy \: \phi(x,y) + \nonumber \\
 \Sigma_{a,i,j+1}\int\int_{V_{i,j+1}} dx dy \: \phi(x,y) \:.\nonumber
\end{align}
\else
\\ \vspace*{8em}\\
\fi
%
Again applying the midpoint scheme and using our edge-centered flux definition:
%
\begin{align}
\int \int dx dy\:\Sigma_a(x,y) \phi(x,y) &= \boxed{\phi_{i,j}\bigl(\Sigma_{a,i,j} V_{i,j} + \Sigma_{a,i+1,j} V_{i+1,j} + \Sigma_{a,i+1,j+1} V_{i+1,j+1} + \Sigma_{a,i,j+1} V_{i,j+1} \bigr) } \nonumber \\
&\equiv \phi_{i,j}\Sigma_{a,ij}\:, \nonumber
\end{align}
%
where
\[V_{i,j} = \frac{1}{4}\delta_i \epsilon_j \:, \quad V_{i+1,j} = \frac{1}{4}\delta_{i+1} \epsilon_{j} \:, \quad V_{i+1,j+1} = \frac{1}{4}\delta_{i+1} \epsilon_{j+1} \:, \quad V_{i,j+1} = \frac{1}{4}\delta_{i} \epsilon_{j+1} \:.\]

% ---------------------------------------------------------
\subsubsection*{Source Term}
Using the same procedure for the source, we get:
\begin{align}
\int \int dx dy \: \:S(x,y) &= \boxed{ S_{i,j} V_{i,j} + S_{i+1,j} V_{i+1,j} + S_{i+1,j+1} V_{i+1,j+1} + S_{i,j+1} V_{i,j+1} }\nonumber \\
&\equiv S_{ij}\:. \nonumber
\end{align}

% ---------------------------------------------------------
\subsubsection*{Discretized Equations}
\ifprintanswers
Collecting all of the terms and separating them, we get a 5-point difference equation for $i=1,\dots,n-1$; $j=1,\dots,m-1$:
%
\[a_{i-1,j}^{ij}\phi_{i-1,j} + a_{i+1,j}^{ij}\phi_{i+1,j} + a_{i,j-1}^{ij}\phi_{i,j-1} + a_{i,j+1}^{ij}\phi_{i,j+1} +  a_{i,j}^{ij}\phi_{i,j} = S_{ij} \:.\]
%
\else
\vspace*{3em}
\fi
The lower index is the cell to which you are coupling, and the upper index is which cell you are in--this becomes important when we're ordering our matrix.
%
\begin{align}
a_{i-1,j}^{ij} &= -\frac{D_{i,j} \epsilon_{j} + D_{i,j+1} \epsilon_{j+1}}{2 \delta_{i}}  \nonumber \\
(a_L^{ij} & \quad \text{capturing influence of \textbf{left} flux on center cell}) \nonumber \\
%
a_{i+1,j}^{ij} &= -\frac{D_{i+1,j} \epsilon_{j} + D_{i+1,j+1} \epsilon_{j+1}}{2 \delta_{i+1}}  \nonumber \\
(a_R^{ij} & \quad \text{capturing influence of \textbf{right} flux on center cell}) \nonumber \\
%
a_{i,j-1}^{ij} &= -\frac{D_{i,j} \delta_{i} + D_{i+1,j} \delta_{i+1}}{2 \epsilon_{j}}  \nonumber \\
(a_B^{ij} & \quad \text{capturing influence of \textbf{lower} flux on center cell}) \nonumber \\
%
a_{i,j+1}^{ij} &= -\frac{D_{i,j+1} \delta_{i} + D_{i+1,j+1} \delta_{i+1}}{2 \epsilon_{j+1}}  \nonumber \\
(a_T^{ij} & \quad \text{capturing influence of \textbf{upper} flux on center cell}) \nonumber \\
%
\nonumber \\
a_{i,j}^{ij} &= \Sigma_{a,ij} - \bigl(a_{i-1,j}^{ij} + a_{i+1,j}^{ij} + a_{i,j-1}^{ij} + a_{i,j+1}^{ij} \bigr)
 \:.\nonumber \\
 (a_C^{ij}) & \nonumber
\end{align}

In this formulation we now have $(n+1) \times (m+1)$ unknowns.

%-------------------------------------------------------
\subsection*{Matrix Form}
To write the system in a way that looks like $\ve{A}\vec{x} = \vec{b}$, we need to choose an ordering strategy for how we want to store the points. Let's look at a 3$\times$3 example:

\begin{minipage}{0.5\textwidth}
%-------------- indices ------------------
\begin{tikzpicture}
\draw[step=2cm] (0,0) grid (4,4);
\foreach \y in {1, 2}
    \foreach \x in  {0, 1, 2}
        \node[below left] at (2*\x cm,2*\y cm) {$(\x,\y)$};
\node[below] at (0,-.25) {$(0,0)$};
\node[below] at (2,-.25) {$(1,0)$};
\node[below] at (4,-.25) {$(2,0)$};
\end{tikzpicture}
\end{minipage} \hfill
%-------------- numbered nodes ------------------
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}
\draw[step=2cm] (0,0) grid (4,4);
\node[below] at (0,-.25) {$0$};
\node[below] at (2,-.25) {$1$};
\node[below] at (4,-.25) {$2$};
\node[below left] at (-.25,2) {$3$};
\node[below left] at (2,2) {$4$};
\node[below left] at (4,2) {$5$};
\node[below left] at (-.25,4) {$6$};
\node[below left] at (2,4) {$7$};
\node[below left] at (4,4) {$8$};
\end{tikzpicture}
\end{minipage}

Our solution vector length in this example is 9 (3 $\times$ 3). Our matrix size is therefore going to be 9 $\times$ 9. We can think of this as a 3 $\times$ 3 matrix of 3 $\times$ 3 matrices:
\begin{equation}
\underbrace{\begin{pmatrix}
\begin{pmatrix}
a_{0,0}^{00} & a_{1,0}^{00} & 0 \\
a_{0,0}^{10} & a_{1,0}^{10} & a_{2,0}^{10} \\
0            & a_{1,0}^{20} & a_{2,0}^{20}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,1}^{00} & 0 & 0 \\
0 & a_{1,1}^{10} & 0 \\
0 & 0 & a_{2,1}^{20}
\end{pmatrix}
&
\begin{pmatrix}
 & & \\
 & 0 & \\
 & &
\end{pmatrix} \\
%--------------------
\begin{pmatrix}
a_{0,0}^{01} & 0 & 0 \\
0 & a_{1,0}^{11} & 0 \\
0 & 0 & a_{2,0}^{21}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,1}^{01} & a_{1,1}^{01} & 0 \\
a_{0,1}^{11} & a_{1,1}^{11} & a_{2,1}^{11} \\
0            & a_{1,1}^{21} & a_{2,1}^{21}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,2}^{01} & 0 & 0 \\
0 & a_{1,2}^{11} & 0 \\
0 & 0 & a_{2,2}^{21}
\end{pmatrix} \\
%--------------------
\begin{pmatrix}
 & & \\
 & 0 & \\
 & &
\end{pmatrix} &
\begin{pmatrix}
a_{0,1}^{02} & 0 & 0 \\
0 & a_{1,1}^{12} & 0 \\
0 & 0 & a_{2,1}^{22}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,2}^{02} & a_{1,2}^{02} & 0 \\
a_{0,2}^{12} & a_{1,2}^{12} & a_{2,2}^{12} \\
0            & a_{1,2}^{22} & a_{2,2}^{22}
\end{pmatrix} \\
\end{pmatrix}}_{\ve{A}}
%--------------------
%
\underbrace{\begin{pmatrix} \phi_{0,0} \\ \phi_{1,0} \\ \phi_{2,0} \\ \\ \phi_{0,1} \\ \phi_{1,1} \\ \phi_{2,1} \\ \\ \phi_{0,2}\\ \phi_{1,2} \\  \phi_{2,2} \end{pmatrix}}_{\vec{\phi}} =
%
\underbrace{\begin{pmatrix} S_{00} \\ S_{10} \\ S_{20} \\ \\ S_{01} \\ S_{11} \\ S_{21} \\ \\ S_{02} \\ S_{12} \\  S_{22} \end{pmatrix}}_{\vec{S}} \nonumber
\end{equation}

%
%
Another way to think of $\ve{A}$ is
\begin{equation}
\begin{pmatrix}
\begin{pmatrix}
a_{C}^{00} & a_{R}^{00} & 0 \\
a_{L}^{10} & a_{C}^{10} & a_{R}^{10} \\
0            & a_{L}^{20} & a_{C}^{20}
\end{pmatrix}
&
\begin{pmatrix}
a_{T}^{00} & 0 & 0 \\
0 & a_{T}^{10} & 0 \\
0 & 0 & a_{T}^{20}
\end{pmatrix}
&
\begin{pmatrix}
 & & \\
 & 0 & \\
 & &
\end{pmatrix} \\
%--------------------
\begin{pmatrix}
a_{B}^{01} & 0 & 0 \\
0 & a_{B}^{11} & 0 \\
0 & 0 & a_{B}^{21}
\end{pmatrix}
&
\begin{pmatrix}
a_{C}^{01} & a_{R}^{01} & 0 \\
a_{L}^{11} & a_{C}^{11} & a_{R}^{11} \\
0            & a_{L}^{21} & a_{C}^{21}
\end{pmatrix}
&
\begin{pmatrix}
a_{T}^{01} & 0 & 0 \\
0 & a_{T}^{11} & 0 \\
0 & 0 & a_{T}^{21}
\end{pmatrix} \\
%--------------------
\begin{pmatrix}
 & & \\
 & 0 & \\
 & &
\end{pmatrix} &
\begin{pmatrix}
a_{B}^{02} & 0 & 0 \\
0 & a_{B}^{12} & 0 \\
0 & 0 & a_{B}^{22}
\end{pmatrix}
&
\begin{pmatrix}
a_{C}^{02} & a_{R}^{02} & 0 \\
a_{L}^{12} & a_{C}^{12} & a_{R}^{12} \\
0            & a_{L}^{22} & a_{C}^{22}
\end{pmatrix} \\
\end{pmatrix} \nonumber
\end{equation}

This gives us a 5-banded matrix, which is not so difficult to represent with built in functions in Python or MATLAB. We could still solve this directly with Gaussian elimination or LU decomposition, but the size of the system increases pretty rapidly with mesh size.

Therefore using an iterative method like Jacobi, GS, or SOR is probably a better plan.

%-------------------------------------------------------
\subsection*{Boundary Conditions}

This all works fine for central points, but what about the boundaries? When we're at the edges, we get four entries rather than five because the edge values are known. For corners we have only three entries.

Let's see how this impacts our equations. Recall:
%
\[\phi(-a,y) = \Phi_L\:, \quad \phi(a,y) = \Phi_R\:, \quad \phi(x,-b) = \Phi_B\:, \quad \phi(x,b) = \Phi_T\:.\]
%
Let's choose what to do at the corners, and then define the rest of the boundaries:
%
\ifprintanswers
\begin{align}
\phi_{0,0} = \Phi_B\:, \quad \phi_{n,0} &= \Phi_R\:, \quad \phi_{0,m} = \Phi_L\:, \quad \phi_{n,m} = \Phi_T\:. \nonumber \\
\phi_{0,j} &= \Phi_L \qquad j=1,\dots,m-1 \:, \nonumber \\
\phi_{n,j} &= \Phi_R \qquad j=1,\dots,m-1 \:, \nonumber \\
\phi_{i,0} &= \Phi_B \qquad i=1,\dots,n-1 \:, \nonumber \\
\phi_{i,m} &= \Phi_T \qquad i=1,\dots,n-1 \:. \nonumber
\end{align}
\else
\\ \vspace*{8em}
\fi

Let's look at how this would impact the left ($i=0$) boundary. The $i=0$ equations are simply the boundary condition:
\begin{itemize}
\item Change the $a_{C}^{0,j}$ entries to $1$s,
\item the $a_{x}^{0,j}$, where $x$ is $R, T$, and $B$ to $0$, and
\item the $S_{0,j}$ entries to $\Phi_L$.
\end{itemize}

For the $i=1$ equations:
\[\underbrace{a_{2,j}^{1j}}_{R}\phi_{2,j} + \underbrace{a_{1,j-1}^{1j}}_{B}\phi_{1,j-1} + \underbrace{a_{1,j+1}^{1j}}_{T}\phi_{1,j+1} + \underbrace{a_{1,j}^{1j}}_{C}\phi_{1,j} = S_{1j} - \underbrace{a_{0,j}^{1j}}_{L}\phi_L \]

And analogously for the rest of the edges.

\subsection*{Larger Matrix}
What about a bigger matrix?

\begin{minipage}{0.5\textwidth}
%-------------- indices ------------------
\begin{tikzpicture}
\draw[step=2cm] (0,0) grid (6,6);
\foreach \y in {1, 2, 3}
    \foreach \x in  {0, 1, 2, 3}
        \node[below left] at (2*\x cm,2*\y cm) {$(\x,\y)$};
\node[below] at (0,-.25) {$(0,0)$};
\node[below] at (2,-.25) {$(1,0)$};
\node[below] at (4,-.25) {$(2,0)$};
\node[below] at (6,-.25) {$(3,0)$};
\end{tikzpicture}
\end{minipage} \hfill
%-------------- numbered nodes ------------------
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}
\draw[step=2cm] (0,0) grid (6,6);
\node[below] at (0,-.25) {$0$};
\node[below] at (2,-.25) {$1$};
\node[below] at (4,-.25) {$2$};
\node[below] at (6,-.25) {$3$};
\node[below left] at (-.25,2) {$4$};
\node[below left] at (2,2) {$5$};
\node[below left] at (4,2) {$6$};
\node[below left] at (6,2) {$7$};
\node[below left] at (-.25,4) {$8$};
\node[below left] at (2,4) {$9$};
\node[below left] at (4,4) {$10$};
\node[below left] at (6,4) {$11$};
\node[below left] at (-.25,6) {$12$};
\node[below left] at (2,6) {$13$};
\node[below left] at (4,6) {$14$};
\node[below left] at (6,6) {$15$};
\end{tikzpicture}
\end{minipage}

Our solution vector length in this example is 16 (4 $\times$ 4). Our matrix size is therefore going to be 16 $\times$ 16. We can think of this as a 4 $\times$ 4 matrix of 4 $\times$ 4 matrices:
\begin{equation}
\underbrace{\begin{pmatrix}
\begin{pmatrix}
a_{0,0}^{00} & a_{1,0}^{00} & 0            & 0\\
a_{0,0}^{10} & a_{1,0}^{10} & a_{2,0}^{10} & 0 \\
0            & a_{1,0}^{20} & a_{2,0}^{20} & a_{3,0}^{20} \\
0            & 0            & a_{2,0}^{30} & a_{3,0}^{30}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,1}^{00} & 0 & 0 & 0 \\
0 & a_{1,1}^{10} & 0 & 0 \\
0 & 0 & a_{2,1}^{20} & 0 \\
0 & 0 & 0 & a_{3,1}^{30}  \\
\end{pmatrix}
&
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}
&
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}\\
%--------------------
\begin{pmatrix}
a_{0,0}^{01} & 0 & 0 & 0\\
0 & a_{1,0}^{11} & 0 & 0\\
0 & 0 & a_{2,0}^{21} & 0\\
0 & 0 & 0 & a_{3,0}^{31}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,1}^{01} & a_{1,1}^{01} & 0            & 0\\
a_{0,1}^{11} & a_{1,1}^{11} & a_{2,1}^{11} & 0\\
0            & a_{1,1}^{21} & a_{2,1}^{21} & a_{3,1}^{21} \\
0            & )            & a_{2,1}^{31} & a_{3,1}^{31}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,2}^{01} & 0 & 0 & 0\\
0 & a_{1,2}^{11} & 0 & 0\\
0 & 0 & a_{2,2}^{21} & 0\\
0 & 0  & 0 & a_{3,2}^{31}
\end{pmatrix}
&
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}\\
%--------------------
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}
&
\begin{pmatrix}
a_{0,1}^{02} & 0 & 0 & 0\\
0 & a_{1,1}^{12} & 0 & 0\\
0 & 0 & a_{2,1}^{22} & 0\\
0 & 0  & 0 & a_{3,1}^{32}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,2}^{02} & a_{1,2}^{02} & 0            & 0\\
a_{0,2}^{12} & a_{1,2}^{12} & a_{2,2}^{12} & 0\\
0            & a_{1,2}^{22} & a_{2,2}^{22} & a_{3,2}^{22}\\
0            & 0            & a_{2,2}^{32} & a_{3,2}^{32}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,3}^{02} & 0 & 0 & 0\\
0 & a_{1,3}^{12} & 0 & 0\\
0 & 0 & a_{2,3}^{22} & 0\\
0 & 0  & 0 & a_{3,3}^{32}
\end{pmatrix} \\
%--------------------
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}
&
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}
&
\begin{pmatrix}
a_{0,2}^{03} & 0 & 0 & 0\\
0 & a_{1,2}^{13} & 0 & 0\\
0 & 0 & a_{2,2}^{23} & 0\\
0 & 0  & 0 & a_{3,2}^{33}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,3}^{03} & a_{1,3}^{03} & 0            & 0\\
a_{0,3}^{13} & a_{1,3}^{13} & a_{2,3}^{13} & 0\\
0            & a_{1,3}^{23} & a_{2,3}^{23} & a_{3,3}^{23}\\
0            & 0            & a_{2,3}^{33} & a_{3,3}^{33}
\end{pmatrix}
\end{pmatrix}}_{\ve{A}} \nonumber
\end{equation}
%--------------------
%
\begin{equation}
\underbrace{\begin{pmatrix}
\phi_{0,0} \\ \phi_{1,0} \\ \phi_{2,0} \\ \phi_{3,0} \\ \\
\phi_{0,1} \\ \phi_{1,1} \\ \phi_{2,1} \\ \phi_{3,1} \\ \\
\phi_{0,2} \\ \phi_{1,2} \\ \phi_{2,2} \\ \phi_{3,2} \\ \\
\phi_{0,3} \\ \phi_{1,3} \\ \phi_{2,3} \\ \phi_{3,3} \end{pmatrix}}_{\vec{\phi}} =
%
\underbrace{\begin{pmatrix}
S_{00} \\ S_{10} \\ S_{20} \\ S_{30} \\ \\
S_{01} \\ S_{11} \\ S_{21} \\ S_{31} \\ \\
S_{02} \\ S_{12} \\ S_{22} \\ S_{32} \\ \\
S_{03} \\ S_{13} \\ S_{23} \\ S_{33}
\end{pmatrix}}_{\vec{S}} \nonumber
\end{equation}

\begin{minipage}{0.5\textwidth}
%-------------- indices ------------------
\begin{tikzpicture}
\draw[step=2cm] (0,0) grid (6,6);
\foreach \y in {1}
    \foreach \x in  {0, 1}
        \node[below left] at (2*\x cm,2*\y cm) {$(\x,\y)$};
\node[below] at (0,-.25) {$(0,0)$};
\node[below] at (2,-.25) {$(1,0)$};
\node[below] at (4,-.25) {$...$};
\node[below] at (6,-.25) {$(n,0)$};
\node[below left] at (0,4) {$\vdots$};
\node[below left] at (0,6) {$(0,m)$};
\node[below left] at (2,6) {$(1,m)$};
\node[below left] at (4,6) {$(n-1,m)$};
\node[below left] at (6,6) {$(n,m)$};
\node[below left] at (6,2) {$(n,1)$};
\node[below left] at (6,4) {$(n,m-1)$};
\node[below left] at (6,6) {$(n,m)$};
\end{tikzpicture}
\end{minipage} \hfill
%-------------- numbered nodes ------------------
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}
\draw[step=2cm] (0,0) grid (6,6);
\node[below] at (0,-.25) {$0$};
\node[below] at (2,-.25) {$1$};
\node[below] at (4,-.25) {$2$};
\node[below] at (6,-.25) {$3$};
\node[below left] at (-.25,2) {$4$};
\node[below left] at (2,2) {$5$};
\node[below left] at (4,2) {$6$};
\node[below left] at (6,2) {$7$};
\node[below left] at (-.25,4) {$8$};
\node[below left] at (2,4) {$9$};
\node[below left] at (4,4) {$10$};
\node[below left] at (6,4) {$11$};
\node[below left] at (-.25,6) {$12$};
\node[below left] at (2,6) {$13$};
\node[below left] at (4,6) {$14$};
\node[below left] at (6,6) {$15$};
\end{tikzpicture}
\end{minipage}

Our solution vector length in this example is $1 \times nm$. Our matrix size is therefore going to be $n m \times n m$. We can think of this as a $n \times m$ matrix of $n \times m$ matrices: ($n$ rows; $m$ columns)

\begin{landscape}
\begin{equation}
\underbrace{\begin{pmatrix}
\begin{pmatrix}
a_{0,0}^{00} & a_{1,0}^{00} & 0            & 0\\
a_{0,0}^{10} & a_{1,0}^{10} & a_{2,0}^{10} & 0 \\
0            & a_{1,0}^{20} & a_{2,0}^{20} & a_{n,0}^{20} \\
0            & 0            & a_{2,0}^{n0} & a_{n,0}^{n0}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,1}^{00} & 0 & 0 & 0 \\
0 & a_{1,1}^{10} & 0 & 0 \\
0 & 0 & a_{2,1}^{20} & 0 \\
0 & 0 & 0 & a_{n,1}^{n0}  \\
\end{pmatrix}
&
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}
&
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}\\
%--------------------
\begin{pmatrix}
a_{0,0}^{01} & 0 & 0 & 0\\
0 & a_{1,0}^{11} & 0 & 0\\
0 & 0 & a_{2,0}^{21} & 0\\
0 & 0 & 0 & a_{n,0}^{n1}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,1}^{01} & a_{1,1}^{01} & 0            & 0\\
a_{0,1}^{11} & a_{1,1}^{11} & a_{2,1}^{11} & 0\\
0            & a_{1,1}^{21} & a_{2,1}^{21} & a_{n,1}^{21} \\
0            & 0            & a_{2,1}^{n1} & a_{n,1}^{n1}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,2}^{01} & 0 & 0 & 0\\
0 & a_{1,2}^{11} & 0 & 0\\
0 & 0 & a_{2,2}^{21} & 0\\
0 & 0 & 0 & a_{n,2}^{n1}
\end{pmatrix}
&
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}\\
%--------------------
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}
&
\begin{pmatrix}
a_{0,1}^{02} & 0 & 0 & 0\\
0 & a_{1,1}^{12} & 0 & 0\\
0 & 0 & a_{2,1}^{22} & 0\\
0 & 0 & 0 & a_{n,1}^{n2}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,2}^{02} & a_{1,2}^{02} & 0            & 0\\
a_{0,2}^{12} & a_{1,2}^{12} & a_{2,2}^{12} & 0\\
0            & a_{1,2}^{22} & a_{2,2}^{22} & a_{n,2}^{22}\\
0            & 0            & a_{2,2}^{n2} & a_{n,2}^{n2}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,m}^{02} & 0 & 0 & 0\\
0 & a_{1,m}^{12} & 0 & 0\\
0 & 0 & a_{2,m}^{22} & 0\\
0 & 0 & 0 & a_{n,m}^{n2}
\end{pmatrix} \\
%--------------------
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}
&
\begin{pmatrix}
 & & & \\
 & 0 & &\\
 & & & \\
 & & &
\end{pmatrix}
&
\begin{pmatrix}
a_{0,2}^{0m} & 0 & 0 & 0\\
0 & a_{1,2}^{1m} & 0 & 0\\
0 & 0 & a_{2,2}^{2m} & 0\\
0 & 0 & 0 & a_{n,2}^{nm}
\end{pmatrix}
&
\begin{pmatrix}
a_{0,m}^{0m} & a_{1,m}^{0m} & 0            & 0\\
a_{0,m}^{1m} & a_{1,m}^{1m} & a_{2,m}^{1m} & 0\\
0            & a_{1,m}^{2m} & a_{2,m}^{2m} & a_{n,m}^{2m}\\
0            & 0            & a_{2,m}^{nm} & a_{n,m}^{nm}
\end{pmatrix}
\end{pmatrix}}_{\ve{A}} \nonumber
\end{equation}
\end{landscape}
%--------------------
%
\begin{equation}
\underbrace{\begin{pmatrix}
\phi_{0,0} \\ \phi_{1,0} \\ \phi_{n-1,0} \\ \phi_{n,0} \\ \\
\phi_{0,1} \\ \phi_{1,1} \\ \phi_{n-1,1} \\ \phi_{n,1} \\ \\
\phi_{0,m-1} \\ \phi_{1,m-1} \\ \phi_{n-1,m-1} \\ \phi_{n,m-1} \\ \\
\phi_{0,m} \\ \phi_{1,m} \\ \phi_{n-1,m} \\ \phi_{n,m} \end{pmatrix}}_{\vec{\phi}} =
%
\underbrace{\begin{pmatrix}
S_{00} \\ S_{10} \\ S_{(n-1)0} \\ S_{n0} \\ \\
S_{01} \\ S_{11} \\ S_{(n-1)1} \\ S_{n1} \\ \\
S_{0(m-1)} \\ S_{1(m-1)} \\ S_{(n-1)(m-1)} \\ S_{n(m-1)} \\ \\
S_{0m} \\ S_{13} \\ S_{(n-1)m} \\ S_{nm}
\end{pmatrix}}_{\vec{S}} \nonumber
\end{equation}

%--------------------------------------------------------------------
%--------------------------------------------------------------------
%\bibliographystyle{plain}
%\bibliography{LinearSolns}

\end{document}


\section*{Conclusion}

In this work we described three approaches to parallelize the FW algorithm with three different architectures:
distributed with MPI, shared-memory multiprocessing with OpenMP and GPGPU with CUDA.

The fastest "pure" implementation is \emph{CUDA FW} thanks to the high computation capability and high memory bandwidth,
but it requires more expensive hardware.

\emph{MPI FW} (with one thread per node)  is still faster than the \emph{serial}, but the implementation
is more complex, the cost of the cluster (hosting and maintenance) makes the solution non convenient,
the efficiency depends on the network bandwidth and the speedup is not that high.

\emph{OpenMP FW} is almost 95 times faster than \emph{serial FW} but 13 times slower than \emph{CUDA FW}. The absence of
overhead due to communication, fast memory access, easy development process and relatively low costs make this solution the
most affordable, maintenable and cost-efficient one.

Talking about hybrid solutions, \emph{MPI + CUDA} is obviously faster than \emph{MPI + OpenMP} as long as the matrix is not small,
but the benefits may not justify the total cost of the infrastructure: the monthly cost for hosting a server with a GPU is at least
four times the cost of one without a GPU. This solution is suggested to those systems that really need the lowest response time possible
(\emph{e.g.} real-time systems or systems that cannot rely on a caching mechanism in front of them).


\documentclass[11pt]{article}
\usepackage{geometry}
\geometry{a4paper,top=2cm,bottom=2cm,left=2cm,right=2cm}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lineno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage {tikz}
\usetikzlibrary {positioning}
\usepackage {xcolor}
\usepackage{titlesec}
\usepackage{varwidth}

\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother

\title{\textbf{Algorithm Design - Homework 1} \\ \bigskip \large \textbf{Sapienza University of Rome}}
\date{\textbf{\today}}
\author{\textbf{Marco Costa, 1691388}}
\pagestyle{fancy}
\fancyhead[L]{Marco Costa, 1691388}
\fancyhead[R]{Algorithm Design - Homework 1}

%section, subsection: space - left, before, after
\titlespacing{\section}{0em}{0em}{0em}
\titlespacing{\subsection}{0em}{0.5em}{0em}
\titlespacing{\subsubsection}{0em}{0.5em}{0em}
\setlength\parindent{0pt}

\begin{document}
\maketitle
\newpage

\section*{Exercise 1}
\subsection*{Problem}
The problem consists in finding the expected optimal reward playing the game ``\textit{Open the Boxes and keep the Best!}''. The input is composed by the number of boxes $k$, the number of different rewards $n$ an
the cost $c_i$ of every box. Two algorithms are required. The first one's complexity must be \textbf{\textit{O}}($n^2 \cdot k$), while the second one's complexity must be \textbf{\textit{O}}($n \cdot k$)
\subsubsection*{Solution}
In order to solve the problem, we can define a matrix \textit{M} composed of $k$ rows and $n$ columns, where the element $M[i, j]$ represents the expected value by opening the box i and having as current maximum reward j. \\
To populate the matrix we can use \textbf{backward induction}, proceeding first considering the last box and choosing what to do for all the possible rewards. Using this information, we can then determine what to do at the penultimate box. This process continues backwards until we have determined the best action for every possible reward for each box. So the element $\mathbf{M[0, 0]}$ is the expected optimal reward.\\
Let's explain the mathematical formula: \\
- $j \cdot \frac{j+1}{n+1}$ (or $M[i+1, j] \cdot \frac{j+1}{n+1}$) is the probability of obtaining a reward $r \le j$; \\
- $\frac{1}{n+1}\sum\limits_{h = j + 1}^n{h}$ (or $\frac{1}{n+1}\sum\limits_{h = j + 1}^n{M[i+1, j]}$) is the probability of obtaining a reward $r > j$; \\
- $c[i]$ is the cost to pay opening the $i^{th}$ box. \\
- the sum of the previous values is the expected value opening the box $i$ having as current maximum reward $j$ \\
To improve the complexity to \textbf{\textit{O}}($n \cdot k$) we can eliminate the summations, since in the worst case we have a sum over $n$ (\textbf{\textit{O}}($n$)) in nested cycles (\textbf{\textit{O}}($n \cdot k$)) having a total cost of\textbf{\textit{O}}($n^2 \cdot k$). To do this we must distinguish the two cases:
\begin{itemize}
	\item \textbf{\textit{Last box}}: we can remove this summation using a mathematical trick: \\
	$\sum\limits_{i = j + 1}^n{i} = \sum\limits_{i = 0}^n{i} - \sum\limits_{i = 0}^j{i} = \frac{n \cdot (n+1)}{2} - \frac{j \cdot (j+1)}{2} = \frac{n \cdot (n+1) - j \cdot (j+1)}{2}$;
	\item \textbf{\textit{Other boxes}}: we can use an auxiliary vector in which we keep track of the sum of the elements of the matrix related to the box next to the current one.
\end{itemize}

Here there are the two \textbf{\textit{Algorithms}}:

\begin{minipage}[t]{0.49\textwidth}
\begin{algorithm}[H]
	\caption{Get optimal expected value (\textbf{\textit{O}}($n^2 \cdot k$))}\label{euclid}
	\begin{algorithmic}[1]
		\State $M[k, n+1] \gets 0$
		\For{$i$ in $(k-1, ..., 0)$}
		\For{$j$ in $(n, ..., 0)$}
		\State $r \gets 0$
		\If{$i = k-1$}
		\State $r \gets j \cdot \frac{j+1}{n+1} + \frac{1}{n+1}\sum\limits_{h = j + 1}^n{h} - c[i]$
		\Else
		\State \begin{varwidth}[t]{\linewidth} $r \gets M[i+1, j] \cdot \frac{j+1}{n+1} + \frac{1}{n+1} \cdot$ \par
			\hskip\algorithmicindent $\sum\limits_{h = j + 1}^n{M[i+1, h]} - c[i]$
		\end{varwidth}
		\EndIf
		\State $M[i, j] \gets \max(j, r)$
		\EndFor
		\EndFor
		\State \Return $M[0, 0]$
	\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}[t]{0.49\textwidth}
\begin{algorithm}[H]
	\caption{Get optimal expected value (\textbf{\textit{O}}($n \cdot k$))}\label{euclid}
	\begin{algorithmic}[1]
		\State $M[k, n+1] \gets 0$
		\State $sums[n+1] \gets 0$
		\For{$i$ in $(k-1, ..., 0)$}
		\For{$j$ in $(n, ..., 0)$}
		\State $r \gets 0$
		\If{$i = k-1$}
			\State $r \gets j \cdot \frac{j+1}{n+1} + \frac{1}{n+1} \cdot \frac{n \cdot (n+1)-j \cdot (j+1)}{2} - c[i]$
		\Else
			\State $r \gets M[i+1, j] \cdot \frac{j+1}{n+1} + \frac{sums[j]}{n+1} - c[i]$
		\EndIf
		\State $M[i, j] \gets \max(j, r)$
		\If{$j = n$}
			\State $sums[j] \gets 0$
		\Else
			\State $sums[j] \gets sums[j+1] + M[i, j+1]$
		\EndIf
		\EndFor
		\EndFor
		\State \Return $M[0, 0]$
	\end{algorithmic}
\end{algorithm}
\end{minipage}
\newpage

\section*{Exercise 2}
\subsection*{First problem}
The problem is to find the complete graph \textbf{\textit{G}} of minimum weight given a weighted tree \textbf{\textit{T}}, such that  \textbf{\textit{T}} is the unique minimum spanning tree of \textbf{\textit{G}}. Algorithm's run time must be polynomial in $n$.
\subsubsection*{Solution}
Insert edges that are not in the tree so as to obtain the complete graph. These edges must have a greater weight than those of the tree, so that \textbf{\textit{T}} is the only \textbf{\textit{MST}} of \textbf{\textit{G}}. Since \textit{Kruskal}'s algorithm uses the \textit{Union-Find} structures for representing the cuts, we use this structures to solve the problem. \\
Let's define with \textbf{\textit{V}} the set of nodes of \textbf{\textit{T}} and with \textbf{\textit{E}} the set of edges of \textbf{\textit{T}}.
\begin{algorithm}
	\caption{Find complete graph}\label{euclid}
	\begin{algorithmic}[1]
		\For{$v \in V$} \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad (\textbf{\textit{O}}($n$))
			\State $v.initializeUnionFindSingleton()$
		\EndFor
		\State $T.sortEdgesByAscendingWeights()$ \qquad \qquad \qquad \qquad \qquad \qquad \qquad (\textbf{\textit{O}}($n\log{n}$))
		\State $G \gets \emptyset$
		\For {$e \gets (u, v) \in E$} \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad (\textbf{\textit{O}}($n^3$))
			\State  $G.addEdge(e)$
			\State  $set_1 \gets u.findComponents()$
			\State  $set_2 \gets v.findComponents()$
			\For {$u \in set_1$}
				\For {$v \in set_2$}
					\State $\hat{e} \gets (u, v)$
					\If {$\hat{e} \notin G$}
						\State $\hat{e}.setWeight(e.getWeight() + 1)$
						\State $G.addEdge(\hat{e})$
					\EndIf
				\EndFor
			\EndFor
			\State $union(set_1, set_2)$
		\EndFor
		\State \Return $G$
	\end{algorithmic}
\end{algorithm} \\
\textbf{Cost}: \textbf{\textit{O}}($|V|\log{|V|} + |E| \cdot |V|^2$) = \textbf{\textit{O}}($n\log{n} + (n-1) \cdot n^2$) = \textbf{\textit{O}}($n\log{n} + n^3 - n^2$) = \textbf{\textit{O}}($n^3$), given by the three nested cycles over $n$.
\subsection*{Second problem}
Find the total weight of the complete graph \textbf{\textit{G}} of minimum weight given a weighted tree \textbf{\textit{T}}, such that  \textbf{\textit{T}} is the unique minimum spanning tree of \textbf{\textit{G}}. Algorithm's complexity must be \textbf{\textit{O}}($n \log{n}$).
\subsubsection*{Solution}
This problem is quite similar to the previous one, but in this case there is no need to create all the edges of the graph.
\begin{algorithm}
	\caption{Find weight of the complete graph}\label{euclid}
	\begin{algorithmic}[1]
		\For{$v \in V$} \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad (\textbf{\textit{O}}($n$))
			\State $v.initializeUnionFindSingleton()$
		\EndFor
		\State $T.sortEdgesByAscendingWeights()$ \qquad \qquad \qquad \qquad \qquad \qquad \qquad (\textbf{\textit{O}}($n\log{n}$))
		\State $w_{total} \gets 0$
		\For {$e \gets (u, v) \in E$} \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad (\textbf{\textit{O}}($n \log{n}$))
			\State $w_{total}$ \textit{+=} $e.getWeight()$
			\State  $set_1 \gets u.findComponents()$
			\State  $set_2 \gets v.findComponents()$
			\State $w_{total}$ \textit{+=} $(set_1.size() \times set_2.size() - 1) \times (e.getWeight() + 1)$
			\State $union(set_1, set_2)$
		\EndFor
		\State \Return $w_{total}$
	\end{algorithmic}
\end{algorithm} \\
\textbf{Cost}: \textbf{\textit{O}}($|V|\log{|V|} + |E| \log{|V|}$) = \textbf{\textit{O}}($n\log{n} + n\log{n}$) = \textbf{\textit{O}}($n\log{n}$) (\textit{union} costs \textbf{\textit{O}}($\log{n}$)).
\newpage

\section*{Exercise 3}
\subsection*{First Problem}
The problem consists in modeling Federico's business as a flow problem in a graph \textbf{\textit{G}}, only consisting of regular vertices, one source, one sink, and capacitated edges to find out how many chocolates he should make every week. An example with $|F| = 4$ is required.
\subsubsection*{Solution}
The model consists in a source node \textit{F} that represents Federico, a sink node \textit{S} that represents the costumers and different nodes $f_i$ representing Federico's friends. Moreover, for each friend there is a node $w_i$ that represents the friend's ``warehouse''. These nodes help us better understand that the amount of total chocolates received by a friend is exactly $n_i$. Each friend can receive the chocolate from Federico (represented with an edge of path from Federico to the friend and capacity $n_i$) or from another friend (represented with an edge of path from the new friend to the first one and capacity $n_i - s_i$). Notice that when a friend meets another, they can exchange chocolates for each other (represented with two edges: the first one has the path from the first friend to the warehouse of the second one and capacity $n_{i1} - s_{i1}$, while the second one has the path from the second friend to the first one and capacity $n_{i2} - s_{i2}$). The chocolates sold by each friend is represented with an edge having the path from the friend to the costumers and capacity $s_i$. Notice that for each friend $s_i \le n_i$ and the total amount of chocolates sold is $\sum\limits_{i \in |F|}s_i$. It's possible to find the \textit{Maximum Flow} in order to find out how many chocolates Federico should
actually make every week. Let's show the example with $|F| = 4$:

\begin {tikzpicture}
\begin{scope}[auto=left,every node/.style={circle,draw, minimum width = 1 cm}]
\node(f) at (0,0) {F};
\node(wa) at (3,1) {w$_a$};
\node(a) at (6.5,1) {f$_a$};
\node(wb) at (3,-1) {w$_b$};
\node(b) at (6.5,-1) {f$_b$};
\node(wc) at (9.5,1) {w$_c$};
\node(c) at (13,1) {f$_c$};
\node(wd) at (9.5,-1) {w$_d$};
\node(d) at (13,-1) {f$_d$};
\node(s) at (16,0) {s};
\end{scope}
\begin{scope}[every edge/.style={draw=black,very thick}, every node/.style={scale=0.8}]
\path [->] (f) edge node[sloped,above]{$n_1$} (wa);
\path [->] (f) edge node[sloped,above]{$n_2$} (wb);

\path [->] (a) edge node[sloped,below]{$n_a - s_a$} (wc);
\path [->] (b) edge node[sloped,above]{$n_b - s_b$} (wd);
\path [->] (c) edge[bend right=20] node[sloped,above]{$n_c - s_c$} (wa);
\path [->] (d) edge[bend left=20] node[sloped,below]{$n_d - s_d$} (wb);

\path [->] (a) edge[sloped,above,pos=0.75] node{$n_a - s_a$} (wb);
\path [->] (d) edge[sloped,above,pos=0.2] node{$n_d - s_d$} (wc);
\path [->] (b) edge[sloped,above,pos=0.2] node{$n_b - s_b$} (wa);
\path [->] (c) edge[sloped,above,pos=0.75] node{$n_c - s_c$} (wd);

\path [->] (wa) edge node[sloped,above]{$n_a$}(a);
\path [->] (wb) edge node[sloped,above]{$n_b$}(b);
\path [->] (wc) edge node[sloped,above]{$n_c$}(c);
\path [->] (wd) edge node[sloped,above]{$n_d$}(d);

\path [->] (a) edge[bend left=30] node[sloped,above]{$s_a$} (s);
\path [->] (b) edge[bend right=30] node[sloped,below]{$s_b$} (s);
\path [->] (c) edge node[sloped,above]{$s_c$} (s);
\path [->] (d) edge node[sloped,above]{$s_d$} (s);
\end{scope}
\end{tikzpicture}
\subsection*{Second Problem}
Adjust the network knowing that each friend will have an associated building $b_f \in B$ and find out if and how this
impacts Federico’s business.
\subsubsection*{Solution}
In this case we must modify a bit the previous model adding some new nodes $b_i$ that represent the buildings. Now each friend can sell chocolates only in his associated building, so we have the edges with capacity $s_i$ with path from the friend to his associated building, and another edge with capacity $c_i$ with path from the building to the costumers. The main difference is that now the total amount of chocolate sold is $\sum\limits_{i \in B}c_i$, and we have that $\sum\limits_{i \in |B|}c_i \le \sum\limits_{i \in |F|}s_i$. It means that Federico could make less chocolates than before because of the possible drop of sales.
Let's show the adjusted example:

\begin {tikzpicture}
\begin{scope}[auto=left,every node/.style={circle,draw, minimum width = 1 cm}]
	\node(f) at (0,0) {F};
	\node(ma) at (2,1) {m$_a$};
	\node(a) at (5.8,1) {f$_a$};
	\node(mb) at (2,-1) {m$_b$};
	\node(b) at (5.8,-1) {f$_b$};
	\node(mc) at (8.2,1) {m$_c$};
	\node(c) at (12,1) {f$_c$};
	\node(md) at (8.2,-1) {m$_d$};
	\node(d) at (12,-1) {f$_d$};
	\node(b1) at (14,2) {$b_1$};
	\node(b2) at (14,0) {$b_2$};
	\node(b3) at (14,-2) {$b_3$};
	\node(s) at (16,0) {s};
\end{scope}
\begin{scope}[every edge/.style={draw=black,very thick}, every node/.style={scale=0.8}]
	\path [->] (f) edge node[sloped,above]{$n_1$} (ma);
	\path [->] (f) edge node[sloped,above]{$n_2$} (mb);

	\path [->] (a) edge node[sloped,below]{$n_a - s_a$} (mc);
	\path [->] (b) edge node[sloped,above]{$n_b - s_b$} (md);
	\path [->] (c) edge[bend right=20] node[sloped,above]{$n_c - s_c$} (ma);
	\path [->] (d) edge[bend left=20] node[sloped,below]{$n_d - s_d$} (mb);

	\path [->] (a) edge[sloped,above,pos=0.75] node{$n_a - s_a$} (mb);
	\path [->] (d) edge[sloped,above,pos=0.2] node{$n_d - s_d$} (mc);
	\path [->] (b) edge[sloped,above,pos=0.2] node{$n_b - s_b$} (ma);
	\path [->] (c) edge[sloped,above,pos=0.75] node{$n_c - s_c$} (md);

	\path [->] (ma) edge node[sloped,above]{$n_a$}(a);
	\path [->] (mb) edge node[sloped,above]{$n_b$}(b);
	\path [->] (mc) edge node[sloped,above]{$n_c$}(c);
	\path [->] (md) edge node[sloped,above]{$n_d$}(d);

	\path [->] (a) edge[bend left=10] node[sloped,above]{$s_a$} (b1);
	\path [->] (b) edge[bend right=10] node[sloped,below]{$s_b$} (b3);
	\path [->] (c) edge node[sloped,above]{$s_c$} (b1);
	\path [->] (d) edge node[sloped,above]{$s_d$} (b2);

	\path [->] (b1) edge node[sloped,above]{$c_1$} (s);
	\path [->] (b2) edge node[sloped,above]{$c_2$} (s);
	\path [->] (b3) edge node[sloped,above]{$c_3$} (s);
\end{scope}
\end{tikzpicture}
\newpage

\section*{Exercise 4}
\subsection*{Problem}
The problem consists in showing that it is not possible to solve the problem of scheduling $n$ tasks with quick algorithm. Each job  $j$ of the $n$ jobs has an earliest time $s_j$ to start task, a deadline $d_j$ when it has to be finished, and the length $l_j \in \mathbb{N}$ that specifies the time needed to complete it. There is also an upper bound time $k$ and $\sum\limits_{j \in J}l_j \le k$.
\subsubsection*{Solution}
In order to prove that this problem is not solvable with quick algorithm we need to prove that it is \textbf{\textit{NP-Hard}}. We can do it reducing another \textit{NP-Hard} problem to the current problem. Let's define our problem as $\Theta$, we need to find a well known \textit{NP-Hard} problem $\Omega$ such that:
\begin{itemize}
	\item $\omega \in \Omega \implies  \theta \in \Theta$
	\item $\theta \in \Theta \implies  \omega \in \Omega$ (or equivalently $\neg\omega \in \Omega \implies  \neg\theta \in \Theta$)
\end{itemize}
\textbf{\underline{Observation}}: The earliest start time  $s_j$ indicate only at what time the job $j$ is available (it does not need to be done at that moment, but it does have to be done before its deadline $d_j$). \\ \\
\textbf{\underline{Observation}}: Our scheduling problem is solvable if and only if each job $j$ meets its deadline $d_j$ and $\sum\limits_{j \in J}l_j \le k$ (we know that this last is satisfied). \\ \\
We can use \textbf{\textit{Subset Sum}} for our purpose ($\Omega$ = \textit{Subset Sum}). \\
\textbf{Subset sum}: Given a set of positive integers and an integer $k$, is there any non-empty subset whose sum to $k$.
\begin{enumerate}
	\item Prove that $\omega \in \Omega \implies  \theta \in \Theta$: \\
	Let's suppose we start with a solvable instance of \textit{Subset Sum} Problem. Given $X = \{x_1, ..., x_n\}$ a set of positive integers to which there is a subset $X'$ such that its elements add up to $k$ and the sum of the whole set is $\lambda$ ($\sum\limits_{x_i \in X'}x_i = k$ and $\sum\limits_{x_i \in X}x_i = \lambda$). Let's define jobs $\{j_1, ..., j_n\}$ such that $s_i = 0$, $l_i = x_i$ and $d_i = \lambda + 1$ for every $j_i$ (earliest start time, duration of the job and deadline respectively). This instance solves the scheduling problem because it's possible to arrange the jobs in any order and they will always meet their deadline.

	\item Prove that $\theta \in \Theta \implies  \omega \in \Omega$: \\
	Let's suppose we start with a solvable instance of our \textit{Scheduling} problem. Given the set of jobs $\{j_1, ..., j_n, j_{n+1}\}$ where the first $n$ jobs are defined the same as before and job $j_{n+1}$ having $s_{n+1} = k$, $l_{n+1} = 1$ and $d_{n+1} = k+1$. The extra job must be done in $[k, k+1]$, but there would still be $\lambda$ units of time available in the time interval $[0, \lambda+1]$. Since this instance is solvable, we have $|X'|$ jobs that can be executed before the job $j_{n+1}$ and the remaining jobs after the job $j_{n+1}$. The set $X'$ solves the \textit{Subset Sum} problem.
\end{enumerate}
We proved that our scheduling problem is \textit{NP-Hard}, so we can say that it is not solvable with a quick algorithm.

\end{document}


\usetikzlibrary{backgrounds,calc}

\begin{document}
	\chapter{Probability}
	\section{Introduction}
	Let an event be denoted by $A$. The probability that event $A$ occurs is denoted by P$(A)$ and is given by \[\Pr(A) = \frac{\text{no. of ways in which } A \text{ can occur}}{\text{total no. of outcomes}}\]

	Also note that the probability of event $A$ not happening is defined by $1-\Pr(A)$ and is denoted by $\Pr(A^c)$.

	\begin{example}
		A letter is chosen at random from the world `CALCULUS'. Find the probability that it is:

		\quad \textbf{a) } a `C'.

		\quad \textbf{b) } a vowel.
	\end{example}

\begin{example}
	A card is chosen at random from a pack of 52 playing cards. Find the probability that the card is:

	\quad \textbf{a) } an ace.

	\quad \textbf{b) } black.

	\quad \textbf{c) } a heart.

	\quad \textbf{d) } a royal card.
\end{example}
	\section{Using Permutations and Combinations}

	In the following problem, the number of successful outcomes and the total number of outcomes are calculated using the counting techniques in the previous chapter.

	\begin{example}
		A team of 6 children is chosen at random from a class of 10 girls and 9 boys. Find the probability thattge selected team contains:

		\quad \textbf{a) } girls only.

		\quad \textbf{b) } boys only.

		\quad \textbf{c) } more girls than boys.

		\quad \textbf{d) } the oldest 5 children in the class.

	\end{example}
	\section{Bernoulli Trials}
	A Binomial Experiment is an experiment which satisfies the following 4 conditions:
	\begin{itemize}
		\item {A fixed number of trials.}
		\item {Each trial is independent of the others.}
		\item {There are only \textbf{two} outcomes.}
		\item {The probability of each outcome remains constant from trial to trial.}
	\end{itemize}
	\section{Probability Space Diagrams and Tree Diagrams.}
	Tree diagrams and possibility spaces are simple graphical tools which help us calculate probabilities. Possibility space diagrams are particularly useful when the problem involves independent events.
	\section{Venn Diagrams}
	Venn diagrams ilustrate sets of objects or items and set operations. Consider for instance the sets $M_2$, $M_3$ and $M_5$ which stand for multiples of 2, 3 and 5 respectively. The \textbf{universal} set $U$ is the set of all integers between 1 and 30. For convenience, let us consider the set $P$ to be the set of all primes between 1 and 30.

	\begin{tikzpicture}[venncircle/.style={draw, circle, minimum size=15em, align=center}, node distance=12.5em, framed]
		\node[venncircle] (circle1) {$M_5$};
		\node[venncircle, right of=circle1] (circle2) {$M_3$};
		\node (MN) at ($(circle1)!0.5!(circle2)$){9};
		\node[venncircle, below of=MN, yshift=3em] (circle3) {$M_2$}; %yshift value by pythagoras
		\node (ML)  at ($(circle1)!0.4!(circle3)$){6};
		\node (ML)  at ($(circle1)!0.5!(circle3)$){12};
		\node (MLa)  at ($(circle1)!0.6!(circle3)$){18};
		\node (NL)  at ($(circle2)!0.5!(circle3)$){4};
		\node (MNL)  at ($(MN)!0.3!(circle3)$){2};
		\node (Lleft) [below of=ML, yshift=5em] {16};
		\node (Lright) [below of=NL, yshift=5em] {21};
		\node (outbotrightnum) [right of=circle3, yshift=1.5em, xshift=-2em] {11};
		\node (outtoprightnum) [above right of=circle2, yshift=-2.5em, xshift=-1em] {13};
		\node (outbotleftnum) [below left of=circle3, yshift=4em, xshift=-4em]{12};
		\node (outtopleftnum) [left of=circle3, yshift=1.5em]{23};
		\node (U)[above left of=circle1, xshift=8em, yshift=-3em]{5};
		\node (M)[above of=circle1, yshift=-4em]{\textbf{\textit{M}}};
		\node (N)[above of=circle2, yshift=-4em]{\textbf{\textit{N}}};
		\node (L)[below right of=circle3, yshift=2.5em, xshift=-2.5em]{\textbf{\textit{L}}};
	\end{tikzpicture}
\begin{itemize}
	\item{The intersection between sets $M_2$ and $M_3$ is denoted by $M_2 \cap M_3$ and hence $M_2 \cap M_3 = \set{6,12,18,25,30}$ and $M_2 \cap M_3 \cap M_5 = \set{30}$.}

	\item{The union between the sets $M_3$ and $M_5$ is denoted by $M_3 \cup M_5$ and hence $M_3 \cup M_5 = \set{3,5,6,7,10,12,15,18,20,21,24,25,27,30}$.}

	\item{We already know that the set that is formed by the members of the universal set which are not in the set $M_2$ is called the complement of the set $M_2$ denoted by $M_2^c$. Hence, $M_2^c = \set{1,3,5,7,9,11,13,15,17,19,21,23,25,27,29}$.}
\end{itemize}

We already know that the set that is formed by the members of the universal set which are not in the set $M_2$ is called the complement of the set $M_2$ denoted by $M_2^C$

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Theoretical Background}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Transformers}

Vaswani et al\cite{vaswani2017attention} described transformers as sequence
models that solely focus on self-attention without the need for recurrence which
eliminates the need for unfolding during the backpropagation phase of learning.
In the paper, attention was defined with respect to keys, values, and queries.
The attention is computed with

\[
    attention(K,Q,V) = \left(\frac{QK^T}{\sqrt{dim(K)}}\right)V
\]

where K is the key matrix, Q is the query matrix, and V is the value matrix.
The dot product of Q and K is scaled by the square root of the dimension of K.

Transformer models take the whole input as a whole instead of recurrently meaning
that the model does not know the order of the words in the sequence. Hence, the
paper proposed the use of positional encodings through sinusoidal functions
added to the embedded vectors. Suppose that W is a matrix where each column
corresponds to a position pos and each row i corresponds to the individual
dimensions in the model which alters the frequency. Let
\begin{math}
    W=10000^2i/embedsize
\end{math}
where embedsize is a hyperparameter which is also the embedding size of the
embedded vectors. Then, the positional encoding is calculated by
\[
    POS(pos,i) = \sin\left(\frac{pos}{W}\right) \text{if \textit{i} is even and}
\]
\[
    POS(pos,i) = \cos\left(\frac{pos}{W}\right) \text{if \textit{i} is odd}
\]
The key component of transformers is the multi-headed attention layer, wherein
attention is computed multiple times and concatenated together. Transformers
were able to outperform established models for machine translation with
English-German translation.

\section{RoBERTa for Classification}
RoBERTa\cite{liu2019roberta} is a replication study of the original BERT
model by finer-tuning hyperparameters and removing the Next Sentence
Prediction task which was shown that it does not negatively affect the
performance of the model. While the original transformer by Vaswani et al.\
is a Seq2Seq transformer, RoBERTa is an autoencoder transformer trained on a
large corpus, which can be used with fine-tuning or transfer learning for
different downstream tasks such as classification\cite{pritzkau2021nlytics}.

In this paper, the researchers will use the CodeBERT\cite{feng2020codebert}
to be used with transfer learning on algorithm classification. The CodeBERT
model is a variant of RoBERTa pretrained on multiple programming languages
including Java, Python, and Javascript.

\subsection{Model Architecture}

The CodeBERT model is a bidirectional transformer using a similar architecture
with RoBERTa without any architectural modification.

\subsection{Dataset}

CodeBERT was trained on a large corpus of about 8million codes of both bimodal
and unimodal data. Bimodal data means that for each code snippet,
there is an accompanying natural language snippet while unimodal data
implies the absence of the natural language snippet. The data were gathered from
GitHub, which was collected by Husain et al\cite{husain2020codesearchnet}.

\section{Task-Constraint Feedback}

Knowledge About Task-Constraints (KTC) feedback systems employ the use of limiting
the submission by adding requirements, called \textit{constraints}, that will tell the
student if they haven’t completed the requirement.\cite{keuning2016towards} One of the methods used
is \textit{Hints on Task Requirements} (TR) wherein a hint will be given when a task was
not completed. As an example, suppose that the problem setter asked to balance a
binary search tree using red-black trees. However, the submitter was able to
complete the problem using an AVL tree. The TR system should give some feedback
that the Red-Black Tree is a requirement for the given problem.

\section{Algorithm Classification}
Algorithms and data structure can be written multiple ways with different stylistic
and data structure choices. The researchers define algorithm classification as to
what algorithm some code snippet is implementing, rather than the class such as
sorting, searching, etc. Introductory algorithm textbooks\cite{velivckovic2021clrs}\cite{skiena2020algorithm}\cite{sedgewick2011algorithms}
have a good resource on the algorithm names through its table of contents which will
be used as labels in the classifier. With this, this research defines algorithm
classification by tagging code snippets as to the question “what is the algorithm
name that this code snippet is implementing?”

In computer science education, students might use multiple algorithms into one file
and begin using different data structures for their implementations. As an example,
consider the task of implementing a \textit{priority queue} (the \textit{priority queue} is a classification).
The priority queue data structure can be implemented with \textit{binary heaps} or dictionaries
such as \textit{linked lists} and \textit{binary search trees}; in this example, assume that the priority
queue is implemented with a \textit{binary heap}. Introductory programming students might usually
be coding these algorithms and algorithms manually into one file and it is not enough to
say that the submission implements a \textit{priority queue} since a \textit{binary heap} is also implemented.

Suppose that the code snippet implements an algorithm and uses some data structure or
another algorithm using the language’s standard library, then the snippet will only be
classified using the manual implementation disregarding the standard library function.
Likewise, code snippets that do not belong to any algorithms stated in any of the
introductory algorithm textbooks are said not to use any algorithm. These code snippets
usually contain the \textit{main} function (but not always), setter and getter functions,
and boilerplate codes.


\chapter{central force motion solutions}
\begin{abox}
	Practice set 1 solutions
	\end{abox}
\begin{enumerate}
		\item The acceleration due to gravity $(g)$ on the surface of Earth is approximately $2.6$ times that on the surface of Mars. Given that the radius of Mars is about one half the radius of Earth, the ratio of the escape velocity on Earth to that on Mars is approximately
		{\exyear{NET JUNE 2011}}
	\begin{tasks}(2)
		\task[\textbf{A.}] $1.1$
		\task[\textbf{B.}]$1.3$
		\task[\textbf{C.}]$2.3$
		\task[\textbf{D.}]$5.2$
	\end{tasks}
\begin{answer}
\begin{align*}
	\text { Escape velocity }&=\sqrt{2 g R}\\
\frac{\text { Escape velocity of Earth }}{\text { Escape velocity of Mass }}&=\sqrt{\frac{g_{e} R_{e}}{g_{m} R_{m}}}=2.3 \quad \text { where } \frac{R_{e}}{R_{m}}=2 \text { and } \frac{g_{e}}{g_{m}}=2.6
\end{align*}
	THe correct option is \textbf{(c)}
\end{answer}
	\item Two particles of identical mass move in circular orbits under a central potential $V(r)=\frac{1}{2} k r^{2}$. Let $l_{1}$ and $l_{2}$ be the angular momenta and $r_{1}, r_{2}$ be the radii of the orbits respectively. If $\frac{l_{1}}{l_{2}}=2$, the value of $\frac{r_{1}}{r_{2}}$ is:
	{\exyear{NET DEC 2011}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\sqrt{2}$
	\task[\textbf{B.}]$1 / \sqrt{2}$
	\task[\textbf{C.}] 2
	\task[\textbf{D.}] $1 / 2$
\end{tasks}
\begin{answer}
	\begin{align*}
	 V_{e f f}&=\frac{l^{2}}{2 m r^{2}}+\frac{1}{2} k r^{2}, \text{where $l$ is angular momentum. }\\
	\intertext{Condition for circular orbit} \frac{\partial V_{e f f}}{\partial r}&=0 \Rightarrow-\frac{l^{2}}{m r^{3}}+k r=0 \Rightarrow l^{2} \propto r^{4} \Rightarrow l \propto r^{2}.\\
	Thus \frac{l_{1}}{l_{2}}&=\left(\frac{r_{1}}{r_{2}}\right)^{2} \Rightarrow \frac{r_{1}}{r_{2}}=\sqrt{\frac{l_{1}}{l_{2}}} \Rightarrow \frac{r_{1}}{r_{2}}=\sqrt{2}\\
	since \frac{l_{1}}{l_{2}}&=2
	\end{align*}
	The correct option is \textbf{(a)}
\end{answer}
	\item A planet of mass $m$ moves in the inverse square central force field of the Sun of mass $M$. If the semi-major and semi-minor axes of the orbit are $a$ and $b$, respectively, the total energy of the planet is:
	{\exyear{NET DEC 2011}}
\begin{tasks}(2)
	\task[\textbf{A.}] $-\frac{G M m}{a+b}$
	\task[\textbf{B.}]$-G M m\left(\frac{1}{a}+\frac{1}{b}\right)$
	\task[\textbf{C.}]$-\frac{G M m}{a}\left(\frac{1}{b}-\frac{1}{a}\right)$
	\task[\textbf{D.}]$-G M m\left(\frac{a-b}{(a+b)^{2}}\right)$
\end{tasks}
\begin{answer}
 Assume Sun is at the centre of elliptical orbit. Conservation of energy\\
  $$\frac{1}{2} m v_{1}^{2}-\frac{G M m}{a}=\frac{1}{2} m v_{2}^{2}-\frac{G M m}{b}$$ Conservation of momentum $L=m v_{1} a=m v_{2} b$\\
  \begin{figure}[H]
  	\centering
  	\includegraphics[height=3cm,width=5cm]{diagram-20210926(12)-crop}
  \end{figure}
 \begin{align*}
 	&v_{2}=v_{1}\left(\frac{a}{b}\right) \\
 	&\frac{1}{2} m v_{1}^{2}-\frac{1}{2} m v_{2}^{2}=\frac{G M m}{a}-\frac{G M m}{b} \Rightarrow \frac{1}{2} m\left(v_{1}^{2}-v_{1}^{2} \frac{a^{2}}{b^{2}}\right)=G M m\left(\frac{b-a}{a b}\right) \\
 	&\frac{1}{2} m v_{1}^{2}\left(\frac{b^{2}-a^{2}}{b^{2}}\right)=G M m\left(\frac{b-a}{a b}\right) \Rightarrow \frac{1}{2} m v_{1}^{2}=G M m\left(\frac{b}{a}\right) \cdot \frac{1}{(b+a)} \\
 	&E=\frac{1}{2} m v_{1}^{2}-\frac{G M m}{a}=G M m \frac{b}{a} \frac{1}{(b+a)}-\frac{G M m}{a} \\
 	&=\frac{G M m}{a}\left(\frac{b}{(b+a)}-1\right)=\frac{G M m}{a}\left(\frac{b-b-a}{(b+a)}\right)=-\frac{G M m}{(b+a)}
 \end{align*}
 The correct option is \textbf{(a)}
\end{answer}

	\item A planet of mass $m$ moves in the gravitational field of the Sun (mass $M$ ). If the semimajor and semi-minor axes of the orbit are $a$ and $b$ respectively, the angular momentum of the planet is
	{\exyear{NET DEC 2012}}

\begin{tasks}(2)
	\task[\textbf{A.}]$\sqrt{2 G M m^{2}(a+b)}$
	\task[\textbf{B.}]$\sqrt{2 G M m^{2}(a-b)}$
	\task[\textbf{C.}]$\sqrt{\frac{2 G M m^{2} a b}{a-b}}$
	\task[\textbf{D.}]$\sqrt{\frac{2 G M m^{2} a b}{a+b}}$
\end{tasks}
\begin{answer}
	 Assume Sun is at the centre of elliptical orbit.\\\\
	Conservation of energy $\frac{1}{2} m v_{1}^{2}-\frac{G M m}{a}=\frac{1}{2} m v_{2}^{2}-\frac{G M m}{b}$\\\\
	Conservation of momentum $L=m v_{1} a=m v_{2} b$
	$$
	v_{2}=v_{1}\left(\frac{a}{b}\right)
	$$
	\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(12)-crop}
	\end{figure}
	\begin{align*}
		&\frac{1}{2} m v_{1}^{2}-\frac{1}{2} m v_{2}^{2}=\frac{G M m}{a}-\frac{G M m}{b} \Rightarrow \frac{1}{2} m\left(v_{1}^{2}-v_{1}^{2} \frac{a^{2}}{b^{2}}\right)=G M m\left(\frac{b-a}{a b}\right) \\
		&\frac{1}{2} m v_{1}^{2}\left(\frac{b^{2}-a^{2}}{b^{2}}\right)=G M m\left(\frac{b-a}{a b}\right) \Rightarrow \frac{1}{2} m v_{1}^{2}=G M m\left(\frac{b}{a}\right) \cdot \frac{1}{(b+a)} \\
		&v_{1}=\sqrt{2 G M\left(\frac{b}{a}\right) \cdot \frac{1}{(b+a)}} \\
		&L=m v_{1} a=m \sqrt{2 G M\left(\frac{b}{a}\right) \cdot\left(\frac{1}{b+a}\right)} \cdot a=m \sqrt{\frac{2 G M a b}{(b+a)}} \Rightarrow L=\sqrt{\frac{2 G M m^{2} a b}{a+b}}
	\end{align*}
	The correct option is \textbf{(d)}
\end{answer}
	\item A planet of mass $m$ and an angular momentum $L$ moves in a circular orbit in a potential, $V(r)=-k / r$, where $k$ is a constant. If it is slightly perturbed radially, the angular frequency of radial oscillations is
	{\exyear{NET JUNE 2013}}
\begin{tasks}(2)
	\task[\textbf{A.}] $m k^{2} / \sqrt{2} L^{3}$
	\task[\textbf{B.}]$m k^{2} / L^{3}$
	\task[\textbf{C.}]$\sqrt{2} m k^{2} / L^{3}$
	\task[\textbf{D.}]$\sqrt{3} m k^{2} / L^{3}$
\end{tasks}
\begin{answer}$\left. \right. $\\
	\begin{minipage}{0.5\textwidth}
	\begin{align*}
	V_{e f f}&=\frac{L^{2}}{2 m r^{2}}-\frac{k}{r} \\
	\intertext{For circular orbit} \frac{\partial V_{e f f}}{\partial r}&=-\frac{L^{2}}{m r^{3}}+\frac{k}{r^{2}}=0 \\
	\Rightarrow \frac{L^{2}}{m r^{3}}&=\frac{k}{r^{2}} \\
	\text{Thus} r&=r_{0}=\frac{L^{2}}{m k} \Rightarrow \omega=\sqrt{\frac{k}{m}},
	\end{align*}
	\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{figure}[H]
	\centering
	\includegraphics[height=4cm,width=5cm]{diagram-20210926(17)-crop}
\end{figure}
\end{minipage}
 \begin{align*}
 k&=\left.\frac{d^{2} V_{e f f}}{d r^{2}}\right|_{r=r_{0}}=+\frac{3 L^{2}}{m r^{4}}-\left.\frac{2 k}{r^{3}}\right|_{r=r_{0}}=\frac{3 L^{2}}{m\left(\frac{L^{2}}{m k}\right)^{4}}-\frac{2 k}{\left(\frac{L^{2}}{m k}\right)^{3}}=\frac{3 m^{3} k^{4}}{L^{6}}-\frac{2 m^{3} k^{4}}{L^{6}}=\frac{m^{3} k^{4}}{L^{6}}\\
 \omega&=\sqrt{\frac{\left.\frac{d^{2} V}{d r^{2}}\right|_{r=r_{0}}}{m}} \Rightarrow \omega=\frac{m k^{2}}{L^{3}}
 \end{align*}
 The correct option is \textbf{(b)}
\end{answer}

\item The radius of Earth is approximately $6400 \mathrm{~km}$. The height $h$ at which the acceleration due to Earth's gravity differs from $g$ at the Earth's surface by approximately $1 \%$ is
	{\exyear{NET DEC 2014}}
\begin{tasks}(2)
	\task[\textbf{A.}] $64 \mathrm{~km}$
	\task[\textbf{B.}] $48 \mathrm{~km}$
	\task[\textbf{C.}]$32 \mathrm{~km}$
	\task[\textbf{D.}]$16 \mathrm{~km}$
\end{tasks}
\begin{answer}
$\frac{g}{g^{\prime}}=1+\frac{2 h}{R} \Rightarrow \frac{g}{g^{\prime}}-1=\frac{2 h}{R} \Rightarrow \frac{\Delta g}{g^{\prime}}=\frac{2 h}{R} \Rightarrow h=32 k \cdot m$\\
The correct option is \textbf{(c)}
\end{answer}

	\item The probe Mangalyaan was sent recently to explore the planet Mars. The inter-planetary part of the trajectory is approximately a half-ellipse with the Earth (at the time of launch),Sun and Mars (at the time the probe reaches the destination) forming the major axis. Assuming that the orbits of Earth and Mars are approximately circular with radii $R_{E}$ and $R_{M}$, respectively, the velocity (with respect to the Sun) of the probe during its voyage when it is at a distance
		\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(22)-crop(1)}
	\end{figure}
	 $r\left(R_{E}<<r<<R_{M}\right) \text { from the Sun, neglecting the effect of Earth and Mars, is }$
	{\exyear{NET DEC 2014}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\sqrt{2 G M \frac{\left(R_{E}+R_{M}\right)}{r\left(R_{E}+R_{M}-r\right)}}$
	\task[\textbf{B.}]$\sqrt{2 G M \frac{\left(R_{E}+R_{M}-r\right)}{r\left(R_{E}+R_{M}\right)}}$
	\task[\textbf{C.}]$\sqrt{2 G M \frac{R_{E}}{r R_{M}}}$
	\task[\textbf{D.}]$\sqrt{\frac{2 G M}{r}}$
\end{tasks}
\begin{answer}
	$\text { Total energy } E=-K / 2 a \text { where } 2 a \text { major axis and } 2 a=R_{E}+R_{M} \text {. }$
	$$\frac{1}{2} m v^{2}-\frac{G M m}{r}=-\frac{G M m}{\left(R_{E}+R_{M}\right)} \Rightarrow v=\sqrt{2 G M \frac{\left(R_{E}+R_{M}-r\right)}{r\left(R_{E}+R_{M}\right)}}$$
	The correct option is \textbf{(b)}
\end{answer}
	\item After a perfectly elastic collision of two identical balls, one of which was initially at rest, the velocities of both the balls are non zero. The angle $\theta$ between the final, velocities (in the lab frame) is
	{\exyear{NET DEC 2016}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\theta=\frac{\pi}{2}$
	\task[\textbf{B.}]$\theta=\pi$
	\task[\textbf{C.}]$0<\theta \leq \frac{\pi}{2}$
	\task[\textbf{D.}] $\frac{\pi}{2}<\theta \leq \pi$
\end{tasks}
\begin{answer}
 Angle between two particle $\theta_{1}+\theta_{2}=0$
Conservation of momentum
\begin{align*}
&m u=m v_{1} \cos \theta_{1}+m v_{2} \cos \theta_{2} \\
&0=m v_{1} \sin \theta_{1}-m v_{2} \sin \theta_{2}
\intertext{conservation of kinetic energy }
&\frac{1}{2} m u^{2}=\frac{1}{2} m v_{1}^{2}+\frac{1}{2} m v_{2}^{2}\\
	&u^{2}=v_{1}^{2}+v_{2}^{2}+2 v_{1} v_{2}\left(\cos \theta_{1} \cos \theta_{2}-\sin \theta_{1} \sin \theta_{2}\right) \\
	&u^{2}=v_{1}^{2}+v_{2}^{2}+2 v_{1} v_{2} \cos \left(\theta_{1}+\theta_{2}\right) \\
	&u^{2}=v_{1}^{2}+v_{2}^{2} \\
	&v_{1}^{2}+v_{2}^{2}=v_{1}^{2}+v_{2}^{2}+2 v_{1} v_{2} \cos \left(\theta_{1}+\theta_{2}\right) \\
	&\cos \left(\theta_{1}+\theta_{2}\right)=0 \\
	&\theta_{1}+\theta_{2}=\frac{\pi}{2} \Rightarrow \theta=\frac{\pi}{2}
\end{align*}
The correct option is \textbf{(a)}
\end{answer}
	\item Consider circular orbits in a central force potential $V(r)=-\frac{k}{r^{n}}$, where $k>0$ and $0<n<2$. If the time period of a circular orbit of radius $R$ is $T_{1}$ and that of radius $2 R$ is $T_{2}$, then $\frac{T_{2}}{T_{1}}$
	{\exyear{NET DEC 2016}}
\begin{tasks}(2)
	\task[\textbf{A.}] $2^{\frac{n}{2}}$
	\task[\textbf{B.}]$2^{\frac{2}{3} n}$
	\task[\textbf{C.}]$2^{\frac{n}{2}+1}$
	\task[\textbf{D.}]$2^{n}$
\end{tasks}
\begin{answer}
	\begin{align*}
		&V_{e f f}=\frac{J^{2}}{2 m r^{2}}-\frac{k}{r^{n}}, \frac{\partial V_{e f f}}{\partial r}=-\frac{J^{2}}{m r^{3}}+\frac{n k}{r^{n+1}}=0\\
		&\because J=m r^{2} \omega \Rightarrow \frac{m^{2} \omega^{2} r^{4}}{r^{3}}=\frac{n k}{r^{n+1}} \Rightarrow \omega^{2} \propto \frac{1}{r^{n+2}} \Rightarrow \omega \propto r^{-(n+2) / 2} \Rightarrow T \propto r^{\frac{n}{2}+1} \\
		&\frac{T_{2}}{T_{1}}=\left(\frac{2 R}{R}\right)^{\frac{n+2}{2}}=2^{\frac{n}{2}+1}
	\end{align*}
	The correct option is \textbf{(c)}
\end{answer}
	\item A ball weighing $100 \mathrm{gm}$, released from a height of $5 \mathrm{~m}$, bounces perfectly elastically off a plate. The collision time between the ball and the plate is $0.5 \mathrm{~s}$. The average force on the plate is approximately
{	\exyear{NET JUNE 2017}}
\begin{tasks}(2)
	\task[\textbf{A.}] $3 N$
	\task[\textbf{B.}]$2 N$
	\task[\textbf{C.}]$5 N$
	\task[\textbf{D.}]$4 N$
\end{tasks}
\begin{answer}
\begin{align*}
m&=\frac{100}{1000}=0.1 \mathrm{~kg}\\
m g h&=\frac{1}{2} m v^{2} \\
v&=\sqrt{2 g h} \\
v & =10 \mathrm{~m} / \mathrm{sec}
\intertext{change in momentum during collision}
 (m v)-(-m v)&=2 k . g m / \mathrm{sec}\\
f&=\frac{\Delta P}{\Delta t}=\frac{2}{0.5}=4 N
\end{align*}
The correct option is \textbf{(d)}
\end{answer}
	\item Which of the following figures best describes the trajectory of a particle moving in a repulsive central potential $V(r)=\frac{a}{r}(a>0$ is a constant)?
	{\exyear{NET JUNE 2018}}
\begin{tasks}(2)
	\task[\textbf{A.}]\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(47)-crop}
	\end{figure}
	\task[\textbf{B.}]\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(48)-crop}
	\end{figure}
	\task[\textbf{C.}]\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(49)-crop}
	\end{figure}
	\task[\textbf{D.}]\begin{figure}[H]
		\centering
		\includegraphics[height=3cm,width=5cm]{diagram-20210926(50)-crop}
	\end{figure}
\end{tasks}
\begin{answer}
\begin{minipage}{0.5\textwidth}
	 The potential is $V(r)=\frac{a}{r}$ which is repulsive. So there is unbounded motion and mainly represent by scattering project
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{figure}[H]
	\centering
	\includegraphics[height=3cm,width=5cm]{diagram-20210926(51)-crop}
\end{figure}
\end{minipage}\\
The correct option is \textbf{(c)}
\end{answer}

	\item A particle of mass $m$ moves in a central potential $V(r)=-\frac{k}{r}$ in an elliptic orbit $r(\theta)=\frac{a\left(1-e^{2}\right)}{1+e \cos \theta}$, where $0 \leq \theta<2 \pi$ and $a$ and $e$ denote the semi-major axis and eccentricity, respectively. If its total energy is $E=-\frac{k}{2 a}$, the maximum kinetic energy is
	{\exyear{NET JUNE 2018}}
\begin{tasks}(2)
	\task[\textbf{A.}] $E\left(1-e^{2}\right)$
	\task[\textbf{B.}]$E \frac{(e+1)}{(e-1)}$
	\task[\textbf{C.}]$E /\left(1-e^{2}\right)$
	\task[\textbf{D.}]$E \frac{(e-1)}{(e+1)}$
\end{tasks}
\begin{answer}

\begin{align*}
 &E=T+V \quad T=E-V\\
&T=-\frac{k}{2 a}+\frac{k}{r} T=-\frac{k}{2 a}+\frac{k}{a\left(1-e^{2}\right)}(1+\cos \theta)
&\intertext{T is maximum when }
&\cos \theta=1\\
&T_{\max }=-\frac{k}{2 a}+\frac{k(1+e)}{a\left(1-e^{2}\right)}=-\frac{k}{2 a}+\frac{k}{a} \frac{(1+e)}{(1-e)(1+e)} \\
&=-\frac{k}{a}\left[\frac{1}{2}+\frac{1}{(1-e)}\right]=-\frac{k}{2 a}\left(\frac{1+e}{1-e}\right)=-E\left(\frac{1+e}{1-e}\right)
\end{align*}
The correct option is \textbf{(b)}
\end{answer}

	\item In the attractive Kepler problem described by the central potential $V(r)=\frac{-k}{r}($ where $k$ is a positive constant), a particle of mass $m$ with a non-zero angular momentum can never reach the centre due to the centrifugal barrier. If we modify the potential to
	$$
	V(r)=-\frac{k}{r}-\frac{\beta}{r^{3}}
	$$
	one finds that there is a critical value of the angular momentum $\ell_{c}$ below which there is no centrifugal barrier. This value of $\ell_{c}$ is
	{\exyear{NET DEC 2018}}

\begin{tasks}(2)
	\task[\textbf{A.}] $\left[12 \mathrm{~km}^{2} \beta\right]^{1 / 2}$
	\task[\textbf{B.}]$\left[12 \mathrm{~km}^{2} \beta\right]^{-1 / 2}$
	\task[\textbf{C.}]$\left[12 \mathrm{~km}^{2} \beta\right]^{1 / 4}$
	\task[\textbf{D.}]$\left[12 \mathrm{~km}^{2} \beta\right]^{-1 / 4}$
\end{tasks}
\begin{answer}
	\begin{align*}
		&V_{e f f}=\frac{L^{2}}{2 m r^{2}}-\frac{k}{r}=0 \Rightarrow-\frac{L^{2}}{m r^{3}}+\frac{k}{r^{2}}=0 \Rightarrow r_{0}=\frac{L^{2}}{m k}\\
	\intertext{when introduce new potential}
	&V_{e f f}=\frac{L^{2}}{2 m r^{2}}-\frac{k}{r}-\frac{\beta}{r^{3}}
	\\
	\intertext{For critical value}
	&\frac{\partial V_{e f f}}{\partial r}=\frac{-L^{2}}{m r^{3}}+\frac{k}{r^{2}}+\frac{3 \beta}{r^{4}} \\
	&\frac{\partial^{2} V_{e f f}}{\partial r^{2}}=\frac{+3 L^{2}}{m r^{4}} \frac{-2 k}{r^{3}}-\frac{12 \beta}{r^{5}} \geq 0\\
	\intertext{ For critical value }
	&=\frac{3 L^{2}}{m\left(\frac{L^{2}}{m k}\right)^{4}}-\frac{2 k}{\left(\frac{L^{2}}{m k}\right)^{3}}-\frac{12 \beta}{\left(\frac{L^{2}}{m k}\right)^{5}}=0=\frac{3 m^{3} k^{4}}{L^{6}}-\frac{2 m^{3} x^{4}}{L^{6}}-\frac{12 m^{5} x^{5} \beta}{L^{10}}=0 \\
	&L_{C}=\left(12 m^{2} k \beta\right)^{1 / 4} \frac{m^{3} k^{4}}{L^{6}}\left(3-2-12 \frac{m^{2} k \beta}{L^{4}}\right)=0 \Rightarrow L_{c}=\left(12 m^{2} k \beta\right)^{1 / 4}
	\end{align*}
	The correct option is \textbf{(c)}
\end{answer}
\end{enumerate}

\newpage
\begin{abox}
	Practice set 2 solutions
	\end{abox}
\begin{enumerate}
	\item In a central force field, the trajectory of a particle of mass $m$ and angular momentum $L$ in plane polar coordinates is given by,\\
	$$\frac{1}{r}=\frac{m}{l^{2}}(1+\varepsilon \cos \theta)$$
	where, $\varepsilon$ is the eccentricity of the particle's motion. Which one of the following choice for $\varepsilon$ gives rise to a parabolic trajectory?
	{\exyear{GATE 2012}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\varepsilon=0$
	\task[\textbf{B.}]$\varepsilon=1$
	\task[\textbf{C.}] $0<\varepsilon<1$
	\task[\textbf{D.}] $\varepsilon>1$
\end{tasks}
\begin{answer}
	$$
	\frac{1}{r}=\frac{m}{l^{2}}(1+\varepsilon \cos \theta)
	$$
	For parabolic trajectory $\varepsilon=1$.\\
	The correct option is \textbf{(b)}
\end{answer}

	\item A particle of unit mass moves along the $x$-axis under the influence of a potential, $V(x)=x(x-2)^{2}$. The particle is found to be in stable equilibrium at the point $x=2$. The time period of oscillation of the particle is
	{\exyear{GATE 2012}}
\begin{tasks}(2)
	\task[\textbf{A.}] $\frac{\pi}{2}$
	\task[\textbf{B.}]$\pi$
	\task[\textbf{C.}]$\frac{3 \pi}{2}$
	\task[\textbf{D.}] $2 \pi$
\end{tasks}
\begin{answer}
	\begin{align*}
	&V(x)=x(x-2)^{2} \Rightarrow \frac{\partial V}{\partial x}=(x-2)^{2}+2 x(x-2)=0 \Rightarrow x=2, x=\frac{2}{3}\\
		&\frac{\partial^{2} V}{\partial x^{2}}=2(x-2)+2(x-2)+\left.2 x \Rightarrow \frac{\partial^{2} V}{\partial x^{2}}\right|_{x=2}=2 \times 2=4 \\
		&\Rightarrow \omega=\sqrt{\left.\frac{\partial^{2} V}{\partial x^{2}}\right|_{x=2}} \Rightarrow \omega=\frac{2 \pi}{T}=2 \Rightarrow T=\pi
	\end{align*}
	The correct option is \textbf{(b)}
\end{answer}
	\item $\text { A particle of mass } m \text { is in a potential given by }$
	$$V(r)=-\frac{a}{r}+\frac{a r_{0}^{2}}{3 r^{3}}$$
	where $a$ and $r_{0}$ are positive constants. When disturbed slightly from its stable equilibrium position it undergoes a simple harmonic oscillation. The time period of oscillation is
	{\exyear{GATE 2014}}
\begin{tasks}(2)
	\task[\textbf{A.}] $2 \pi \sqrt{\frac{m r_{0}^{3}}{2 a}}$
	\task[\textbf{B.}]$2 \pi \sqrt{\frac{m r_{0}{ }^{3}}{a}}$
	\task[\textbf{C.}]$2 \pi \sqrt{\frac{2 m r_{0}^{3}}{a}}$
	\task[\textbf{D.}]$4 \pi \sqrt{\frac{m r_{0}^{3}}{a}}$
\end{tasks}
\begin{answer}
	\begin{align*}
	V(r)&=-\frac{a}{r}+\frac{a r_{0}^{2}}{3 r^{3}}\\
	\text{For equilibrium} \frac{\partial V}{\partial r}&=\frac{a}{r^{2}}-\frac{3 a r_{0}^{2}}{3 r^{4}}=0, \quad r=\pm r_{0} \\
	\frac{\partial^{2} V}{\partial r^{2}}&=-\frac{2 a}{r^{3}}+\left.\frac{4 a r_{0}^{2}}{r^{5}}\right|_{r_{0}}=-\frac{2 a}{r_{0}^{3}}+\frac{4 a r_{0}^{2}}{r_{0}^{5}}=\frac{2 a}{r_{0}^{3}}\\
	\omega&=\sqrt{\frac{\left.\frac{\partial^{2} V}{\partial r^{2}}\right|_{r_{0}}}{m}} \Rightarrow T=2 \pi \sqrt{\frac{m r_{0}^{3}}{2 a}}
	\end{align*}
	The correct option is \textbf{(a)}
\end{answer}
	\item A planet of mass $m$ moves in a circular orbit of radius $r_{0}$ in the gravitational potential $V(r)=-\frac{k}{r}$, where $k$ is a positive constant. The orbit angular momentum of the planet is
	{\exyear{GATE 2014}}
\begin{tasks}(2)
	\task[\textbf{A.}] $2 r_{0} \mathrm{~km}$
	\task[\textbf{B.}]$\sqrt{2 r_{0} \mathrm{~km}}$
	\task[\textbf{C.}]$r_{0} k m$
	\task[\textbf{D.}]$\sqrt{r_{0} k m}$
\end{tasks}
\begin{answer}
\begin{align*}
	V_{\text {effctive }}&=\frac{J^{2}}{2 m r^{2}}-\frac{k}{r} \Rightarrow \frac{d V_{\text {effect }}}{d r}=-\frac{J^{2}}{m r^{3}}+\frac{k}{r^{2}}=0 \text { at } r=r_{0}\\
\text { so } J&=\sqrt{r_{0} k m}
\end{align*}
The correct option is \textbf{(d)}
\end{answer}
	\item An interstellar object has speed $v$ at the point of its shortest distance $R$ from a star of much larger mass $M$. Given $v^{2}=2 G M / R$, the trajectory of the object is
	{\exyear{GATE 2018}}
\begin{tasks}(2)
	\task[\textbf{A.}] circle
	\task[\textbf{B.}]ellipse
	\task[\textbf{C.}]parabola
	\task[\textbf{D.}]hyperbola
\end{tasks}
\begin{answer}
	\begin{align*}
	\text { At shortest distance } E&=\frac{J^{2}}{2 m R^{2}}-\frac{G M m}{R}\\
	Since, m v R&=J \Rightarrow J^{2}=m^{2} v^{2} R^{2}\\
	Now, J^{2}&=m^{2} 2 G M R=2 G M m^{2} R\\
	(Given that v^{2}&=\frac{2 G M}{R} )\\
	E&=\frac{2 G M m^{2} R}{2 m R^{2}}-\frac{G M m}{R}=\frac{G M m}{R}-\frac{G M m}{R}=0
	\end{align*}
	$\text { For Kepler's potential, if energy is zero, then the shape is parabola. }$\\
	The correct option is \textbf{(c)}
\end{answer}

\end{enumerate}

Classical Mechanics  -CSIR/chapter/central force motion solutions.tex


\documentclass[12pt]{article}
\input{physics1}
\begin{document}

\section*{NYU Physics I---ideal gas law}

Here we investigate the statistical properties of a large number of
free particles in a box.
Imagine you have $N$ particles, each of mass $m$, in a box of volume $V$.
For definiteness, imagine that the box is a cube of side length $\ell$.
Work with a partner and make sure you both agree on each part and understand
why at each stage. This is an introduction to statistical mechanics.

\paragraph{\theproblem}\refstepcounter{problem}%
Just for kicks, imagine that \emph{half} of the particles are moving
at speed $+v$ in the $x$-direction, and half are moving at speed $-v$
in the $x$-direction. When the particles hit the box walls, they
bounce elastically off them. How many particles per unit time, on
average, hit the wall that is perpendicular to the $x$ direction?
Make sure you have a good, simple argument, and that your answer is
dimensionally correct.

\paragraph{\theproblem}\refstepcounter{problem}%
If each particle bounces elastically and normally off the wall (that
is, there is no frictional force at the wall), then how much momentum
is delivered by the wall at each individual-particle impact? That is,
what is the impulse of each impact?

\paragraph{\theproblem}\refstepcounter{problem}%
If the average force is the average of momentum provided per unit
time, what is the mean force provided by the ``gas'' of particles to
the wall, and what is the mean pressure (force per area)? Do you see
why there is a mean force? If not, argue it out.

\paragraph{\theproblem}\refstepcounter{problem}%
Now imagine that each particle has not the same velocity, but some
mean squared velocity $\bar{v_x^2}$ in the $x$-direction. What is the
mean pressure in terms of the mean squared velocity?

\paragraph{\theproblem}\refstepcounter{problem}%
In high school, did you learn that $P\,V = n\,R\,T$? What were the
units of $P$, $V$, $P\,V$, $n$, $R$, $T$, and $n\,R\,T$?

\paragraph{\theproblem}\refstepcounter{problem}%
In statistical mechanics, the equation is $P\,V = N\,k\,T$, where $N$
is the number of molecules, and $k$ is the Boltzmann constant. What is
the ratio $R/k$, both conceptually and numerically?

\paragraph{\theproblem}\refstepcounter{problem}%
Space is three-dimensional, so the mean squared three-space
velocity can be written in terms of one-dimensional means $\bar{v^2} =
\bar{v_x^2} + \bar{v_y^2} + \bar{v_z^2}$. If the gas of particles is
isotropic, these three contributions to the mean velocity magnitude
ought to all be equal, or three times the mean-squared $x$ component.
Relate the pressure you got above to the mean-squred three-space velocity,
and also the mean kinetic energy per molecule $(1/2)\,m\,\bar{v^2}$.

\paragraph{\theproblem}\refstepcounter{problem}%
Rearrange your equation into the form $P\,V=\mbox{something}$. How can
you define $T$ in terms of the per-particle kinetic energy to make the
statistical mechanics equation $P\,V = N\,k\,T$ true? Do you have any
comments to make?

\paragraph{\theproblem}\refstepcounter{problem}%
Look up equipartition on the web and comment on the relationship
between what you got and what you expect from your web reading. Any
comments on the derivation above?

\end{document}


\documentclass[
  xhtml,%
  use filename%
]{internet}
%\usepackage{fancyvrb}
%\usepackage[scale=.8]{geometry}
\usepackage{tutorial}
\usepackage{hyperref}

\newtheorem{question}{Question}

\title{What's Your Angle?}

\begin{document}
\maketitle
\section{Introducing Logo}

\ \verb+Logo+ is a computer programming language built around giving instructions to a \emph{turtle} (can be either robotic or virtual).
You tell the turtle where to move, and as it moves then it draws a line to show its path.
The instructions are given as if telling the turtle where to go next.
So you might say ``Go forward \(50\) steps'' or ``Turn left \(30^\circ\)''.
Using these, and similar, commands you can get the turtle to draw quite intricate patterns.

There are a few other commands relating to the line that it draws.
You can change the colour and width of the line.
You can tell it to skip a section of the line.
In some implementations, you can tell it to \emph{fill} a shape that it has drawn (that isn't a feature of this version but you can find online \verb+Logo+ implementations to play with).

\section{Moving Your Turtle}

\begin{enumerate}
\item Go to \href{http://luacanvas.mathforge.org?project=Turtle}{http://luacanvas.mathforge.org?project=Turtle}
\item To make the turtle draw something, you give it the instructions inside the \verb+setup+ function.
It will then draw what you tell it when you run the code.

Your turtle is called just \verb+turtle+.
If you want to change its name, replace the lowercase \verb+turtle+ in the line \verb+turtle = Turtle()+ with your chosen name.
You can only use letters, and you can't use spaces (but capital letters are fine).
So \verb+Fred = Turtle()+ is okay.
If you change the name, you have to use that name exactly as you originally wrote it.
In this tutorial, we will assume that we haven't changed the name.

The commands are:
\begin{itemize}
\item To make the turtle go forwards, \verb+turtle:forward(30)+.

Note the colon, \verb+:+, between the \verb+turtle+ and \verb+forward+.
The number, in this case \(30\), tells it how much to go forwards.
The units are pixels (the tiny dots) on the screen.

The number can be negative, but \dots

\item To make the turtle go backwards, \verb+turtle:backward(30)+.

\item To turn the turtle to its left, \verb+turtle:left(30)+.

The key here is that the turn is from the point of view of the turtle.
It will turn to its left by \(30^\circ\).

The number can be negative, but \dots

\item To turn the turtle to its right, \verb+turtle:right(30)+.

\item To stop it drawing, use \verb+turtle:penUp()+.

Note the parentheses at the end.
This means that when the turtle moves it will not leave a trail behind it.

\item To resume drawing, use \verb+turtle:penDown()+.

\item To change the colour, use \verb+turtle:setPenColour(127,245,200)+ or \verb+turtle:setPenColour("blue")+.

For more on how to specify a colour, see the \href{Style.xhtml}{Programming with Style} tutorial in the \emph{Programming} section of the tutorials.

\item To change the width, use \verb+turtle:setPenWidth(3)+.

\end{itemize}

\item Put some commands in the code to see what happens.
For example, so that the start of your code looks like this:

\begin{verbatim}
function setup()
  turtle = Turtle()
  turtle:forward(100)
  turtle:right(60)
  turtle:forward(30)
  turtle:left(100)
  turtle:forward(50)
  protractor = Protractor()
  ruler = Ruler()
end
\end{verbatim}

\item When you run this code, the ``turtle'' will draw the lines you have told it to.
You will notice two other shapes on the screen (you may have noticed them in the code) which look a bit like a protractor and a ruler.
They are.
You can drag them around the screen and turn them to make measurements to plan your drawing.
They aren't labelled, but the marks are \(5^\circ\) on the protractor and \(5\) pixels on the ruler.
To move them, click near the middle of the shape and drag it.
To rotate them, click near the outside of the shape and drag it round.

\end{enumerate}

\section{A Regular Shape}

In a regular shape, all the sides have the same length and all the angles are the same.
You can easily make the turtle draw a regular shape by alternating a turn of a fixed angle with a forward of a fixed distance.
Written out in full, this would have a lot of repetition and would be tedious to change to make a new shape.
So we use a \emph{loop} to make it more concise.

To repeat something a set number of times, we put it in a \verb+for+ loop, like this:

\begin{verbatim}
for k=1,4 do
  turtle:forward(100)
  turtle:turn(50)
end
\end{verbatim}

This repeats the instructions a total of \(4\) times.
The start of your code should look like this:

\begin{verbatim}
function setup()
  turtle = Turtle()
  for k = 1,4 do
    turtle:forward(100)
    turtle:right(50)
  end
  protractor = Protractor()
  ruler = Ruler()
end
\end{verbatim}

This shape doesn't join up.
The first goal is to find an angle and a number of repetitions that do make a closed, simple shape.
``Closed'' means that the lines join up, ``simple'' means that the lines don't cross each other.

By changing the \verb+4+ in the line \verb+for k=1,4 do+ then we change the number of repetitions.
Changing the \verb+50+ changes the angle.
If your drawing is too big for the screen, change the \verb+100+ to something smaller.

Once you have found an angle and a number of repetitions that works, make sure that your number of repetitions is \emph{minimal}.
That means that if you reduce the number of repetitions further then the shape will no longer close up.
It will also mean that the turtle ends up at exactly the same place and in the same direction as it started.

\begin{question}
What is the relationship between the number of repetitions and the angle that the turtle turns each time?

Find some other angles and number of repetitions that also draw closed, simple shapes.

What is the general relationship?
\end{question}

\begin{question}
What happens if we no longer insist that the shape be \emph{simple}?
So we allow the lines to cross existing lines, but the turtle must end up back where it started and facing the same way as it started.
\end{question}

\section{Irregular Shapes}

In an irregular shape, we no longer insist that the angles and side lengths be the same.
Let us, though, insist that the shape be still a closed, simple shape.

Draw a closed, simple shape that only involves \emph{left} turns (i.e., left turns with a positive angle).

To draw your shape, start with a few instructions with turns and forwards, then run your code to see where your turtle ends up.
Keep adding some more instructions and running your code to see what happens.
You may find it useful to use the ruler and protractor, particularly when figuring out the last ``joining up'' line.

\begin{question}
What do you spot about the angles that you turn?

\end{question}

\emph{Hint: what do you get if you add them up?}

\begin{question}
Now include some right turns as well (but keep the shape simple: no intersections).
What do you notice about the angles now?
\end{question}

\emph{Hint: treat the left and right turns separately.}

\section{Spirals}

There are some additional drawing commands that can be used to make nice spirals.

\begin{itemize}
\item \verb+turtle:toPosition(20,30)+ moves the turtle to the coordinate \((20,30)\) (with origin in the centre of the screen).
If the turtle's pen is down, a line will be drawn as it moves.

\item \verb+turtle:toRelativePosition(20,30)+ moves the turtle to the
coordinate \((20,30)\) relative to its current position.
That is, it moves it \(20\) pixels across and \(30\) up.

\item \verb+turtle:toAngle(50)+ turns the turtle so that it makes an angle of \(50^\circ\) from the horizontal, measured anticlockwise.

\item \verb+turtle:toRelativeAngle(50)+ turns the turtle so that it makes an angle of \(50^\circ\) from the line joining it to its original position at the centre of the screen.
\end{itemize}

Here are some spirals to get you started.
Pick one and make some changes to the code to experiment with.

\begin{enumerate}

\item You can get a nice spiral with the following instructions:

\begin{verbatim}
turtle:penUp()
turtle:toPosition(10,0)
turtle:penDown()
for k = 1,100 do
  turtle:forward(10)
  turtle:toRelativeAngle(90)
end
\end{verbatim}

\item The \emph{Fibonacci Sequence} leads to a nice spiral:

\begin{verbatim}
local a,b = 5,5
turtle:right(135)
for k=1,10 do
  turtle:forward(a)
  turtle:left(90)
  a,b = b,a+b
end
\end{verbatim}

\item Spirals can go inwards as well as outwards:

\begin{verbatim}
local s = 100
for k=1,30 do
  turtle:forward(s)
  turtle:left(60)
  s = .9*s
end
\end{verbatim}
\end{enumerate}

\end{document}


\documentclass[12pt]{article}
\usepackage[pdftex]{graphicx}
\begin{document}
\newcounter{problem}
\thispagestyle{empty}

\section*{NYU General Physics 1---Problem set 2}

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
What is the mean acceleration $a$ of a dragster (that is, a
drag-racing automobile) that can travel 0.25~mi in 5.5~s, starting
from a dead stop?  Assume that the dragster accelerates with constant
acceleration throughout the 5.5~s (not a terrible assumption, but not
a good one either).  Give your answer in terms of the gravitational
acceleration $g$.  Does your answer seem reasonable?  What do you
predict, under the constant-acceleration assumption, for the final
speed $v_\mathrm{f}$ of the dragster as it crosses the finish line?
Convert your answer to $\mathrm{mi\,h^{-1}}$.  Search the web for the
current world-record quarter-mile drag-race time and final speed.

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
For the time interval $0<t<1~\mathrm{s}$, draw graphs of the vertical
position $y$ (height) as a function of time, the vertical velocity
$v_y$ as a function of time, and the vertical acceleration $a_y$ as a
function of time of a rock that is thrown precisely upwards at
$3~\mathrm{m\,s^{-1}}$ at time $t=0$.  For definiteness, set
$|\vec{g}|=10~\mathrm{m\,s^{-2}}$ and make the ``upwards'' direction the
positive-$y$ direction.  Where does the rock ``end up'' at the end of
the $1~\mathrm{s}$ period; that is, what is $y(1\,\mathrm{s})$?
Assume that the rock is large and dense enough that we can ignore air
resistance.

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
Below is a graph of velocity $v_x$ in the $x$ direction as a function
of time $t$.  Draw the corresponding graph of position $x$ \textit{vs} time $t$ and
acceleration $a_x$ \textit{vs} time $t$.  Be very careful with the transitions and the
vertical scales.\\
\includegraphics{../py/vx_vs_t.pdf}

\end{document}