\documentclass[11pt]{article}

% Thanks to Evan Chen (http://www.mit.edu/~evanchen/index.html)
% for the template and helpful resources.

% Include math
\usepackage{amsmath,amsthm,amssymb,xspace}
% Include links
\usepackage{hyperref}

%%%%%%%%%%%%%  THEOREMS  %%%%%%%%%%%%%%%%%
\theoremstyle{plain} % other options: definition, remark
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}

\theoremstyle{definition}
\newtheorem*{definition}{Definition} % the star prevents numbering

% Remarks
\theoremstyle{remark}
\newtheorem{remark}{Remark}

%%%%%%%%%%%%%%  PAGE SETUP %%%%%%%%%%%%%%%%%
\usepackage[margin=1.5in]{geometry}

% The following sets up some headers
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{An eggs-ample of a linear programming problem} % Left Header
\rhead{\thepage} % Right Header
\cfoot{} % Center Foot (empty)

%%%%%%%%%%%%% SHORTCUTS %%%%%%%%%%%%%%%%%%%%

%latex symbol needs a forced space afterwords for God knows what reason
\newcommand{\latex}{\LaTeX\xspace}

\begin{document}

\title{Visualizing The Four Fundamental Subspaces in a Linear Programming Problem}
\author{Brooks Mershon}
\date{\today}
\maketitle
Please refer to Figure 1.6 on page 25 of \textit{BT} throughout this exercise. Pages 21-25 cover all of section 1.4, which provides some useful techniques for visualizing standard form  problems. Consider reading section 1.4 before continuing. I found section 1.4 helpful, but wanted to further explore the connection between a particular example contained within to some of the linear algebra prerequisites assumed for the course. In particular, I hope this exercise will help tie together the concepts of solving a system of linear equations with the Four Fundamental Subspaces in the context of a linear programming problem.

\bigskip

\section{Constraints in $\mathbb{R}^3$}
On page 25 of Bertsimas and Tsitsiklis (BT), we are instructed to visualize the feasible set in $\mathbb{R}^3$ defined by the constraints:
$$x_1 + x_2 + x_3 = 1 $$
and
$$x_1, x_2, x_3 \ge 0 $$

Try graphing the feasible set defined by this constraint in the empty box provided. You should get a view similar to Figure 1.6a from the textbook. The equation $x_1 + x_2 + x_3 = 1 $ defines a hyperplane, which is in this case a plane in $\mathbb{R}^3$.

\begin{center}\framebox(200, 200){}\end{center}

Ignoring for a moment the constraint that $x_1$, $x_2$, and $x_3$ are all positive, we can represent the information contained in the hyperplane we visualized with the $3\times 1$ matrix A as follows:

\[
\mathbf{A}=
  \begin{bmatrix}
    1 & 1 & 1
  \end{bmatrix}
\]

\[
\vec{x}=
  \begin{bmatrix}
    x_1 \\
    x_2 \\
    x_3
  \end{bmatrix}
\]

\[
\vec{b}=
  \begin{bmatrix}
    1
  \end{bmatrix}
\]

It is common for us to specify constraints in linear programming problems with the expression $\mathbf{A}\vec{x}=\vec{b}$. Here, $\vec{x}$ is a decision variable, usually chosen such that $\mathbf{A}\vec{x}=\vec{b}$ holds while some objective function of $\vec{x}$ is minimized. The graph you have just drawn shows a set in 3-dimensional space where the information contained in $\mathbf{A}$ and $\vec{b}$ has defined a hyperplane. Tasked with finding an assignment of  $x_1$, $x_2$, and $x_3$ for which $\mathbf{A}\vec{x}=\vec{b}$ holds, you only need to produce a vector $\vec{x}$ whose tip lies somewhere on the hyperplane (the feasible set). This feasible set is a triangle in $\mathbb{R}^3$ if $x_1, x_2, x_3 \ge 0 $.

\bigskip

Go ahead and add a vector $\vec{x}$ which stretches from the origin to a point somewhere in the feasible region of your drawing (the triangle in $\mathbb{R}^3$).

\newpage

\section{Resource allocation}
It's often easier to think about abstract ideas by playing with concrete examples. The \textit{hyperplane in three dimensions} example we just encountered can be made even more concrete by relating it to a ``real-world'' problem. Let us imagine a linear programming problem (LPP) that would be served well by the $\mathbf{A}\vec{x}=\vec{b}$ model of constraints that we just examined. This example will let us connect several linear algebra concepts to our new desire to solve all things that look like $\mathbf{A}\vec{x}=\vec{b}$.

\bigskip

Suppose you run a Bed \& Breakfast in Vermont that specializes in local food. You keep chickens around so you always have lots of fresh eggs on hand, and you use these eggs to prepare, among other things, three fantastic breakfast dishes, each of which uses just one egg. You never know how many of these dishes you will serve on a particular day. Some days one of the three dishes (call them dish A, B, and C) is very popular while the others are rarely ordered. On other days guests have you cooking up all three dishes in similar quantities. You do, however, only have a set number of eggs on hand; perhaps 40 eggs on a good day and only 20 or so on a bad day. On a bad day in which you only have 24 fresh eggs, you will be able to serve 9 guests who order dish A, 4 guests order dish B, and 11 guests who order dish C, but you will not be able to serve 30 total orders for an egg dish. On that day, you would have to recommend other choices to those 6 who were late to come to breakfast!

If we wanted to visualize a vector space that told us something about the combinations of orders we could satisfy with $b$ eggs on hand, we could imagine an $3 \times 1$ matrix A that looked like this:

\[
\mathbf{A}=
  \begin{bmatrix}
    1 & 1 & 1
  \end{bmatrix}
\]

And a vector $\vec{x}$ specifying how many of each dish we serve:

\[
\vec{x}=
  \begin{bmatrix}
    \text{\# of dish A}\\
   \text{\# of dish B} \\
   \text{\# of dish C}
  \end{bmatrix}
\]

$\mathbf{A}\vec{x}$ gives us the total number of eggs used in satisfying the orders vector $\vec{x}$. This is a scalar for all practical purposes, but we should still consider $\vec{b}$ as a column vector of length 1:

\[
\vec{b}=
  \begin{bmatrix}
   \text{\# of eggs on hand}
  \end{bmatrix}
\]

Go back to your graph and annotate the three axes, where $x_1$ is now dish A, $x_2$ is now dish B, and $x_3$ is now dish C. You have just created \textit{dish space}. Any vector $\vec{x}$ in \textit{dish space}, where $x_1, x_2, x_3 \ge 0 $, corresponds to some particular day's distribution of orders. For example, 10 of dish A, 3 of dish B, and no orders for dish C. The graph you have now annotated shows the combinations of orders you could satisfy if you had ONLY ONE EGG TO USE. If you relax the requirement that you cook whole dishes, rather than fractions of a dish, then you can pick a vector $\vec{x}$ anywhere in the feasible set you have drawn.

\section{Column space in $\mathbb{R}$}

The column space of a matrix $\mathbf{A}$ is the span of the column vectors of $\mathbf{A}$. In this example, the three column vectors are not linearly independent. Intuitively, this is because the three dishes we make all use eggs. Viewed as a resource allocation problem, we have 3 products and one material. Each product (dish) uses one material (eggs). Our specific problem indicates that each product uses the same amount of material, but this could easily be changed so that dish A took 3 eggs, dish B took 2 eggs, and dish C required only 1 egg. So the column space in this case is really a one-dimensional ``number line.'' The vector $\vec{b}$ lies in \textit{egg space}, or \textit{material space}. Given a vector $\vec{x}$ in $\mathbb{R}^3$, $\mathbf{A}\vec{x}$ gives us the number of eggs used, which is actually a vector in \textit{egg space}. The \textit{egg space} we have now visualized is in fact the \textit{column space} of the matrix $\mathbf{A}$. And this column space is one-dimensional.

Go ahead and draw a number line in the box below. This is \textit{egg space}. This is the \textit{column space} of matrix A. The matrix $\mathbf{A}$ maps vectors from $\mathbb{R}^3$ to $\mathbb{R}$, or from \textit{dish space} to \textit{egg space}.

\begin{center}\framebox(375, 100){}\end{center}

\section{Null space in $\mathbb{R}^3$}

The null space of a matrix $\mathbf{A}$ is the set of vectors $\vec{x}$ that satisfy $\mathbf{A}\vec{x}=\vec{0}$. If we restrict ourselves to positive numbers of dishes, then the only way to make dishes while using zero eggs is to make none of each dish. This corresponds to a plane through the origin in \textit{dish space}. This plane can be shifted away from the origin in the direction of a normal to our plane by increasing the amount of eggs we have to use. This corresponds to picking a vector $\vec{b}$ on our number line in \textit{egg space} further to the right. The plane can be tilted if we change the entries of $\mathbf{A}$. Draw a ``tilted`` version of the feasible region by specifying a different matrix $\mathbf{A}$ and corresponding graph in the box below.

\begin{center}\framebox(375, 200){}\end{center}

\bigskip

Notice that a normal to our feasible set is orthogonal to our null space...

\section{Row space in $\mathbb{R}^3$}

The row space of a  matrix $\mathbf{A}$ is the span of the row vectors. In this case, we see that this is a line specified by scalar multiples of the normal vector to our hyperplane. The row space is the orthogonal complement to the null space, and it is spanned by a normal vector to our feasible set!. Any vector with positive components in $\mathbb{R}^3$ (\textit{dish space}) can be thought of as some vector in the null space plus some vector in the row space of $\mathbf{A}$. Remember, the column space lives elsewhere, on the number line you have drawn, but the row space lives in the same space where you decide how many of each dish to make (the vector $\vec{x}$).

\bigskip

*So here's the really neat part: you can think of the row space as providing a direction to move if you want to require more or less eggs \textit{in total}. If you want to reallocate your numbers of each type of dish so as to use the same number of eggs, then you should move around in the feasible set. How do you move around in the feasible set? Moving strictly along the row space keeps the number of each dish in proportion; you simply end up requiring more ore less total eggs. If you take a vector $\vec{x}$ that already satisfies $\mathbf{A}\vec{x}=\vec{b}$, and add to that vector some vector in the null space, you get another feasible combination of dishes. You are moving from one feasible set of orders in \textit{dish space}, given a set number of eggs on hand, to another feasible set of orders in \textit{dish space}.

\section{Left null space in $\mathbb{R}$}

The left null space is the orthogonal complement to the column space. Since this subspace lives in $\mathbb{R}^m$, and $m=1$, the dimension of this subspace is zero.

\section{Where's the optimization?}

Lastly, the linear programming formulation of the bed \& breakfast problem requires some objective function to minimize (maximize). With just the feasible set that you have drawn, you might just stop at imagining the combinations of orders you will be able to satisfy as the guests show up and request various dishes, given the number of fresh eggs $b$ that you have for the day. However, let us say each dish has a different cost, and the line chef gets bored if he doesn't get to experience some variety in the orders for the three dishes. With a price vector $\vec{p}$ and an interest vector $\vec{q}$, we can aim to maximize the restaurant's success counterbalanced against the chef's fulfillment. Let $p_i$ represent the price of dish $i$, and let $q_i$ represent the chef's interest, normalized in a unit comparable to dollars, in cooking dish $i$. We wish to maximize:

$$\sum_{i=1}^{n} (p_i + q_i)x_i$$

Look back at the graphs you have drawn and annotated. If things got messy, draw  $\mathbb{R}^3$ and  $\mathbb{R}$ again in the boxes below. Try drawing and labeling the basis vectors corresponding to the column space (egg space) and row space.

\begin{center}\framebox(200, 200){}\end{center}

\begin{center}\framebox(375, 100){}\end{center}

I hope this helps. Writing this sure helped me better understand the connection between subspaces and solving constraints of the form $\mathbf{A}\vec{x}=\vec{b}$. The big box below is a good space to write down a diagram representing the Four Fundamental Subspaces. Gilbert Strang's (MIT) essay on the Four Fundamental Subspaces is a useful resource.
\bigskip

\url{<http://web.mit.edu/18.06/www/Essays/newpaper_ver3.pdf>}

\begin{center}\framebox(375, 200){}\end{center}

For a refresher on the interaction between row space and null space, consider watching the following series of videos from Khan Academy:

\bigskip

\url{<https://www.khanacademy.org/math/linear-algebra/alternate_bases>}

\bigskip

Areas for further exploration:

\begin{itemize}
  \item The left null space and quotient spaces and their relation to LPP's.
  \item Other``real-world'' examples of LPP's visualized as linear transformations.
  \item Find interactive resources to put textbook theory into practice.

\end{itemize}

\end{document}


\problemname{Identifying Map Tiles}

Map websites such as Bing Maps and Google Maps often store their maps as many different image files, called tiles. The lowest zoom level (level $0$) consists of a single tile with a low-detail image of the whole map, zoom level $1$ consists of four tiles each containing a slightly more detailed version of a quarter of the map, and in general zoom level $n$ contains $4^n$ different tiles that each contain a part of the map.

One way of identifying a tile is by means of a \emph{quadkey}. A quadkey is a string of digits uniquely identifying a tile at a certain zoom level. The first digit specifies in which of the four  quadrants of the whole map the tile lies: \texttt{0} for the top-left quadrant, \texttt{1} for the top-right quadrant, \texttt{2} for the bottom-left quadrant and \texttt{3} for the bottom-right quadrant. The subsequent digits specify in which sub quadrant of the current quadrant the tile is. The quadkeys for zoom levels $1$ to $3$ are shown in Figure~\ref{fig:maps}(a).

\begin{figure}[h]
	\centering
	\subfigure[Quadkeys for zoom levels $1$ to $3$]{ \label{fig:quadkey}
\ifplastex
		\includegraphics[width=0.85\textwidth]{maptiles.jpg}
\else
		\includegraphics[width=0.6\textwidth]{maptiles.jpg}
\fi
	}
\ifplastex\else	\quad \fi
	\subfigure[Coordinates for zoom level 3]{ \label{fig:coords}
		% Ugly, use specific width to make the height equal, but problem
		% is that there's text in the left image so we can't easily use height
\ifplastex
		\includegraphics[width=0.90\textwidth]{maptiles2.jpg}
\else
		\includegraphics[width=0.338\textwidth]{maptiles2.jpg}
\fi
	}
	\caption{Visualisation of the two representations. The images are taken from the \href{https://msdn.microsoft.com/en-us/library/bb259689.aspx}{MSDN}.}
    \label{fig:maps}
\end{figure}

Another way of identifying a tile is to give the zoom level and $x$ and $y$ coordinates, where $(0,0)$ is the left-top corner. The coordinates for the tiles of zoom level 3 are shown in Figure~\ref{fig:maps}(b). Given the quadkey of a tile, output the zoom level and $x$ and $y$ coordinates of that tile.

\section*{Input}

The input consists of:
\begin{itemize}
   \item one line with a string $s$ ($1\leq \text{length}(s) \leq 30$), the quadkey of the map tile.
\end{itemize}
The string $s$ consists of only the digits `\texttt{0}', `\texttt{1}', `\texttt{2}' and `\texttt{3}'.

\section*{Output}

Output three integers, the zoom level and the $x$ and $y$ coordinates of the tile.


\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[margin=1in]{geometry}
\usepackage{enumitem}
\usepackage{listings}
\usepackage{soul}

\title{Depth First Learning Problem Set 2: Random matrix theory basics}

\date{\today}

\begin{document}
\maketitle

\section*{Problem 1: Avoided crossings in random matrix spectra}

In the first DFL session's intro to RMT, we mentioned that eigenvalues of random matrices tend to \emph{repel} each other.  In fact, one of the recommended textbooks on RMT says that
\begin{quote}
    This interplay between confinement and repulsion is the physical mechanism at the heart of many results in RMT.
\end{quote}

This problem explores that statement, relating it to a concept which comes up often in physics: the avoided crossing.

\begin{enumerate}[label=(\alph*)]
\item The simplest example of an avoided crossing is in a two-by-two matrix.  Let's take the matrix
 \begin{center}
\begin{pmatrix}
\Delta & J \\
J & -\Delta
\end{pmatrix}
\end{center}

Since this matrix is symmetric, its eigenvalues will be real.  \textbf{What are its eigenvalues?}

To see the avoided crossing here, \textbf{plot the eigenvalues as a function of $\Delta$, first for $J=0$, then for a few non-zero values of $J$.}

You should see a gap open up as $J$ grows beyond zero.  \textbf{What is the size of this gap?}

\item Now take a matrix of the form
 \begin{center}
\begin{pmatrix}
A & C \\
C & D
\end{pmatrix}
\end{center}

In terms of $A$, $B$, $C$, and $D$, \textbf{what is the absolute value of the difference between the two eigenvalues of this matrix?}

\item Now let's make the matrix a random matrix.  We will take $A$, $C$, and $D$ to be random variables, where the diagonal entries $A$ and $D$ are distributed according to a normal distribution with mean zero and variance one, while the non-diagonal entry $C$ is also a zero-mean Gaussian but with a variance of $1/2$.

\textbf{Use the formula you derived in the previous part of the question to calculate the probability distribution function for the spacing between the two eigenvalues of the matrix.}

\textbf{What is the behavior of this pdf at zero?  How does this relate to the avoided crossing you calculated earlier?}

\item \textbf{Verify using numerical simulation that the pdf you found in the previous part is correct.}

\end{enumerate}

\section*{Problem 2: Properties of the Gaussian Orthogonal Ensemble}

One of the simplest and most-studied random matrices is the so-called Gaussian Orthogonal Ensemble, or GOE.  In this problem, we will discover some properties of the GOE.
\begin{enumerate}[label=(\alph*)]
\item To sample from the Gaussian orthogonal ensemble, one way is to generate an $N$ by $N$ random matrix where all of the entries are independent, identically-distributed Gaussians with zero mean and unit variance.  The eigenvalues of this matrix will in general be complex, so we symmetrize the matrix by adding it to its transpose and dividing by two.

\textbf{From the above information, what is the joint probability density function of the entries of a GOE matrix?}

\item One of the celebrated properties of the GOE is its rotational invariance. Rotational invariance here means that any orthonormal vector in $N$ dimensions is equally likely to be an eigenvector of a GOE matrix: no direction is preferred.  The rest of the problem is dedicated to showing that the GOE is in fact rotationally invariant.

First, imagine a diagonalizable matrix $M$, which has some (real) eigenvalues and eigenvectors.  \textbf{If I want to make a matrix which is the same as $M$ except that every eigenvector is rotated by a rotation matrix $O$, what is the resulting matrix?}

\item The trace of a matrix is defined as the sum of its diagonal entries.  \textbf{Show that a matrix $M$, and its rotated version, have the same trace.}

\item \textbf{Write the pdf of entries of a GOE matrix (which you found in part (a) above) in terms of the trace of some matrix, and use this to argue that the distribution is rotationally invariant.}

\end{enumerate}

\section*{Problem 3: Analysis with random matrices warm-up}

In this problem, we'll explore a one of the first brushes with actually analyzing random matrices that one will come across in studying the subject - getting some notion of the sizes of various random matrix ensembles, and understanding how the distributions, conditions, and dependencies between them, all of which determine various random matrix ensembles, generate the size. This will also be directly relevant to the family of papers we're interested in since the size of the random matrices we'll be considering is a prerequisite to understanding both what initial constraints to place on the matrices we study and how to properly normalize them for analysis.

We'll break this problem down into several concrete steps, building up to the final definition of size we'll use and how to calculate it for the prototypical example of random matrices, which also happens to be the ensemble relevant for us: Wigner matrices.

\begin{enumerate}
    \item What exactly does it mean for a matrix (which is really just a linear transformation on, say, some Euclidean space) to have a magnitude? Let's start with how we measure size for numbers where this already makes sense, and then generalize. The absolute value of a real (or complex) number is typically conceptualized as the "distance from zero", but since matrices are linear transformations it makes more sense to treat numbers as one-dimensional linear transformations too, visualized as acting via multiplication to stretch the real line. The absolute value, then, is the stretch factor. Matrices, however, do not have a single stretch factor - after all, if they did, all their eigenvalues would be the same - but instead we can simply use the maximum stretch factor, defining the \textbf{operator norm} of a matrix $ M $ as $ || M ||_\text{op} = \sup_{x \neq 0} \frac{|| M x ||_2}{|| x ||_2} $.

    \textbf{Let's start by proving that this norm is coordinate-independent. Take a matrix $ M $ and any invertible change-of-basis matrix $ P $, and show that $ M $ and $ P M P^{-1} $ have the same operator norm.}

    \item \textbf{How is the operator norm related to the spectrum of a matrix?} Assume the matrix is symmetric.

    \item Now let's take an $ N \times N $ random matrix $ M_N $ whose entries are i.i.d. with zero mean and unit variance. To make this a Wigner matrix, we'll also stipulate that it's symmetric - so $ (M_N)_{ji} = (M_N)_{ij} $ - and therefore guaranteed $ N $ (counting multiplicity) real eigenvalues. Exactly computing the operator norm of $ M_N $ requires techniques that are out of scope (see the epsilon-net method, or the moment method, for how to do this) but something we can determine using the spectrum is how the operator norm grows with $ N $.

    \textbf{To start this off, prove that}
    $$ || M_N ||_\text{op} = \lim_{p \to \infty} \left( \text{tr}(M_N)^p \right)^\frac{1}{p} $$

    \item \textbf{Taking } $ p = 2 $ \textbf{above, show that } $ \frac{1}{N} \text{tr}(M_N^2) $ \textbf{is the average squared eigenvalue.} Note that this is a reasonable proxy for the average size of the eigenvalues - without squaring, we would have unwanted cancellations in the average.

    \item \textbf{Show that the average squared eigenvalue of $ M_N $ grows as $ O(N) $.}

    \item \textbf{Finally, show why dividing each entry of $ M_N $ by $ \sqrt{N} $ is precisely what we need to ensure that the spectrum is on average $ O(1) $ (and thus the operator norm is too, though you don't have to prove this).}

\end{enumerate}

\section*{Problem 4: Proving the semicircle law}

In this problem, we'll prove one of the most prominent results in random matrix theory: the semicircle law. Essentially, we'll find that the distribution of eigenvalues of an $ N \times N $ Wigner matrix converges (in $ N $) to a particular distribution - that of a semicircle. This is striking because the definition of a Wigner matrix imposes a small number of mild constraints on the structure of the random matrices, basically just the bare minimum we need to ensure our random matrices are well-defined enough to actually study their spectra, but beyond requiring the matrix be symmetric and its entries be i.i.d with bounded moments, we've stipulated nothing about the actual distributions of the entries. We'll use a powerful technique commonly applied in random matrix theory, and which we'll meet again in upcoming lectures: the Stieltjes transform.

Let's define the $ N \times N $ Wigner matrix $ W_N $ by normalizing the $ M_N $ from the above $ M_N $ from the previous problem. This way, we can guarantee that the eigenvalue spectrum doesn't explode without bound as we take $ N \to \infty $ and actually forms a valid distribution worth studying. More formally, define

$$ \begin{aligned} W_n := \frac{1}{\sqrt{n}} \begin{bmatrix} \zeta_{ij} \end{bmatrix}_{1 \leq i, j \leq n} &\text{ where for } \begin{cases} i > j&: \mathbb{E}(\zeta_{ij}) = 0 \text{ (centered) and } \text{Var}(\zeta_{ij}) = \mathbb{E}(| \zeta_{ij} |^2) = 1 \\ i < j&: \zeta_{ij} = \zeta_{ji} \\ i = j&: \mathbb{E}(\zeta_{ii}) = 0, \text{Var}(\zeta_{ii}) < \infty \end{cases} \\ &\text{ and the } \zeta_{ij} \text{ are i.i.d. for } i \geq j \end{aligned} $$

To formally study the eigenvalue distribution of $ W_N $, let's define the \textit{empirical spectral distribution} $ \mu_N = \frac{1}{N} \sum_{i = 1}^N \delta_{\lambda_i} $ where the $ \lambda_i $ are the $ N $ eigenvalues of $ W_N $ and $ \delta $ refers to the Dirac delta function. So, we're essentially constructing a pretty artifical "distribution" of the finitely many eigenvalues of $ W_N $ by simply placing a point mass at each eigenvalue and then normalizing. This is the distribution we'll show converges to the semicircle distribution.

\begin{enumerate}
    \item The \textit{Stieltjes transform} of $ W_N $ is defined
        $$ s_{\mu_N}(z) = \int_\mathbb{R} \frac{\text{ d} \mu_N(t)}{t - z} $$
    \textbf{How can we rewrite this in terms of the trace of $ W_N $?}

    \item The \textit{semicircle distribution} that we'll show $ \mu_N $ converges to is defined precisely to have the shape of a semicircle in the upper half plane with radius 2 (because the eigenvalues of $ W_N $ concentrate in the interval $ [-2, 2] $, though this isn't super relevant).
        $$ \rho_\text{sc}(z) = \frac{1}{2 \pi} \sqrt{4 - x^2} $$
    \textbf{What is the Stieltjes transform of the semicircle distribution?}

    \end{enumerate}

You might be wondering why the semicircle, of all shapes, comes up here. This is related to another observation you may have made about the Stieltjes transform of the semicircle from the previous part of this problem, namely that it looks strikingly like something akin to the quadratic formula. Indeed, this is because the semicircle distribution is in fact the solution to a quadratic equation: the \textit{self-consistency equation}. $ \rho_\text{sc} $ is the unique distribution that satisfies
    $$ s_\rho = \frac{1}{-z - s_\rho} $$
Because the self-consistency equation has one unique solution (the proof of uniqueness is out of scope), if we can show that
    $$ s_{\mu_N} \approx \frac{1}{-z - s_{\mu_N}} $$
with the approximation becoming exact as $ N \to \infty $, then we'll be done. The next couple parts of this question will walk you through proving this.

\begin{enumerate}
    \item[3.] The Stieltjes transform of a Wigner matrix is basically the average diagonal entry of the quantity $ (W_N - z I_N)^{-1} $, which is also known as the resolvent. The resolvent is a diagonal matrix, and based on the assumption that its last entry is typical (it is, but we won't prove this here), we can approximate the Stieltjes transform, which is exactly equal to $ \frac{1}{n} \text{tr} \left( (W_N - z I_N)^{-1} \right) $ with $(W_N - z I_N)^{-1}_{NN}$.

    \textbf{Letting $\zeta_{ij}$ denote the entries of $ W_N $, use the Schur complements formula}
    $$ \text{ for } n \times n \text{ block matrix } M = \begin{bmatrix} A & B \\ C & D \end{bmatrix}, M_{nn} = (D - C A^{-1} B)^{-1} $$
    \textbf{to show that}
    $$(W_N - z I_N)^{-1}_{NN} = \left( \frac{1}{\sqrt{N}} \zeta_{NN} - z - \frac{1}{N} X^* (W_{N - 1} - z I_{N - 1})^{-1} X \right)^{-1}$$
    \textbf{for random vector $X$ with i.i.d entries and top left minor $W_{N - 1}$ Of $ W_N$.}
    \textit{Hint: Decompose $ W_N $ into a block matrix first.}

    \item[4.] \textbf{Finally, show that}
    $$ \mathbb{E} \left( \frac{1}{N} X^* (W_{N - 1} - z I_{N - 1})^{-1} X \right) = \frac{1}{N} \text{tr} \left( (W_{N - 1} - z I_{N - 1})^{-1} \right) = s_{\mu_{N - 1}}(z) $$

\end{enumerate}

This part suffices to complete the proof, because it shows that at least in expectation, as we take $ N \to \infty $, the $ \frac{1}{\sqrt{N}} \zeta_{NN} $ term vanishes since $ \frac{1}{\sqrt{N}} \rightarrow 0 $ and $ \zeta_{NN}$ is $ O(1) $, and so we are left with
$$ s_{\mu_N}(z) \approx (W_N - z I_N)^{-1}_{NN} \approx \left(-z - s_{\mu_{N - 1}}(z) \right)^{-1} \approx \left(-z - s_{\mu_N}(z) \right)^{-1} $$
for large $ N $. Hence, the empirical spectral distribution of $W_N$ obeys the self-consistency equation as $N \to \infty$, and thus converges to the semicircle distribution. Note that while we've shown this only in expectation, it can be easily extended rigorously using the Cauchy interlacing formula, though this is out of scope.

\end{document}


% !TEX root = thesis.tex

\section{Methodology}\label{sec:style}

As we've seen in the previous section the log data comprises of error messages of multiple unknown classes. The basic idea is to analyse the data present and cluster the messages in to different classes. One can see from the error logs that a few features of all the messages are unique (eg. timestamps, ErrorID.. etc). These unique features are given lesser priority in the clustering of the data  hence corresponding weights are assigned to these features. The distance between the messages is compared by ignoring these unique features. The trivial logic is to put the messages whose distance is less than a predefined threshold are put into the same class. A dummy illustration of the algorithm is shown below.

\begin{figure}[htp]
    \centering
    \includegraphics[width=7cm]{img/proc.png}
    \caption{Illustration of the log data analysis procedure}
    \label{fig:galaxy}
\end{figure}

The figure shows the demonstration of the clustering and the classification procedure. Each one of the 3 shapes represents as class and the variables inside each shape represent the unique features in the dataset. The data is clustered based on how similar the shapes are ignoring the unique features of the message. Once the messages are clustered, the principal features are extracted from each class and marked as a feature vector of that class. Now, every new entry in the data point is compared with these principal feature vectors to

The first step idea is to extract message "keys" which
correspond to messages generated by the same lines of code but with different message variables, implemented using regex. They proceed to utilise
the similarity in clustering raw log keys by using the edit distance as their
metric, which is defined as the number of insertion, deletion or replacement
operations required to convert one message into another. This distance does
not account for the position of the words in the logs, and so they use the
weighted edit distance which uses sigmoid function to place greater emphasis on words appearing earlier in the message than later based on the
idea/observation that programmers tend to place important information in
this way. The edit distances to all other logs is calculated, and all members
whose distance is less than a threshold is connected via a link.

In this section, we define how we approach the problem
mathematically, starting with our choice of similarity measure, the Jaccard
Similarity, J: in order to identify similar items, we must first identify how
to define and quantify similarity. We progress to describe shingling, a naïve
method to fully iterate over the parameter space in order to compute J, and
learn how it is infeasible to apply to large datasets, such as when hundreds
of thousands of logs are generated every minute, as can be the case in distributed systems.

\subsection{Min hash}\label{sec:_academic_style}
In order to identify similar items, a similarity measure is necessary. A common and intuitive means is that of the Jaccard Similarity. This treats two strings as sets of words, and defines the size of their intersection relative to their union as the defining metric of similarity. We therefore see that not only can the relation between two logs be evaluated,but the distances between different logs represent hierarchies of similarity, and these can be mined to reveal underlying clusters. Other alternative methods include measuring distance as the number of edits required to transform one message in another. he signatures we desire to construct for sets are composed of the results of a large number of calculations, say several hundred, each of which is a “minhash”. To minhash a set represented by a column of the characteristic matrix, pick
a permutation of the rows. The minhash value of any column is the number of
the first row, in the permuted order, in which the column has a 1. The probability that the minhash function for a random permutation of
rows produces the same value for two sets equals the Jaccard similarity
of those sets. \textbf{[Add reference for minhash here]}

\subsection{Min Hash Locality Sensitive Hashing}\label{sec:_tips_for_writing}

MinHash is an effective means for reducing the dimensionality of variable
length alphanumerical data to fixed length numerical output, with which
Jaccard similarity can be probabilistically calculated via random sampling.
However, each log hash must still be compared to every other in order to
identify relationships, resulting in complexity O(n**2). There are a range of
search methods for identifying nearest neighbours (examples, references)
based on space partitioning but it was shown that they all degrade to linear search for sufficiently high dimensions. Locality Sensitive Hashing
is used to reduce the search space by using hash collisions as a proxy for
similarity.  \textbf{{[Add reference for LSH here]}}

\subsection{Shingling}\label{sec:_tips_for_writing}


\graphicspath{ {lecture2/} }
\section{Models of Computation}

What is an Algorithm ?
\begin{enumerate}
    \item Mathematical abstraction of computer program
    \item Computational procedure to solve a problem
\end{enumerate}

\begin{figure}[H]
    \includegraphics[width=\textwidth]{Figure1}
    \centering
    \caption{Algorithm}
    \label{fig:img1}
\end{figure}

\noindent Model of computation specifies
\begin{enumerate}
    \item what operations an algorithm is allowed
    \item cost (time, space, . . .) of each operation
    \item cost of algorithm = sum of operation costs
\end{enumerate}


%-----------------------------------------------------------------------------------------------
\section{Illustration of Carnot's General Proposition}

    Solutions to the integrals of Eqs.~(\ref{eq:W}) and (\ref{eq:Q})  are  given  by  Cheng  and
    Yang~\cite{2012-ChengCH+YangHS-ApEnergy}, which applied the residual theorem. The  resulting
    expressions are:
    %
    \begin{align}
        \label{eq:Ws}
        \bar{W} &= \frac{2\pi\tau\kappa(1 - \tau)\sin\alpha}{a^2 + b^2}\cdot\Lambda,\\
        \label{eq:Qs}
        \bar{Q}_{in} &= \frac{2\pi\tau\kappa\sin\alpha}{a^2 + b^2}\cdot\Lambda,
    \end{align}
    %
    \noindent with
    %
    \begin{equation}
        \label{eq:Lamda}
        \Lambda = \left(
                \frac{\beta - \sqrt{\beta^2 - (a^2 + b^2)}}{\sqrt{\beta^2 - (a^2 + b^2)}}
            \right),
    \end{equation}
    %
    \noindent where $a$, $b$, and $\beta$ are configuration dependent expressions, given as:
    %
    \begin{align}
        \label{eq:aa}
        a^{\alpha}  &= \tau\sin\alpha,\\
        \label{eq:ab}
        a^{\beta}   &= -(1 - \tau)\sin\alpha,\\
        \label{eq:ag}
        a^{\gamma}  &= -(1 - \tau)\sin\alpha;\\
        \label{eq:ba}
        b^{\alpha}  &= \kappa + \tau\cos\alpha,\\
        \label{eq:bb}
        b^{\beta}   &= \kappa - (1 - \tau)\cos\alpha,\\
        \label{eq:bg}
        b^{\gamma}  &= \kappa - (1 - \tau)\cos\alpha;\\
        \label{eq:betaa}
        \beta^{\alpha}  &= 4\tau\chi/(1 + \tau) + \tau + \kappa,\\
        \label{eq:betab}
        \beta^{\beta}   &= 4\tau\chi/(1 + \tau) + \tau \nonumber\\
                        &+ \sqrt{1 - 2\kappa\cos\alpha + \kappa^2},\\
        \label{eq:betag}
        \beta^{\gamma}  &= 4\tau\chi/(1 + \tau) + 1 + \tau + \kappa.
    \end{align}

    Although the  cycle  net  work,  $\bar{W}$,  and  inlet  heat,  $\bar{Q}_{in}$,  are  indeed
    \emph{complicated} functions of the engine's configuration, internal  details,  and  of  the
    reservoir temperatures, as shown by Eqs.~(\ref{eq:Ws}) and (\ref{eq:Qs}), one  can  realize,
    by mere inspection on these same equations, that the thermal  efficiencies,  $\eta_t  \equiv
    \bar{W} / \bar{Q}_{in}$, of all these reversible engines:
    %
    \begin{enumerate}
        \item Are indeed \emph{the same}: $\eta^{\alpha}_t = \eta^{\beta}_t = \eta^{\gamma}_t$;
        \item Are \emph{equal to any reversible engine's} thermal efficiency, $\eta_{t,rev} =  1
            - \tau$, operating between the same temperature reservoirs; and
        \item  Are  indeed   a   function   of   \emph{only}   the   reservoirs'   temperatures:
            $\eta_t\!:\!\eta_t(\tau)$.
    \end{enumerate}

    Therefore, the reversible $\alpha$-, $\beta$-, and $\gamma$-types Stirling engine models  of
    Cheng and Yang~\cite{2012-ChengCH+YangHS-ApEnergy}, are shown  to  follow  Carnot's  general
    proposition, according to the second law of thermodynamics.

    The worked out illustration serves thus as an instance of defined  reversible  engines  with
    different internal details and  working  fluids  of  possibly  different  properties,  whose
    thermal efficiencies are restricted by Carnot's general proposition, despite the  fact  that
    their net work and inlet heat are different and complicated functions of the various working
    parameters and engine configuration.

%-----------------------------------------------------------------------------------------------


\section{Interpreter Exercise}

\begin{lstlisting}[language=Haskell]
divProg =
  CpsCmd [
    AssiCmd "q" (LitAExpr 0),
    AssiCmd "r" (IdAExpr "m"),
    WhileCmd (RelBExpr GreaterEq (IdAExpr "r") (IdAExpr "n"))
      (CpsCmd [
         AssiCmd "q" (DyaAExpr Plus (IdAExpr "q") (LitAExpr 1)),
         AssiCmd "r" (DyaAExpr Minus (IdAExpr "r") (IdAExpr "n"))
      ])
  ]

type Value = Int
type Ident = String

type State = Ident -> Value

state_q5 "q" = 5
state_q5 _ = 0

readS :: State -> Ident -> Value
readS state ident = state ident

updateS :: State -> (Ident, Value) -> State
updateS s (ident, val) =
  \ident' -> if ident' == ident then val
             else s ident'

data ArithExpr
  = LitAExpr Int   -- Literal Arithmetic Expression
  | IdAExpr Ident
  | DyaAExpr ArithOperator ArithExpr ArithExpr   -- dyadic, means two
  deriving Show

data ArithOperator
  = Times | Div | Mod | Plus | Minus
  deriving Show

-- (2 + 3) * 4
ae1, ae2 :: ArithExpr
ae1 = DyaAExpr Plus (LitAExpr 2) (LitAExpr 3)
ae2 = DyaAExpr Times ae1 (LitAExpr 4)

-- (q + 1)
aeq1 = DyaAExpr Plus (IdAExpr "q") (LitAExpr 1)
-- (r - n)
aern = DyaAExpr Minus (IdAExpr "r") (IdAExpr "n")

evalAExpr :: ArithExpr -> State -> Int   -- Semantic function
evalAExpr (LitAExpr c) _ = c
evalAExpr (IdAExpr ident) state = readS state ident
evalAExpr (DyaAExpr opr expr1 expr2) state =
    operation val1 val2
  where operation = evalAOpr opr
        val1 = evalAExpr expr1 state
        val2 = evalAExpr expr2 state

evalAOpr :: ArithOperator -> (Int -> Int -> Int)
evalAOpr Times = (*)
evalAOpr Div = div
evalAOpr Mod = mod
evalAOpr Plus = \a b -> a + b
evalAOpr Minus = (-)

evalAOprV2 :: ArithOperator -> (Int -> Int -> Int)
evalAOprV2 Times a b = a * b

data RelOperator
  = LessEq
  | GreaterEq
  deriving Show

evalROpr :: RelOperator -> (Value -> Value -> Bool)
evalROpr LessEq = (<=)
evalROpr GreaterEq = (>=)

data BoolExpr
  = RelBExpr RelOperator ArithExpr ArithExpr
  deriving Show

evalBExpr :: BoolExpr -> State -> Bool   -- Semantic function
evalBExpr (RelBExpr opr expr1 expr2) state =
    operation val1 val2
  where operation = evalROpr opr
        val1 = evalAExpr expr1 state
        val2 = evalAExpr expr2 state

data Command
  = AssiCmd Ident ArithExpr
  | CpsCmd [Command]
  | WhileCmd BoolExpr Command
  deriving Show

interCmd :: Command -> State -> State
interCmd (AssiCmd ident expr) state =
    updateS state (ident, val)
  where
    val = evalAExpr expr state

interCmd (CpsCmd cmds) state =
  foldl (flip interCmd) state cmds

interCmd (WhileCmd guard repetend) state
  | evalBExpr guard state =
      interCmd (WhileCmd guard repetend) state'
  | otherwise = state
        where state' = interCmd repetend state

state175 "m" = 17
state175 "n" = 5
state175 _ = 0

stateOut = interCmd divProg state175

qres = readS stateOut "q"
rres = readS stateOut "r"

--evalAOpr :: ArithOperator -> (Int -> Int -> Int)
--evalAOpr Times = (*)

--data T = Prelude.False
\end{lstlisting}
\clearpage


\section{Automaton $\rarr$ Regular Expression}
\textbf{BMC} (Brzozowski \& McCluskey) method.

\textbf{Assumptions}: unique initial state $i$ without incoming arcs, unique final state $t$ without outgoing arcs.

Remove internal states (i.e. not $i$ nor $t$) compensating with new moves.

\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\linewidth]{automata/bmc.png}
\end{figure}

Replace $q$ with: for each pair $p_i$, $r_j$ a compensating transition $p_i \xrightarrow{H_iJ^*K_j} r_j$. All the parallel transitions should be merged ASAP in $p \xrightarrow{e_1|e_2} r$.


\section{Moment Realizability for the Fermionic Two-Moment Model}
\label{sec:realizability}

Our goal is to simulate massless fermions (e.g., neutrinos) and study their interactions with matter.
The principal objective is to obtain the fermionic distribution function $f$ (or moments of $f$ as in the two-moment model employed here).
The Pauli exclusion principle requires the distribution function to satisfy the condition $0 \le f \le 1$, which puts restrictions on the admissible values for the moments of $f$.
In this paper, we seek to design a numerical method for solving the system of moment equations given by Eq.~\eqref{eq:momentEquations} that preserves realizability of the moments; i.e., the moments evolve within the set of admissible values as dictated by Pauli's exclusion principle.
(Since we are only concerned with the angular dependence of $f$ in this section, we simplify the notation by suppressing the $\vect{z}$ and $t$ dependence and write $f(\omega,\vect{z},t)=f(\omega)$.)

\modified{
We let
\begin{equation}
  \mathfrak{R} := \left\{\,f~|~0\le f \le 1 ~\text{and}~0<\f{1}{4\pi}\int_{\bbS^{2}}f\,d\omega<1\,\right\},
\end{equation}
and begin with the following definition of moment realizability.}
\begin{define}
  \modified{The moments $\vect{\cM}=\big(\cJ,\vect{\cH}\big)^{T}$ are realizable if they can be obtained from a distribution function $f(\omega)\in\mathfrak{R}$.}
  %satisfying $0 < f(\omega) < 1~\forall~\omega\in\bbS^{2}$.
  The set of all realizable moments $\cR$ is
  \begin{equation}
    \cR:=\big\{\,\vect{\cM}=\big(\cJ,\vect{\cH}\big)^{T}~|~\cJ\in(0,1)~\text{and}~\gamma(\vect{\cM}) > 0\,\big\},
    \label{eq:realizableSet}
  \end{equation}
  where we have defined the concave function $\gamma(\vect{\cM})\equiv(1-\cJ)\cJ-|\vect{\cH}|$.
  \label{def:momentRealizability}
\end{define}
\begin{rem}
  Following \cite{lareckiBanach_2011}, in Definition~\ref{def:momentRealizability}, and in the rest of this paper, we exclude the cases $f=0$ and $f=1$ almost everywhere (a.e.) on $\bbS^{2}$, which would give $\cJ=0$, $\vect{\cH}=0$ and $\cJ=1$, $\vect{\cH}=0$, respectively.
\end{rem}
\modified{
\begin{rem}
  The conditions in Eq.~\eqref{eq:realizableSet} are necessary and sufficient for the moments to be realizable \cite[Theorem 7.1]{banachLarecki_2017a}.  (See also \cite{lareckiBanach_2011,banachLarecki_2013}.)
\end{rem}
}

%The algebraic constraints in Eq.~\eqref{eq:realizableSet} are proven in \cite{banachLarecki_2017a}.
%\begin{lemma}
%  Suppose that $0 < f(\omega) < 1~\forall~\omega\in\bbS^{2}$.
%  Then the moments $\vect{\cM}=(\cJ,\vect{\cH})^{T}$, defined as in Eq.~\eqref{eq:angularMoments}, satisfy $0 < \cJ < 1$ and $\big(1-\cJ\big)\,\cJ-|\vect{\cH}| > 0$.
%  \label{lem:MomentRealizable}
%\end{lemma}

%\begin{define}
%  For the fermion two-moment model, the realizable set is
%  \begin{equation}
%    \cR:=\big\{\,\vect{\cM}=\big(\cJ,\vect{\cH}\big)^{T}~|~\cJ\in(0,1)~\text{and}~\gamma(\vect{\cM})\equiv(1-\cJ)\cJ-|\vect{\cH}| > 0\,\big\}.
%    \label{eq:realizableSet}
%  \end{equation}
%\end{define}

\begin{lemma}
  The realizable set $\cR$ is convex.
\end{lemma}
\begin{proof}
%  In order to prove that $\cR$ is convex, it is sufficient to show that any convex combination of elements in $\cR$ also belongs to $\cR$.
  Let $\vect{\cM}_{a}=\big(\cJ_{a},\vect{\cH}_{a}\big)^{T}$ and $\vect{\cM}_{b}=\big(\cJ_{b},\vect{\cH}_{b}\big)^{T}$ be two arbitrary elements in $\cR$, and let $\vect{\cM}_{c} = \theta\,\vect{\cM}_{a} + (1-\theta)\,\vect{\cM}_{b}$, with $0\leq\theta\leq1$.
  The first component of $\vect{\cM}_{c}$ is
  \begin{equation*}
    \cJ_{c} = \theta\,\cJ_{a} + (1-\theta)\,\cJ_{b}.
  \end{equation*}
  Since $\cJ_{a},\cJ_{b} \in (0,1)$, it follows that $\cJ_{c} \in (0,1)$.
  Concavity of $\gamma$ implies that
%  Since $\cJ_{a},\cJ_{b} \in (0,1)$, it is straightforward to verify that
  \begin{equation*}
  \gamma(\vect{\cM}_{c}) \geq \theta\,\gamma(\vect{\cM}_{a}) + (1-\theta)\,\gamma(\vect{\cM}_{b}) > 0.
  \end{equation*}
  Hence, $\vect{\cM}_{c}\in\cR$.
\end{proof}

Figure~\ref{fig:RealizableSetFermionic} illustrates the geometry of the convex set $\cR$ in the $(\cH,\cJ)$-plane (light blue region).
The boundary $\partial\cR$ (black curves) is given by $\gamma(\vect{\cM})=0$.
The realizable domain of positive distribution functions, $\cR^{+}$ (no upper bound on $f$), which is a convex cone defined by
\begin{equation}
  \cR^{+}:=\big\{\,\vect{\cM}=\big(\cJ,\vect{\cH}\big)^{T}~|~\cJ > 0~\text{and}~\cJ > |\vect{\cH}|\,\big\},
  \label{eq:realizableSetPositive}
\end{equation}
is partially shown as the light red region above the red lines, which mark the boundary of $\cR^{+}$ (denoted $\partial\cR^{+}$).
The realizable set $\cR$ is a bounded subset of $\cR^{+}$.
%The realizable domains $\cR$ and $\cR^{+}$ overlap for low particle densities ($\cJ\ll1$), but for larger values of $\cJ$, the realizable domain of particles governed by Fermi-Dirac statistics is much more restricted than that of particles described by positive distribution functions with no upper bound.

\begin{figure}[H]
  \centering
  \includegraphics[width=1.0\linewidth]{figures/RealizableSetFermionic}
  \caption{Illustration of the realizable set $\cR$ (light blue region) defined in Eq.~\eqref{eq:realizableSet}.
  The black lines define the boundary $\partial\cR$, while the red lines indicate the boundary of the realizable set $\cR^{+}$ (light red region) defined in Eq.~\eqref{eq:realizableSetPositive}.}
  \label{fig:RealizableSetFermionic}
\end{figure}

For the realizability-preserving scheme developed in Section~\ref{sec:realizableDGIMEX}, we state some additional results.
Lemma~\ref{lem:explicitStep} is used to help prove the realizability-preserving property of explicit steps in the IMEX scheme, while Lemmas~\ref{lem:implicitStep} and \ref{lem:correctionStep} are used to prove realizability-preserving properties of implicit steps.
\begin{lemma}
  Let $\big\{\cJ_{a},\vect{\cH}_{a},\vect{\cK}_{a}\big\}$ and $\big\{\cJ_{b},\vect{\cH}_{b},\vect{\cK}_{b}\big\}$ be moments defined as in Eq.~\eqref{eq:angularMoments} with distribution functions $f_{a}$ and $f_{b}$, respectively, such that $f_{a}(\omega),f_{b}(\omega)\in(0,1)\,\forall\,\omega\in\bbS^{2}$.
  Let $\Phi^{\pm}(\vect{\cM},\vect{\cK})=\f{1}{2}\big(\vect{\cM}\pm\widehat{\vect{e}}\cdot\vect{\cF}\big)$, where $\widehat{\vect{e}}\in\bbR^{3}$ is an arbitrary unit vector, and $\widehat{\vect{e}}\cdot\vect{\cF}=\big(\widehat{\vect{e}}\cdot\vect{\cH},\widehat{\vect{e}}\cdot\vect{\cK}\big)^{T}$.
  Then
  \begin{equation*}
    \vect{\cM}_{ab} \equiv \Phi^{+}(\vect{\cM}_{a},\vect{\cK}_{a})+\Phi^{-}(\vect{\cM}_{b},\vect{\cK}_{b})\in\cR.
  \end{equation*}
  \label{lem:explicitStep}
\end{lemma}
\begin{proof}
  The components of $\vect{\cM}_{ab}$ are
  \begin{equation*}
    \cJ_{ab}=\f{1}{4\pi}\int_{\bbS^{2}}f_{ab}(\omega)\,d\omega
    \quad\text{and}\quad
    \vect{\cH}_{ab}=\f{1}{4\pi}\int_{\bbS^{2}}f_{ab}(\omega)\,\vect{\ell}(\omega)\,d\omega,
  \end{equation*}
  where $f_{ab}(\omega)=\vartheta\,f_{a}(\omega)+(1-\vartheta)\,f_{b}(\omega)$ and $\vartheta(\omega)=(1+\widehat{\vect{e}}\cdot\vect{\ell}(\omega))/2\in[0,1]$.
  Then, since $f_{ab}(\omega)\in(0,1)\,\forall\,\omega\in\bbS^{2}$, it follows that $\vect{\cM}_{ab}\in\cR$.
\end{proof}

\begin{lemma}
  Let $\vect{\cM}_{a}=(\cJ_{a},\vect{\cH}_{a})^{T}\in\cR$ and $\alpha>0$.
  Let $\vect{\cM}_{b}=(\cJ_{b},\vect{\cH}_{b})^{T}$ satisfy
  \begin{equation}
    \vect{\cM}_{b}=\vect{\cM}_{a}+\alpha\,\vect{\cC}(\vect{\cM}_{b}),
    \label{eq:implicitStep}
  \end{equation}
  where $\vect{\cC}(\vect{\cM})=\vect{\eta}-\vect{\cD}\,\vect{\cM}$ is the collision term in Eq.~\eqref{eq:collisionTermMoments}.
  Then $\vect{\cM}_{b}\in\cR$.
  \label{lem:implicitStep}
\end{lemma}
\begin{proof}
  Solving Eq.~\eqref{eq:implicitStep} for $\vect{\cM}_{b}$ gives $\vect{\cM}_{b} = \big(\vect{I}+\alpha\,\vect{\cD}\big)^{-1}\big(\vect{\cM}_{a}+\alpha\,\vect{\eta}\big)$.
  The first component of $\vect{\cM}_{b}$ can be written as
  \begin{equation*}
    \cJ_{b}=\f{1}{4\pi}\int_{\bbS}f_{b}(\omega)\,d\omega,
  \end{equation*}
  where $f_{b}(\omega)=\zeta\,f_{a}(\omega)+(1-\zeta)\,f_{0}$, $\zeta=1/(1+\alpha\,\xi)\in[0,1]$, and $f_{0}$ and $\xi$ are defined in Eq.~\eqref{eq:collisionTerm} in Section~\ref{sec:model}.
  Then, since $f_{b}(\omega)\in(0,1)\,\forall\,\omega\in\bbS^{2}$, $\cJ_{b}\in(0,1)$.
  Meanwhile,
  \begin{equation*}
    \vect{\cH}_{b}=\f{(1+\alpha\,\xi)}{(1+\alpha)}\,\widetilde{\vect{\cH}}_{b},
    \quad\text{where}\quad
    \widetilde{\vect{\cH}}_{b}=\f{1}{4\pi}\int_{\bbS^{2}}f_{b}(\omega)\,\vect{\ell}(\omega)\,d\omega.
  \end{equation*}
  It follows that $\widetilde{\vect{\bcM}}_{b}=(\cJ_{b},\widetilde{\vect{\cH}}_{b})^{T}\in\cR$.
  Then, since $0\le\xi\le1$, $|\vect{\cH}_{b}|\le|\widetilde{\vect{\cH}}_{b}| < (1-\cJ_{b})\,\cJ_{b}$.
\end{proof}

\begin{lemma}
  Let $\vect{\cM}_{a}=(\cJ_{a},\vect{\cH}_{a})^{T}\in\cR$ and $\alpha>0$.
  Let $\vect{\cM}_{b}$ satisfy
  \begin{equation*}
    \vect{\cM}_{b}=\vect{\cM}_{a}+\alpha\,\vect{\cD}\,\vect{\cC}(\vect{\cM}_{b}),
  \end{equation*}
  where $\vect{\cD}$ and $\vect{\cC}(\vect{\cM})$ are given by Eq.~\eqref{eq:collisionTermMoments}.
  Then $\vect{\cM}_{b}\in\cR$.
  \label{lem:correctionStep}
\end{lemma}
The proof of Lemma~\ref{lem:correctionStep} follows along the same lines as the proof of Lemma~\ref{lem:implicitStep} and is omitted.


% This LaTeX was auto-generated from an M-file by MATLAB.
% To make changes, update the M-file and republish this document.

%%% \documentclass{article}
%%% \usepackage{graphicx}
%%% \usepackage{color}

%%% \sloppy
%%% \definecolor{lightgray}{gray}{0.5}
\setlength{\parindent}{0pt}

%%% \begin{document}

\subsection*{Ratio of signal to noise and distortion and Effective number of bits (time space)}

\begin{par}
Example for algorithm SINAD-ENOB.
\end{par} \vspace{1em}
\begin{par}
Algorithm calculates Ratio of signal to noise and distortion and Effective number of bits in time space. First signal is generated, then estimates of signal parameters are calculated by Four parameter sine wave fitting and next SINAD and ENOB are calculated. This example do not take into account a quantisation noise.
\end{par} \vspace{1em}

\subsubsection*{Contents}

\begin{itemize}
\setlength{\itemsep}{-1ex}
   \item Generate sample data
   \item Calculate estimates of signal parameters
   \item Copy results to inputs
   \item Calculate SINAD and ENOB
   \item Display results:
\end{itemize}

\subsubsection*{Generate sample data}

\begin{par}
Two quantities are prepared: \lstinline{t} and \lstinline{y}, representing 1 second of sinus waveform of nominal frequency 1 kHz, nominal amplitude 1 V, nominal phase 1 rad and offset 1 V sampled at sampling frequency 10 kHz.
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
DI = [];
Anom = 2; fnom = 100; phnom = 1; Onom = 0.2;
DI.t.v = [0:1/1e4:1-1/1e4];
DI.y.v = Anom*sin(2*pi*fnom*DI.t.v + phnom) + Onom;
\end{lstlisting}
\begin{par}
Add a noise with normal distribution probability:
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
noisestd = 1e-4;
DI.y.v = DI.y.v + noisestd.*randn(size(DI.y.v));
\end{lstlisting}
\begin{par}
Lets make an estimate of frequency 0.2 percent higher than nominal value:
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
DI.fest.v = 100.2;
\end{lstlisting}

\subsubsection*{Calculate estimates of signal parameters}

\begin{par}
Use QWTB to apply algorithm \lstinline{FPNLSF} to data \lstinline{DI}.
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
CS.verbose = 1;
DO = qwtb('FPNLSF', DI, CS);
\end{lstlisting}

        \begin{lstlisting}[style=output]
QWTB: no uncertainty calculation
Fitting started

Local minimum found.

Optimization completed because the size of the gradient is less than
the default value of the function tolerance.

Fitting finished
\end{lstlisting} \color{black}

\subsubsection*{Copy results to inputs}

\begin{par}
Take results of \lstinline{FPNLSF} and put them as inputs \lstinline{DI}.
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
DI.f = DO.f;
DI.A = DO.A;
DI.ph = DO.ph;
DI.O = DO.O;
\end{lstlisting}
\begin{par}
Suppose the signal was sampled by a 20 bit digitizer with full scale range \lstinline{FSR} of 6 V (+- 3V). (The signal is not quantised, so the quantization noise is not present. Thus the simulation and results are not fully correct.):
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
DI.bitres.v = 20;
DI.FSR.v = 3;
\end{lstlisting}

\subsubsection*{Calculate SINAD and ENOB}

\begin{lstlisting}[style=mcode]
DO = qwtb('SINAD-ENOB', DI, CS);
\end{lstlisting}

        \begin{lstlisting}[style=output]
QWTB: no uncertainty calculation
\end{lstlisting} \color{black}

\subsubsection*{Display results:}

\begin{par}
Results are:
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
SINADdB = DO.SINADdB.v
ENOB = DO.ENOB.v
\end{lstlisting}

        \begin{lstlisting}[style=output]

SINADdB =

   82.9229

ENOB =

   13.0657

\end{lstlisting} \color{black}
    \begin{par}
Theoretical value of SINADdB is 20*log10(Anom./(noisestd.*sqrt(2))). Theoretical value of ENOB is log2(DI.range.v./(noisestd.*sqrt(12))). Absolute error of results are:
\end{par} \vspace{1em}
\begin{lstlisting}[style=mcode]
SINADdBtheor = 20*log10(Anom./(noisestd.*sqrt(2)));
ENOBtheor = log2(DI.FSR.v./(noisestd.*sqrt(12)));
SINADerror = SINADdB - SINADdBtheor
ENOBerror = ENOB - ENOBtheor
\end{lstlisting}

        \begin{lstlisting}[style=output]

SINADerror =

   -0.0874

ENOBerror =

   -0.0145

\end{lstlisting} \color{black}

%%% \end{document}


%% Chapter 3 : Basics of Solar Energy

\section{Solar Radiation and Solar Spectrum}
\
\
\
\
Sun is the source of radiation. It is a thermonuclear furnace, where hydrogen atoms undergo fusion to become helium atoms. The mass lost in the process is converted into electromagnetic energy of the order of $3.8\times10^{20}$ MW. This energy is radiated outwards from the surface of he sun into space.\\

For the purpose of understanding the nature of absorption and emission of electromagnetic radiation by an object, we use a mathematical abstraction called a \textit{Blackbody}. It is the perfect emitter and absorber of radiation; which means that for a given area and temperature the blackbody will absorb  all radiation impinging on it, and emit more radiation per square unit area as compared to any other object. Moreover, no radiation is reflected or transmitted through a blackbody. The idea of the blackbody is credited to the German physicist Max Planck.\\

The wavelengths emitted by a blackbody are dependent on its temperature. This is described by the \textit{Planck's Law} given in eq (\ref{planck})

\begin{equation}
\label{planck}
E_{\lambda}=\frac{3.74\times10^{8}}{\lambda^{5} \left[\text{exp}\left( \frac{14,400}{\lambda T}\right)-1 \right]}
\end{equation}\\
where,\\
$ E_{\lambda} $ = Emissive power per unit area of a blackbody $ (W/m^{2}) $ \\
$ T $ = Absolute temperature of the body $ (K) $ \\
$ \lambda $ = Wavelength $ (\mu m) $ \\

The \textit{Stefan-Boltzman Law of Radiation} given in eq (\ref{stefbolt}) expresses the area under the Planck's curve between any two points, which represents the power emitted between those two wavelengths. This is called as the total emitted radiant power.

\begin{equation}
\label{stefbolt}
E = A \sigma T^{4}
\end{equation}\\
where,\\
$ E $ = Total blackbody emission rate $ (W) $ \\
$ A $ = Area of the body $ (m^{2}) $ \\
$ \sigma $ = Stefan-Boltzman constant $ (5.67\times10^{-8} W/m^{2}K^{4}) $ \\

One characteristic feature of the blackbody radiation curve is given by \textit{Wien's Displacement Rule} given in eq (\ref{wien}), which identifies the wavelength where the blackbody will emit maximum radiation.

\begin{equation}
\label{wien}
\lambda_{{max}}(\mu m)=\frac{2898}{T(K)}
\end{equation}\\
where,\\
$ \lambda_{max} $ = Wavelength at which blackbody emits maximum radiation $ (\mum) $ \\

The Fig \ref{figc3h1} shows the ideal blackbody Planck's curve at 5800 K, which is the surface temperature of the sun. The total area under this blackbody curve gives the solar insolation just outside the earth's atmosphere, which is approximately $1.37 \ \text{kW/m}^{2}$. The yellow part of the Fig \ref{figc3h1} shows the actual Solar Spectrum prior to entering earth's atmosphere, it approximately depicts the blackbody curve. The actual solar spectrum consists of:

\begin{enumerate}
\item Ultraviolet (UV) is 7\%
\item Visible is 47\%
\item Infrared (IR) is 46\%
\end{enumerate}

\begin{figure}[H]
\centering
\includegraphics[scale=1]{SolarSpec}
\caption{Solar Spectrum [5]}
\label{figc3h1} %% to refer use, \ref{}
\end{figure}

Also, the red part of Fig \ref{figc3h1} shows the Solar Spectrum (terrestrial spectrum) after passing through the earth's atmosphere, where it undergoes various stages of absorption. Hence, the available solar energy on the surface of the earth is lesser than that available outside the atmosphere.

\section{Photovoltaic Cell}
\
\
\
\
The photovoltaic cell is physically equivalent to a p-n junction diode shown in Fig (\ref{figc3h2}). A p-n junction diode consists of two types of semiconducting materials, which are n-type and p-type materials. The n-type material has been doped with a valency +5 element atoms, which donates the extra electron to the lattice which is free to move within the crystal lattice formed by the valency 4 Silicon atoms and the donor atoms; hence, the n-type materials have free electrons. Whereas, for creating a p-type material valency +3 element atoms, which creates a hole in the crystal lattice which can readily accept a free moving electron; hence, the p-type materials have positively charged holes (lack of an electron can be mathematically termed as a positive charge). However, the net charge of both the n and p type materials is neutral.

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{pn-junction}
\caption{PN- Junction Diode}
\label{figc3h2} %% to refer use, \ref{}
\end{figure}

A pn-junction diode is formed by joining a p-type material with an n-type material. Now, at the junction of the diode the mobile electrons from the n region and the mobile holes from the p region of the diode drift by diffusion across the junction, leaving behind static positive charges and negative charges in the n region and p region of the diode respectively. These immobile charges create  a static electric field which opposes the diffusion of mobile electron and holes (also called charged carriers). The diffusion process continues till the electric field increases so much so that it restricts all further  diffusion of the charged carriers across the junction. This region of immobile charges at the junction is called the depletion region (depleted of mobile charged carriers). The width of the depletion region is about 1 $\mu \text{m} $ and the voltage across it is about 1 V; hence, electric field strength is about 10,000 V/cm. The Fig (\ref{diode12}) shows the symbol characteristics of a pn-junction diode.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{diode1}
\caption{PN Juction Diode Symbol and Characteristics [5]}
\label{diode12} %% to refer use, \ref{}
\end{figure}

There are two modes of operation of a p-n junction diode. Firstly, the forward conduction mode, where an external positive voltage is applied across p-side and n-side (the external voltage cancels the effect of electric feild developed by the depletion region and allows for further diffusion reducing the width of the depletion region), in this mode the diode conducts very well offering least resistance. But, when a the voltage polarity across the pn-junction diode is reversed it blocks the flow of current offering maximum resistance, this mode of operation is called the reverse bias. Still a small amount of current flows due to thermally generated carriers, this current is called the reverse saturation current. The voltage-current characteristics for the pn-junction diode is described by the Shockley diode equation given by eq (\ref{diode})

\begin{equation}
\label{diode}
I_{d} = I_{0}( e^{qV_{d}/kT}-1)
\end{equation}\\
where,\\
$ I_{d} $ = Diode Current $ (A) $ \\
$ I_{0} $ = Reverse saturation current $ (A) $ \\
$ q $ = Electron charge $ (1.602\times10^{-19} C) $ \\
$ V_{d} $ = Voltage across diose terminals frm p-side to n-side $ (V) $ \\
$ k $ = Boltzman's constant $ (1.381\times10^{-23} J/K) $ \\

The Fig (\ref{d2}) shows the operation principle of a photovoltaic cell. When a pn-junction diode is exposed to sunlight, owing to the photo-electric effect photons of sunlight will be absorbed and electron-hole pairs will be formed.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{pv8}
\caption{PN-Junction Diode as a Photovoltaic Cell [5]}
\label{d2} %% to refer use, \ref{}
\end{figure}

If these mobile charge carriers reach near the depletion layer, the electric field in the depletion layer will push the holes to the p-side and electrons to the n-side. Hence, holes will accumulate in the p-side and electrons in the n-side of the pn-junction diode. Now, if electrical contacts are attached to the pn-junction diode ends, conventional current will from p-side (electrons flow from the n-side) into the wire, through the load and back to the n-side, thus completing a circuit.\\

A simple model of a photovoltaic cell consists of a pn-junction diode in parallel with an ideal current source shown in Fig (\ref{p1}), where the ideal current source produces current in direct proportion to the amount of solar flux incident on it.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{pv9}
\caption{Simple Equivalent circuit of a Photovoltaic Cell [5]}
\label{p1} %% to refer use, \ref{}
\end{figure}

From Fig (\ref{pv9}) we can write the voltage and current equations for the PV cell as,

\begin{equation}
\label{pv1}
I = I_{SC}-I_{d}
\end{equation}\\
where,\\
$ I $ = Current output from PV Cell $ (A) $ \\
$ I_{SC} $ = Short circuit current of PV Cell $ (A) $ \\

Substituting the value of $I_{d}$ in above equation we get,

\begin{equation}
\label{pv2}
I = I_{SC}-I_{0} \left(e^{qV/kT}-1 \right )
\end{equation}

Where, $I_{SC}$ is the short circuit current, i.e. the current measured when the p-side and n-side are shorted, which means $V=0$, and $I$ is the load current.\\

Conversely, when the leads from the PV cell are kept open, no current flows i.e. $I=0$, the voltage measured is called as open-circuit voltage $(V_{OC})$, which is given by the following equation,

\begin{equation}
\label{pv3}
V_{OC} = \frac{kT}{q}\ln \left (\frac{I_{SC}}{I_{0}}+1\right )
\end{equation}\\
where,\\
$ V_{OC} $ = Open circuit voltage of PV Cell $ (V) $\\

The eq (\ref{pv2},\ref{pv3}) at $25^{\circ} \text{C}$ are given by the following equations,

\begin{equation}
\label{pv4}
I = I_{SC}-I_{0} \left(e^{38.9V}-1 \right )
\end{equation}

\begin{equation}
\label{pv5}
V_{OC} = 0.0257\ln \left (\frac{I_{SC}}{I_{0}}+1\right )
\end{equation}

\subsection{PV Cell Model with Shunt Resistance}
\
\
\
\
A more accurate model of PV cell is developed when a resistance is added in parralel to the pn-junction diode as shown in Fig (\ref{fig3h4})

\begin{figure}[H]
\centering
\includegraphics[scale=1]{PVmo}
\caption{PV Cell Model With Shunt Resistance [5]}
\label{figc3h4} %% to refer use, \ref{}
\end{figure}

This model describes the behaviour of a PV cell in a string of PV cell. If we consider that one of the PV cells in the string is shaded, then it will not produce current, moreover the pn-junction diode pertaining to that cell will be reverse biased and no current will not allow any flow of current. This will cause the entire current output from the string of PV cells to be reduced to zero, and no power is delivered to the load according to the simple equivalent model. But, in reality this is not the case and power though reduced in amount is delivered to the load even during shading. Hence, the voltage and current characteristics of a PV cell model with parallel resistance $R_{P}$ is given as follows,

\begin{equation}
\label{pv6}
I = (I_{SC}-I_{d})-\frac{V}{R_{P}}
\end{equation}\\
where,\\
$ V $ = Voltage at output of PV Cell $ (V) $ \\
$ R_{P} $ = Parallel resistance of the PV Cell $ (\Omega) $

\begin{figure}[H]
\centering
\includegraphics[scale=1]{pv1}
\caption{Effect of Parallel Resistance on I-V Curve [5]}
\label{figc3h111} %% to refer use, \ref{}
\end{figure}

The Fig (\ref{figc3h111]) shows the effect of parallel resistance on the I-V characteristics of the PV cell. It can be observed that the parallel resistance causes the load current for the simple model to be decreased by $V/R^{P}$.

\subsection{PV Cell Model with Series Resistance}
\
\
\
\
There is some intrinsic resistance of the semiconductor and also the contact resistance of the bond between the the wires and the cell leads. This resistance is called the series resistance ($R_{S}$), as it reduces the voltage availabe at the load terminals.
Hence, an accurate model of a PV cell should consinder $R_{S}$ as shown in Fig (\re{figc3h3})

\begin{figure}[H]
\centering
\includegraphics[scale=1]{PVmm}
\caption{PV Cell Model with Series Resistance [5]}
\label{figc3h3} %% to refer use, \ref{}
\end{figure}

The voltage and current characteristics of the PV cell with a series resistance are given by the following equations,

\begin{equation}
\label{pv7}
V_{d}=V+I.R_{S}
\end{equation}\\
where,\\
$ R_{S} $ = Series resistance of the PV Cell $ (\Omega) $

\begin{equation}
\label{pv8}
I = I_{SC}-I_{0} \left\{\text{exp}\left[\frac{q(V+I.R_{S})}{kT} \right]-1 \right\}
\end{equation}

\begin{figure}[H]
\centering
\includegraphics[scale=1]{pv2}
\caption{Effect of Series Resistance on I-V Curve [5]}
\label{figc3h222} %% to refer use, \ref{}
\end{figure}

The Fig (\ref{figc3h222}) shows the effect of series resistance on the I-V curve of the PV cell. It can be observed that the series resistance reduces the voltage available at the load by the factor of $IR_{S}$.

\subsection{Complete PV Cell Model}
\
\
\
\
The complete PV cell model as shown in Fig (\ref{figc3h333}) includes the both the parallel as well as the series resistance. This model of the PV cell is highly accurate.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{pv3}
\caption{Complete Model of PV Cell [5]}
\label{figc3h333} %% to refer use, \ref{}
\end{figure}

The load current equation for this model is given by the following equation,

\begin{equation}
\label{pv10}
I_{SC}=I+I_{d}+I_{P}
\end{equation}\\
where,\\
$ I_{P} $ = Current in the parallel branch of the PV Cell $ (A) $\\

The effect of series resistance is given by the following equation,

\begin{equation}
\label{pv11}
V=V_{d}-IR_{S}
\end{equation}

The combined effect of the series and parallel resistances is given in the following equation,

\begin{equation}
\label{pv9}
I = I_{SC}-I_{0} \left\{\text{exp}\left[\frac{q(V+I.R_{S})}{kT} \right]-1 \right\}-\left(\frac{V+I.R_{S}}{R_{P}}\right)
\end{equation}

\subsection{I-V Curve}
\
\
\
\
Fig (\ref{figc3h5}) shows the I-V curve of the PV cell. The I-V curve helps us identify the key parameters of the PV cell. On the horizontal axis we find open-circuit voltage $(V_{OC})$ when current is zero, and on the vertical axis we find the short-circuit current $(I_{SC})$ when the voltage is zero; at both these points the power delivered by the PV cell is zero as either voltage or current are zero $(P=VI)$.

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{PVivp [5]}
\caption{PV Cell I-V Curve}
\label{figc3h5} %% to refer use, \ref{}
\end{figure}

The maximum power delivered is obtained at the knee of the I-V curve, the point is called as the maximum power point (MPP). The voltage and current at the MPP are represented as $V_{m}$ and $I_{m}$. The I-V curve summarizes the entire performance characteristic of the PV cell. Any other point on the I-V curve is represented as $V_{R}$ and $I_{R}$.

\subsection{Effect of Insolation and Temperature on I-V Curve}
\
\
\
\
\
The Fig (\ref{figc3h6}) shows the PV cell curves for two different values of insolation. We observe that the short-circuit current is directly proportional to insolation, and it changes linearly with insolation. But, the open-circuit voltage is inversely proportional to the insolation, and it changes modestly with insolation as it follows a logarithmic relationship. Hence, as insolation increases the power output from the PV cell increases.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{PVinso}
\caption{Effect of Insolation on I-V Curve [5]}
\label{figc3h6} %% to refer use, \ref{}
\end{figure}

The Fig (\ref{figc3h7}) shows the PV cell curves for two different values of temperature. We observe that as temperature increases the open-circuit voltage decreases considerably, while the short-circuit current increases very slightly. Hence, the power output of PV cell increases on a clear and cold day.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{PVtemp}
\caption{Effect of Temperature on I-V Curve [5]}
\label{figc3h7} %% to refer use, \ref{}
\end{figure}

The cell temperature depends not only on ambient temperature; but also on insolation as small fraction of insolation hitting the cell is converted to electricity, and the rest is converted to heat. Hence, manufacturers of the PV cells provide clients with a normal operating cell temperature (NOCT); it is the temperature in the cell when the ambient temperature is $20^{\circ} \text{C}}$, solar irradiance is $0.8 \  \text{kW/m}^{2}$, and windspeed is 1 m/s. This value helps in accounting the changes in the PV cell performance with temperature. The cell temperature can be calculated using the following equation,

\begin{equation}
\label{tefpv}
T_{{cell}}=T_{{amb}}+\left(\frac{NOCT-20^{\circ}}{0.8}\right)
.\ S
\end{equation}

\newpage

\section{Cells, Modules and Arrays}
\
\
\
\
The individual cell with its small voltage of 0.5 V cannot be used alone for producing power for everyday applications. Hence, to increase the power output, a number of cells are connected together in series and parallel to form a module, which is encased in tough weather-resistant packages. Usually 36 cells are connected in series to give a module with voltage of 12 V and the number of parallel strings can be adjusted according to the amount of power to be generated from a module. Also, there are large modules with 72 cell connected in series giving a voltage of 72 V.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{pv4}
\caption{PV - Cell, Module and Array [5]}
\label{figc3h444} %% to refer use, \ref{}
\end{figure}

To increase the power generation capacity further, modules can be connected in series to increase voltage and a number of similar parallel strings can be connected to increase the current. Such a combination of modules is called as an array.

The eq (\ref{mod1}) gives the voltage equation for a module, where $n$ is the number of cells connected in series.

\begin{equation}
\label{mod1}
V_{{module}}=n(V_{d}-IR_{S})
\end{equation}\\
where,\\
$ V_{{module} $ = Total voltage of a PV Module $ (V) $ \\
$ n $ = Total number of PV Cells in one string in the PV Module  \\

From Fig (\ref{figc3h555}) we observe that as the number of cells in series in a module increase, the open-circuit voltage increases. But, the short-circuit current remains the same, hence the MPP has horizontal movement; and power output of the module increases

\begin{figure}[H]
\centering
\includegraphics[scale=1]{pv5}
\caption{Effect of Series connected modules on I-V Curve [5]}
\label{figc3h555} %% to refer use, \ref{}
\end{figure}

The eq (\ref{mod2}) gives the current equation for a module, where $p$ is the number of strings in the module.

\begin{equation}
\label{mod2}
I_{{module}}=p(I_{SC}-I_{d}-I_{P})
\end{equation}\\
where,\\
$ I_{{module}} $ = Total current of the PV Module $ (A) $ \\
$ p $ = Total number of parallel strings of PV Cells in the PV Module\\

From Fig (\ref{figc3h666}) we observe that as the number of strings in a module increase, the short-circuit current increases. But, the open-circuit voltage remains the same, hence the MPP has a vertical movement; and power output of the module increases.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{pv6}
\caption{Effect of Parallel connected modules on I-V Curve [5]}
\label{figc3h666} %% to refer use, \ref{}
\end{figure}

\newpage

\section{Effect of Shading on PV Modules}
\
\
\
\
To understand the concept of shading in the PV cells let us consider the Fig (\ref{figc3h888}). It shows a string of $n$ cells, figure on the left shows condition when all the cells are in the sun. This will give us the usual behaviour of the PV module, where the major component of the current from the preceding cells will pass through the $I_{SC}$ current source branch.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{shading1}
\caption{PV module with \textit{n} Cells - top cell in sun, or in shade [5]}
\label{figc3h888} %% to refer use, \ref{}
\end{figure}

But, the figure on the right shows the condition when one cell from the string is shaded (it does not produce current). Here we can see that the path taken by the current from the preceding cells in the string will have to pass through the branch of parallel resistance, which causes a large voltage drop as the value of parallel resistance is high. This drop in voltage reduces the power output of the module severely.\\

The output voltage $(V_SH)$ of the $n$ celled shaded module is given in the following equation,

\begin{equation}
\label{shade1}
V_{SH}=V_{n-1}-I(R_{P}+R_{S})
\end{equation}

Output voltage across $n-1$ cells $(V_{n-1})$ if $V$ is the output voltage of $n$ cells is given by,

\begin{equation}
\label{shade2}
V_{n-1}=\left(\frac{n-1}{n}\right)V
\end{equation}\\
where,\\
$ n $ = Total number of cells ahaded $  $ \\
$ V_{n-1} $ = Output voltage across $ n-1 $ cells $ (V) $ \\
$ \triangledown V $ = Voltage drop caused by shaded cell $ (V}) $

Putting eq (\ref{shade2}) in eq (\ref{shade1}), we get;

\begin{equation}
\label{shade3}
V_{SH}=\left(\frac{n-1}{n}\right)V-I(R_{P}+R_{S})
\end{equation}\\
where,\\
$ V_{SH} $ = Output voltage of a $\text{n celled}$ shaded module $ (V) $ \\

Hence, the drop in voltage $(\triangledown)V$ at any given current $I$, caused by shaded cell is given by the following equation,

\begin{equation}
\label{shade4}
\triangledown V=\frac{V}{n}-I(R_{P}+R_{S})
\end{equation}\\
where,\\
$ \triangledown V $ = Voltage drop caused by shaded cell $ (V}) $ \\

The above equation can be modified as follows, as parallel resistance is very large as compared to the series resistance. Hence, neglecting the effect of series resistance, we get the following equation,

\begin{equation}
\label{shade4}
\triangledown V=\frac{V}{n}-IR_{P}
\end{equation}

The Fig (\ref{figc3h999}) shows the comparison of I-V curves for an un-shaded and a shaded module. We can observe that in the module with shading both the short-circuit current and open-circuit voltage are reduced and the curve assumes a linear shape, which drastically reduces the power output from the module.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{shading2}
\caption{Effect of shading one cell in \textit{n} cell module [5]}
\label{figc3h999} %% to refer use, \ref{}
\end{figure}

\newpage

\subsection{Bypass Diode}
\
\
\
\
In order to overcome the problem of shading, bypass diodes are used as shown in Fig (\ref{figc3h100}). The figure on the left in Fig (\ref{figc3h100}) shows a PV cell which is un-shaded, here the bypass diode will be reverse biased as the PV ell produces reverse voltage across the bypass diode; hence, no current follow through the bypass diode when the cell is un-shaded.

\begin{figure}[H]
\centering
\includegraphics[scale=1]{bydiode1}
\caption{Mitigation of shading problem with Bypass Diode - In sunny cell bypass diode is cut-off, in shaded cell it conducts [5]}
\label{figc3h100} %% to refer use, \ref{}
\end{figure}

The figure in right in Fig (\ref{figc3h100}) shows a shaded PV cell with a bypass diode. As the cell is shaded the output voltage of the cell is reduced drastically, moreover the current from the preceding cells rather than passing through the parallel resistance of the shaded cell causing large voltage drop flows through the bypass diode as it gets forward biased. Hence, the bypass diode reduces the amount of voltage reduced due to shading(voltage drop in the bypass diode is about 0.5 V).

\begin{figure}[H]
\centering
\includegraphics[scale=1]{bydiode2}
\caption{Effect of Bypass Diode on I-V Curve [5]}
\label{figc3h190} %% to refer use, \ref{}
\end{figure}

The Fig (\ref{figc3h190}) shows the comparison of I-V curves for shaded cell, un-shaded cell and shaded cell with bypass diode. We observe that the bypass diode improves the performance of the shaded cell by increasing the MPP point; however, it does not completely eliminate the effect of shading.

\subsection{Blocking Diode}
\
\
\
\
Blocking diodes as shown in Fig (\ref{figc3h200}) are connected at the top of each string of an array. The blocking diode will conduct only when the source of current is the string as it is in forward biased mode. But, when the string malfunctions or is shaded it acts as a load and draws current, the blocking diode becomes reverse biased and prevents any flow of current to the string. Hence a blocking diode helps improve the performance of a PV array.

\begin{figure}[H]
\centering
\includegraphics[scale=0.75]{bldiode1}
\caption{Blocking Diode prevents reverse flow of current through PV modules [5]}
\label{figc3h200} %% to refer use, \ref{}
\end{figure}

\newpage

\section{Results of PV-IV Curve App}
\
\
\
\
The Table (\ref{tabc3h1})gives the information of the different PV modules, which are used to simulate P-V and I-V curves from the PV-IV Curve App.

\begin{table}[htbp]
  \centering
  \caption{PV Module Information}
    \begin{tabular}{|l|c|c|c|c|}
    \hline
    \textbf{TYPE} & \textbf{Poly} & \textbf{Mono} & \textbf{Cdte} & \textbf{A-si} \bigstrut\\
    \hline
    \textbf{MAKE} & Lanco & Lanco & First Solar & Du-Pont \bigstrut\\
    \hline
    \textbf{Crys/TF} & Crys & Crys & TF & TF \bigstrut\\
    \hline
    \textbf{Pmpp (W)} & 235 & 250 & 85 & 107 \bigstrut\\
    \hline
    \textbf{Vmpp (V)} & 29.56 & 31.15 & 46.4 & 74 \bigstrut\\
    \hline
    \textbf{Impp (A)} & 7.95 & 8.034 & 1.83 & 1.44 \bigstrut\\
    \hline
    \textbf{Voc (V)} & 37.17 & 38.04 & 60.5 & 99 \bigstrut\\
    \hline
    \textbf{Isc (A)} & 8.4 & 8.712 & 1.94 & 1.81 \bigstrut\\
    \hline
    \textbf{Kv} & -0.31 & -0.33 & -0.27 & -0.3 \bigstrut\\
    \hline
    \textbf{Ki} & 0.06 & 0.036 & 0.04 & 0.09 \bigstrut\\
    \hline
    \textbf{Kp} & -0.43 & -0.47 & -0.25 & -0.25 \bigstrut\\
    \hline
    \end{tabular}%
  \label{tabc3h1}%
\end{table}%
\\
Where Crys-Crystalline, TF-Thin Film, mmp-Maximum Power Point, oc-Open Circuit, sc-Short Circuit, P-Power, V-Voltage, I-Current and Kv, Ki, Kp are the temperature co-efficients of voltage, current and power respectively.\\

The PV and IV curves are plotted at different temperatures (-25, 0, 25, 50 and 75 ºC) and different irradiances ( 200, 400, 600, 800 and 1000 W/m^{2}) are as follows,

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{Poly_Irradiance}
\caption{Polycrystalline Solar PV module I-V and P-V Curves at different Irradiances}
\label{figc3h15} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{Poly_Temperature}
\caption{Polycrystalline Solar PV module I-V and P-V Curves at different Temperatures}
\label{figc3h16} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{Mono_Irradiance}
\caption{Monocrystalline Solar PV module I-V and P-V Curves at different Irradiances}
\label{figc3h17} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{Mono_Temperature}
\caption{Monocrystalline Solar PV module I-V and P-V Curves at different Temperatures}
\label{figc3h18} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{A-si_Irradiance}
\caption{A-Si Thin Film Solar PV module I-V and P-V Curves at different Irradiances}
\label{figc3h19} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{A-si_Temperature}
\caption{A-Si Thin Film Solar PV module I-V and P-V Curves at different Temperatures}
\label{figc3h20} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{CDTE_Irradiance}
\caption{CDTE Thin Film Solar PV module I-V and P-V Curves at different Irradiances}
\label{figc3h21} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{CDTE_Temperature}
\caption{CDTE Thin Film Solar PV module I-V and P-V Curves at different Temperatures}
\label{figc3h22} %% to refer use, \ref{}
\end{figure}
The effect of decreasing irradiance with temperature at kept constant at 25ºC can be observed in Fig (\ref{figc3h15}, \ref{figc3h17}, \ref{figc3h19}, \ref{figc3h21}). It is clearly seen that the photovoltaic module current output and power are directly proportional to the irradiance level, however the module voltage increases by very small values with decreasing irradiance levels. This concurs with the theory that module current is a direct function of the solar irradiance.\\

The effect of increasing temperature with irradiance level kept constant at 1000 W/m2 can be observed in Fig (\ref{figc3h16}, \ref{figc3h18}, \ref{figc3h20}, \ref{figc3h22}). It is clearly seen that the module voltage and power output are inversely proportional to the temperature, however the module current increases very slightly with increase in temperature. This concurs with theory that diode voltage is inversely proportional to temperature.

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{Poly_Shading_WithoutByPassDiode}
\caption{Polycrystalline Solar PV moduleP-V and I-V curves for Shading without Bypass Diode and at different number of shaded cells}
\label{figc3h23} %% to refer use, \ref{}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{Poly_Shading_With_ByPassDiode}
\caption{Polycrystalline Solar PV moduleP-V and I-V curves for Shading with Bypass Diode and at different number of shaded cells}
\label{figc3h24} %% to refer use, \ref{}
\end{figure}

In Fig (\ref{figc3h23}) we can observe that as the number of single cells within a module being shaded increase, both the PV and IV curves start becoming flat. Hence, shading of even a single cell almost reduces the module power by half and this can be attributed to the voltage loss in the series and parallel equivalent resistances due to the flow of the module output current.\\

To mitigate the shading effect, bypass diodes are used, which allow for alternative path to the current to flow which would have otherwise flowed through Rp and Rs causing large voltage drops, which consequently causes large reductions in output power. Ideally for the best shading effect mitigation, each cell within a module should be supplied with its own bypass diode, but as this would be escalate the cost and manufacturing complexity; hence optimal number of cell per bypass diodes have to selected. In Fig (\ref{figc3h24}) it can be observed that as the number of cell per bypass diode increase the performance of the module deteriorates.\\

\newpage

\section{Variables Affecting Solar PV Cell Output}
\
\
\
\
From the discussions in the previous sections, it is clear that the performance of a PV Cell depends on the following four variable;

\begin{enumerate}
\item Insolation
\item Temperature
\item Wind Speed
\item Cloud Cover
\end{enumerate}

The Fig (\ref{mfigc3h1}) shows pictures of some instruments which help in measuring the above mentioned variables.

\begin{figure}[H]
    \centering
    \begin{subfigure}[b]{0.45\textwidth}
       \centering
\includegraphics[scale=0.5]{Pyranometer}
\caption{Pyranometer}
\label{figc3h8}
    \end{subfigure}
    \hfill%% Fill Horizontal Space between two Figures
        \begin{subfigure}[b]{0.45\textwidth}
       \centering
\includegraphics[scale=0.5]{Pyrheliometer}
\caption{Pyrheliometer}
\label{figc3h9} %% to refer use, \ref{}
    \end{subfigure}
    \caption{}
    \label{}
\end{figure}

\begin{figure}[H]
    \centering
    \begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[scale=0.5]{Anemometer}
\caption{Anemometer}
\label{figc3h10} %% to refer use, \ref{}
    \end{subfigure}
    \hfill%% Fill Horizontal Space between two Figures
        \begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[scale=0.5]{Temperature}
\caption{TEmperature Sensor}
\label{figc3h11} %% to refer use, \ref{}
    \end{subfigure}
    \caption{Weather Variables Measurement Instruments}
    \label{mfigc3h1}
\end{figure}

The Fig (\ref{figc3h8}) shows a Pyranometer, it mmeasures the Global Horizontal Irradiance. The Fig (\ref{figc3h9}) shows a Pyrheliometer, it measures the Direct Beam Irradiance of the sun. The Fig (\ref{figc3h10}) shows an Anemometer, which measures the wind speed. The Fig (\ref{figc3h11}) shows a temperature sensor. Also, there is a sky imager which can measure the cloud cover.

\section{PV Cell Technologies}
\
\
\
\
There are majorly three PV technologies, Mono-Crysalline, Poly-Crystalline and Thin Film which are commercially widely used in Solar PV Plants.

\subsection{Mono-Crystalline PV}

\begin{figure}[H]
\centering
\includegraphics[scale=2]{PVmono}
\caption{Mono-Crystalline Cell and its Crystal}
\label{figc3h12} %% to refer use, \ref{}
\end{figure}

It is manufactured by slicing thin wafers from a single long Silicon crystal rod (shown in the figure at the right of Fig (\ref{figc3h12} ) using Czochralski process. It is the most expensive of the three technologies. It has an efficiency of 15-20\%, and has the highest density of power production (area/power is lowest). It has a market share of 36%.

\subsection{Poly-Crystalline PV}

\begin{figure}[H]
\centering
\includegraphics[scale=0.5]{PVPoly}
\caption{Poly-Crystalline Cell and its Crystal}
\label{figc3h13} %% to refer use, \ref{}
\end{figure}

It is manufactured from the metallurgical grade silicon (shown in the figure at the right of Fig \ref{figc3h13} ) by a chemical process, called as Siemens process. It is the moderately priced. It has an efficiency of 13-16\%, and has the moderate density of power production (area/power is lower than Mono-Crystalline).

\subsection{Thin Film PV}

\begin{figure}[H]
\centering
\includegraphics[scale=2.5]{PVthin}
\caption{Thin Film Sheet}
\label{figc3h14} %% to refer use, \ref{}
\end{figure}

It is manufactured by depositing one or more thin layes of PV material on a substrate such as glass, plastic or metals. The  Fig (\ref{figc3h13}) shows the Thin Film PV sheet. It is the least expensive of the three technologies. But, has has an efficiency of 7-13\%, and has the lowest density of power production (area/power is lowest).