\chapter{Elements of Probability}
\label{Appendix_A}
\section{Basic Definitions}
	\begin{definition}
		A probability measure $\mathbb{P}$ on a measurable space $(\Omega, \mathcal{F})$ is a function from $\mathcal{F}$ to $[0, 1]$ such that
			\begin{itemize}
				\item
				$\mathbb{P} (\emptyset) = 0$, and $\mathbb{P} (\Omega) = 1$.
				\item
				If $\{ A_n \}_{n \geq 1} \in \mathcal{F}$ and $A_i \cap A_j \neq \emptyset$ if $i \neq j$, then $\mathbb{P} (\cup^{\infty}_{n=1} A_n) = \sum^{\infty}_{n = 1} \mathbb{P} (A_n)$.
			\end{itemize}
	\end{definition}

	\noindent A $\sigma$-algebra on a set $X$ is a collection of subsets of $X$ that includes the empty subset and is closed under complement and under countable unions. Denote $\sigma (D) = \cap \{ H : H \text{ is a } \sigma \text{-algebra of } \Omega, D \subseteq H \}$. We call $\sigma (D)$ a $\sigma$-algebra generated by $D$.

	\begin{definition}
		A triple  $(\Omega, \mathcal{F}, \mathbb{P})$ is called a probability space if
		\begin{itemize}
			\item
			$\Omega$ is a sample space which is a collection of all samples.
			\item
			$\mathcal{F}$ is a $\sigma$-algebra on $\Omega$.
			\item
			$\mathbb{P}$ is a probability measure on $(\Omega, \mathcal{F})$.
		\end{itemize}
	\end{definition}

	\noindent On a given probability space $(\Omega, \mathcal{F}, \mathbb{P}) (\Omega = \mathbb{R})$, if a cumulative distribution function of a random variable $X$ is normal, i.e.,
	\begin{align}
		\mathbb{P} (X < x) = \displaystyle \int_{-\infty}^{x} \frac{1}{ \sigma \sqrt{2 \pi} } e^{-\frac{(y - \mu)^2}{2 \sigma^2}} dy, \hspace{2mm} \sigma > 0,
	\end{align}
	then the random variable $X$ is called a Gaussian (normal) random variable on the probability space $(\Omega, \mathcal{F}, \mathbb{P})$. Here $X$ is completely characterized by its mean $\mu$ and its standard deviation $\sigma$. We denote $X \sim \mathcal{N} (\mu, \sigma^2)$. The probability density function of $X$ is
	\begin{align*}
		p(x) = \frac{1}{\sigma \sqrt{2 \pi}} e^{-\frac{(x - \mu)^2}{2 \sigma^2}}.
	\end{align*}

	\noindent When $\mu = 0$ and $\sigma = 1$, we call $X$ a standard Gaussian (normal) random variable.

	\begin{definition}
		A probability space $(\Omega, \mathcal{F}, \mathbb{P})$ is said to be a complete probability space if for all $B ∈\in \mathcal{F}$ with $\mathbb{P} (B) = 0$ and all $A \subseteq B$ one has $A \in \mathcal{F}$.
	\end{definition}

	\begin{definition}
		If $(\Omega, \mathcal{F}, \mathbb{P})$ is a given probability space then a function $Y : \Omega \rightarrow \mathbb{R}^n$ is called $\mathcal{F}$-measurable if $Y^{-1} (U) = \{ w \in \Omega : Y(w) \in U \} \in \mathcal{F}$ holds for all open sets $U \in \mathbb{R}^n$. If $X : \Omega \rightarrow \mathbb{R}^n$ is a function, then $\sigma (X)$ is the smallest $\sigma$-algebra on $\Omega$ containing all the sets $X^{-1} (U)$ for all open sets $U$ in $\mathbb{R}^n$.
	\end{definition}

	\begin{definition}
		Suppose that $(\Omega, \mathcal{F}, \mathbb{P})$ is a given complete probability space. A random variable $X$ is an $\mathcal{F}$-measurable function $X : \Omega \rightarrow \mathbb{R}^n$.
	\end{definition}

	\noindent Its well known that every random variable induces a probability measure $\mu_X$ (distribution of $X$) on $\mathbb{R}_n$ given by
	\begin{align*}
		\mu_X (B) = \mathbb{P} (X^{-1} (B)).
	\end{align*}
	If $ \int_{\Omega} | X(w) | d \mathbb{P} (w) < \infty$, the expectation of $X$ w.r.t. $\mathbb{P}$ is defined by
	\begin{align*}
		\mathbb{E} [X] = \int_{\Omega} X(w) d \mathbb{P} (w) = \int_{\mathbb{R}^n} x d \mu_X (x).
	\end{align*}
	Also the $p$-th moment of $X$ is defined as (if the integrals are well defined)
	\begin{align*}
		\mathbb{E} [X^p] = \int_{\Omega} X^p d \mathbb{P} (w) = \int_{\mathbb{R}^n} x^p d \mu_X (x).
	\end{align*}
	The centered moments are defined by $\mathbb{E} \left[ |X - \mathbb{E}[X]| \right]$, $p = 1, 2, \dots, $. When
	$p = 2$, the centered moment is also called the variance. \\

	\begin{definition}
		Let $(\Omega, \mathcal{F}, \mathbb{P})$ be a probability space and let $T \subseteq \mathbb{R}$ be
		time. A collection of random variables $X_t$ , $t \in T$ with values in $\mathbb{R}$ is called a
		stochastic process. If time is an interval, $\mathbb{R}^+$ or $\mathbb{R}$, it is called a stochastic process with continuous time. For any fixed $w \in \Omega$, one can regard $X_t (w)$ as a function of
		$t$ (called a sample function of the stochastic process).
	\end{definition}

	\noindent On a probability space $(\Omega, \mathcal{F}, \mathbb{P})$, a filtration refers to an increasing sequence of $\sigma$-algebras:
	\begin{align*}
		\mathcal{F}_0 \subseteq \mathcal{F}_1 \subseteq \mathcal{F}_2 \subseteq \cdots \subseteq \mathcal{F}_n \subseteq \cdots .
	\end{align*}

	\noindent A natural filtration (w.r.t. $X$) is the smallest $\sigma$-algebra that contains
	information of $X$. It is generated by $X$ and $\mathcal{F}^X_n = \sigma(X_1, \dots, X_n)$ with $\mathcal{F}^X_0 = \{\emptyset, \Omega \}$. If $\lim_{n \rightarrow \infty} \mathcal{F}_n \subseteq \mathcal{F}$, then we call $(\Omega, \mathcal{F}, \{ \mathcal{F}_n \}_{n \geq 1}, \mathbb{P})$ a filtered probability space. A stochastic process $\{X_n \}$ on a filtered probability space is an adapted process if $X_n$ is $\mathcal{F}_n$-measurable for each $n$.

	\begin{definition}
		A family of sub-$\sigma$-algebras $\mathcal{F}_t \subseteq \mathcal{F}$ indexed by $t \in [0, \infty)$ is called a filtration if it is increasing $\mathcal{F}_s \subseteq \mathcal{F}_t$ when $0 \leq s \leq t < \infty$.
	\end{definition}

	\begin{definition}
		A collection of random variables is called a Gaussian process, if the joint distribution of any finite number of its members is Gaussian. In other words, a Gaussian process is a $\mathbb{R}^d$-valued stochastic process with continuous time (or with index) $t$ such that $\left(X(t_0), X(t_1), \dots, X(t_n) \right)^T$ is a $(n+1)$-dimensional Gaussian random vector
		for any $0 \leq t_0 < t_1 < \cdots < t_n$. The Gaussian process is denoted as $X = \{X(t)\}_{t \in I}$ where $I$ is a set of indexes.
	\end{definition}

	\begin{definition}
		\label{brownian_motion}
		 A continuous time stochastic process $W(t)$ is called a standard Brownian motion if
		\begin{itemize}
			\item
			$W(t)$ is almost surely continuous in $t$, and $W(0) = 0$.
			\item
			$W(t)$ has independent increments $W(t_{i+1}) - W(t_i)$ for all $t_n \geq 0$, $i = 0, 1, \dots, n$.
			\item
			$W(t) - W(s) \sim \mathcal{N} (0, t-s)$, i.e., obeys the normal distribution with mean zero and variance $t - s$.
		\end{itemize}
	\end{definition}

	\noindent Set $x \in D \subset \mathbb{R}^d$, we define infinite dimensional Gaussian processes as follows
	\begin{align*}
		W^Q (x, t) = \displaystyle \sum^{\infty}_{j = 1} \sqrt{q_j} e_j (x) W_j (t),
	\end{align*}
	where $W_j (t)$ are mutually independent Brownian motions. Here $q_j \geq 0$, $j \in \mathbb{N}^d$ and $\{ e_j (x) \}$ is an orthonormal basis in $L^2 (D)$.  The following expansion is usually considered in literature:
	\begin{align*}
		\dot{W}^Q (x, t) = \displaystyle \sum^{\infty}_{j = 1} \sqrt{q_j} e_j (x) \dot{W}_j (t).
	\end{align*}
	where $\dot{W}_j (t) =\frac{d}{dt} W$, is formally the first-order derivative of $W_j (t)$ in time. When $q_j = 1$ for all $j$, we have a space-time white noise, and if $\sum^{\infty}_{j = 1} \sqrt{q_j}$ is called a $Q$-Wiener process. \\

	\noindent The Brownian motion and white noise can also be defined in terms of orthogonal expansions. Suppose that $\{e_j (t)\}_{j \geq 1}$ is a complete orthonormal system in $L^2 ([0, T ])$, then the Brownian motion $W(t)$ can be defined by
	\begin{align}
	    W(t) = \displaystyle \sum_{j=1}^{\infty} \beta_j \int_{0}^{t} e_j (s) ds, \hspace{2mm} t \in [0, T],
	\end{align}
	where $\beta_j$ are mutually independent standard Gaussian random variables for each $j$, and it can be also checked that is indeed a standard Brownian motion. Correspondingly, the white noise is defined by
	\begin{align}
	    \dot{W}(t) = \displaystyle \sum_{j=1}^{\infty} \beta_j e_j (t), \hspace{2mm} t \in [0, T].
    \end{align}

	\begin{definition}
		\label{cylindrical}
		Let $\{e_j\}_{j \geq 1}$ be a complete orthonormal  system of a separable Hilbert space $\mathcal{H}$, and $T \in \mathbb{R}^+$, and $\{\beta_j (t)\}_{j \geq 1}$ be an independent and identically distributed sequence of Brownian Motions. Then a cylindrical Wiener process $W$ in $\mathcal{H}$ is given by
		\begin{align*}
			W(t) = \displaystyle \sum_{j=1}^{\infty} \beta_j e_j (t)
		\end{align*}
	\end{definition}

	\section{Some Important Results in Probability Spaces}

	It is well known that the Hermite Polynomials $\{P_k (\dot) \}_{k \in \mathbb{N}}$ with $P_0 = 1$ is a complete orthonormal system for $L_2 (\mathbb{R}, \mu_1 (dx))$ with $\mu_1 (dx) = \frac{1}{\sqrt{2 \ pi}} e^{- \frac{x^2}{2}} dx$, which are defined by
	\begin{align}
		\label{hermite_polynomials}
		P_k(x) = \frac{(-1)^k}{(k!)^{1/2}} e^{\frac{x^2}{2}} \frac{d^k}{dx^k} e^{-\frac{x^2}{2}}, \hspace{3mm} x \in \mathbb{R}
	\end{align}

	A functional $\Phi: \mathcal{H} \longrightarrow  \mathbb{R}$, is said to be a smooth simple functional (or a cylinder functional) if there exists a $C^{\infty} $-function $\varphi$ on $\mathbb{R}^n$ and $n$-continuous linear functional $l_1 ,\cdots ,l_n$ on $\mathcal{H}$ such that for $h \in \mathcal{H}$
	\begin{align*}
		\Phi(h) = \phi(h_1, \cdots, h_n) \hspace{2mm} \text{where} \hspace{2mm} h_i = l_i (h), \hspace{2mm} i = 1, \cdots, n.
	\end{align*}

	Let $\mathbb{H} = L_2 (\mathcal{H}, \mu)$ denote the Hilbert space of Borel measurable functionals on the probability space with inner product
	\begin{align}
		\label{Inner_Functionals}
		\langle \Phi, \Psi \rangle_{\mathbb{H}} = \displaystyle \int_{\mathcal{H}} \Phi (v) \Psi (v) \mu (dx), \hspace{2mm} \Phi, \Psi \in \mathbb{H},
	\end{align}
	and the norm $\| \Phi \|_{\mathbb{H}} = \langle \Phi, \Phi\rangle_{\mathbb{H}}^{1/2}$. In $\mathcal{H}$ we choose a basis system $\{\varphi_k \}$ such that $\varphi_k \in \mathcal{H}$.\\

	Let $\Lambda$ an operator such that $Tr < +\infty$. We will denote as $\mathcal{H}_0$ the Hilbert subspace of $\mathcal{H}$ with inner product $\langle g, h \rangle_0 = \langle \Lambda^{1/2} g, \Lambda^{1/2} h \rangle_{\mathcal{H}}$ for $g, h \in \Lambda^{1/2} \mathcal{H}$, which is the completion of $\Lambda^{1/2} \mathcal{H}$ with respect to the norm $\| g \|_0 = \langle g, g \rangle^{1/2}$, and also is dense in $\mathcal{H}$. Then, by using the above can be defined The Hermite functional as follows
	\begin{align}
	\label{hermite_funcionals}
		H_n(h) = \prod_{i=1}^{\infty} P_{n_i} (l_i (h)), h \in \mathcal{H}_0 , n \in J
	\end{align}
	with
	\begin{equation*}
		l_i (h) = \left\langle h, \Lambda^{-1/2} \varphi_i \right\rangle_{\mathcal{H}}, \hspace{3mm} i = 1,2 \cdots
	\end{equation*}
	and the set $\mathcal{J}$ is given by
	\begin{align}
	\label{Conjunto_J}
		\mathcal{J} = \{\alpha = (\alpha_i,i \geq 1) | \alpha_i \in \mathbb{N}\cup {0}, |\alpha|:= \displaystyle \sum _{i = 0}^{\infty}\alpha_i < \infty\}
	\end{align}

	\begin{lemma}
	\label{dense}
		For $h \in \mathcal{H}$ let $l_i (h) = (h, \Lambda^{-1/2} \varphi_i )_{\mathcal{H}}$, $i=1, 2, \cdots$. Then the set $\{H_n \}$ of all Hermite polynomials on $\mathcal{H}$ forms a complete orthonormal system for $\mathbb{H}$. Hence the set of all functionals are dense in $\mathbb{H}$. Moreover, we have the direct sum decomposition:
		\begin{align*}
		\mathbb{H} = \displaystyle \bigoplus^{\infty}_{j=0} K_j,
		\end{align*}
		where $K_j$ is the subspace of $\mathbb{H}$ spanned by $\{H_n : |n| = j \}$. This result can be found in \cite{DAPRATO1994}.
	\end{lemma}

	\begin{lemma}
		\label{eigen}
		Let $H_n (h)$ be a Hermite polynomial functional given by (\ref{hermite_funcionals}), and suppose that the operator $-A$ have eigenfunctions $e_k$ with eigenvalues $\lambda_k$. Then the operator given in (\ref{operator_L}) satisfies the following
		\begin{align}
			\label{eigen_lambda_kolmo}
			\mathcal{L} H_n (h) = - \lambda_n H_n (h)
		\end{align}
		for any $n \in \mathcal{J}$ and $H_n \in \mathcal{H}$, where
		\begin{align*}
			\lambda_n = \displaystyle \sum_{k=1}^{\infty} n_k \lambda_k
		\end{align*}
	\end{lemma}


\subsection{Surface area}
Let $S$ be a surface parameterized by $x$ and $y$.
That is, let $S=(x,y,z)$ where $z=f(x,y)$.
The tangent lines at a point on $S$ form a tiny parallelogram.
The area $a$ of the parallelogram is given by the magnitude of the cross product.
$$a=\left|{\partial S\over\partial x}\times{\partial S\over\partial y}\right|$$
By summing over all the parallelograms we obtain the total surface area $A$.
Hence
$$A=\int\!\!\!\int dA=\int\!\!\!\int a\,dx\,dy$$
The following example computes the surface area of a unit disk
parallel to the $xy$ plane.

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
z = 2
S = (x,y,z)
a = abs(cross(d(S,x),d(S,y)))
defint(a,y,-sqrt(1-x^2),sqrt(1-x^2),x,-1,1)
\end{Verbatim}

$\displaystyle \pi$

The result is $\pi$, the area of a unit circle, which is what we expect.
The following example computes the surface area of $z=x^2+2y$ over
a unit square.

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
z = x^2+2y
S = (x,y,z)
a = abs(cross(d(S,x),d(S,y)))
defint(a,x,0,1,y,0,1)
\end{Verbatim}

$\displaystyle \frac{3}{2}+\frac{5}{8}\log(5)$

The following exercise is from
{\it Multivariable Mathematics} by Williamson and Trotter, p. 598.
Find the area of the spiral ramp defined by
$$S=\begin{bmatrix}u\cos v\\\ u\sin v\\ v\end{bmatrix},\qquad 0\le u\le1,\qquad 0\le v\le3\pi$$
%The coordinates $x$, $y$ and $z$ are
%functions of the parameter space $(u,v)$.

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
x = u*cos(v)
y = u*sin(v)
z = v
S = (x,y,z)
a = abs(cross(d(S,u),d(S,v)))
defint(a,u,0,1,v,0,3pi)
\end{Verbatim}

$\displaystyle \frac{3}{2}\pi\log(1+2^{1/2})+\frac{3\pi}{2^{1/2}}$

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
float
\end{Verbatim}

$\displaystyle 10.8177$


\subsection{Matrix additon and multiplication}

\subsubsection{Matrix multiplication}

\(A=A^{mn}\)

\(B=B^{no}\)

\(C=C^{mo}=A.B\)

\(c_{ij}=\sum_{r=1}^na_{ir}b_{rj}\)

Matrix multiplication depends on the order. Unlike for real numbers,

\(AB\ne BA\)

Matrix multiplication is not defined unless the condition above on dimensions is met.

A matrix multiplied by the identity matrix returns the original matrix.

For matrix \(M=M^{mn}\)

\(M=MI^m=I^nM\)

\subsubsection{Matrix addition}

\(2\) matricies of the same size, that is with idental dimensions, can be added together.

If we have \(2\) matrices \(A^{mn}\) and \(B^{mn}\)

\(C=A+B\)

\(c_{ij}=a_{ij}+b_{ij}\)

An empty matrix with \(0\)s of the same size as the other matrix is the identity matrix for addition.

\subsubsection{Scalar multiplication}

A matrix can be multiplied by a scalar. Every element in the matrix is multiplied by this.

\(B=cA\)

\(b_{ij}=ca_{ij}\)

The scalar \(1\) is the identity scalar.


\subsection{Sampling from multi-variate normal distributions with arbitrary correlations}

The multi-variate distribution is given by:

\begin{equation}
p(\bar{x}) = {1\over{(2\pi)^{k/2}{|\tilde{C}|}^{1/2}}}\,{\exp{-{1\over{2}}{(\bar{x} - \bar{\mu})^T\tilde{C}^{-1}{(\bar{x} - \bar{\mu})}}}}
\end{equation}

If we write out the terms of the exponent $M \equiv (\bar{x} - \bar{\mu})^T\tilde{C}^{-1}(\bar{x} - \bar{\mu})$
we have:

\begin{equation}
M = {x_k}^2 C_{kk} - 2x_k\mu_kC_{kk} + 2\sum_{i \neq k}{x_k(x_i - \mu_i)C_{ki}} + C_{kk}B_k
\end{equation}

where $B_k/C_{kk}$ represents all terms that don't depend on $x_k$. If we rewrite this as:

\begin{eqnarray}
M &=& C_{kk}{x_k}^2 + C_{kk}x_k\left(2\sum_{i \neq k}{(x_i - \mu_i)C_{ki}/C_{kk} - 2\mu_k}\right) + C_{kk}B_k\\
  &=& C_{kk}{x_k}^2 + C_{kk}x_kA_k + C_{kk}B_k\\
  &=& C_{kk}\left({x_k}^2 + x_kA_k + A_k^2/4\right) + C_{kk}\left(B_k - A_k^2/4\right) \\
  &=& C_{kk}\left(x_k + A_k/2\right)^2 + C_{kk}\left(B_k - A_k^2/4\right)
\end{eqnarray}

we see that if $\mu_k^\prime \equiv -A_k/2$, the exponent can be written, up to a constant factor, as:

\begin{equation}
M_k = C_{kk}\left(x_k - \mu_k^\prime\right)^2.
\end{equation}

We see then that up to a normalization, the conditional distribution for
$x_k$, $p(x_k|\{x_{i\neq k}\})$ is simply given by a univariate gaussian
with:

\begin{eqnarray}
\mu_k^\prime &=& -A_k/2 \\
\sigma_k   &=& 1/\sqrt{C_{kk}}
\end{eqnarray}

Our prescription for generating samples from the joint distribution is
then to Gibbs sample from the univariate conditional distributions,
starting from a random point, and iterating each time from the
previous point.  The result is itself a Markov chain which
collectively represents an unbiased sample from the joint
distribution.


\subsection{Sets}
\begin{definition}
	A set $A$ is a collection of distinct elements. Those elements can be anything, like numbers, functions, and even other sets.
\end{definition}
We can define a set by giving its elements, like $A = \{-2, 5, 3\}$ or by describing its properties, like $A = \{x \mid x > 0\}$ where the vertical bar means ``such that''.
If an object $x$ is a member of the set $A$, we write $x\in A$.\bigskip

\noindent
A set $A$ is called a subset of a set $B$ if every element of $A$ is also an element of $B$.
We can write this as $A \subseteq B$.
For example, $\{7, 10, 16\} \subseteq \{5, 6, 7, 9, 10, 11, 16\}$.
Note that this relation can be strict if there exists at least one element in $B$ that is not also an element of $A$.
Some common sets and their informal definitions are given below:

\begin{table}[H]
	\centering
	\begin{tabular}{c|c|c}
		Set Name & Symbol & Informal Definition                                                                                \\ \hline
		Natural numbers & $\mathbb{N}$ & $\{1, 2, 3, \dots\}$           						                                                               \\
		Integers & $\mathbb{Z}$ & $\{\dots, -3, -2, -1, 0, 1, 2, 3, \dots\}$                                                                                \\
		Rational numbers & $\mathbb{Q}$ & $\{\frac{m}{n} \mid m,n \in\mathbb{Z}$ and $n \neq 0\}$                                                                       \\
		Real numbers & $\mathbb{R}$ & Any number on the number line\footnote{Sadly, there is no way to give a stronger formal definition without higher mathematics.}   \\
	\end{tabular}
\end{table}

This means that $\mathbb{N} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R}$.\bigskip

\noindent
There are several common operations that can be performed on sets.
The union $A \cup B$ of two sets $A$ and $B$ is the set of all elements that are elements of $A$ or of $B$.
Similarly, the intersection $A \cap B$ of two sets $A$ and $B$ is the set of all elements that are also elements of both $A$ and $B$.
\begin{example}
	If $A = \{\sqrt{2}, 2, 5, 8\}$ and $B = \{-9, 8, 2.3\}$, what are $A \cup B$ and $A \cap B$?
\end{example}
\begin{answer}
	To find the union, we combine the sets, making sure to include any repeated element only once:
	\begin{equation*}
		A \cup B = \{-9, \sqrt{2}, 2, 2.3, 5, 8\}.
	\end{equation*}
	Then, since the only element both sets share is 8, we also have
	\begin{equation*}
		A \cap B = \{8\}.
	\end{equation*}
\end{answer}

\subsection{Intervals}
\begin{definition}
	We call a subset $I$ of $\mathbb{R}$ an interval if, for any $a, b \in I$ and $x \in \mathbb{R}$ such that $a \leq x \leq b$, then $x \in I$.
\end{definition}
We can write an interval more simply using the notation $[a, b]$, which is equivalent to $\{x \in \mathbb{R} \mid a \leq x \leq b\}$.
This is called a closed interval, and to make the inequalities strict, we can also define an open interval by using parantheses instead of square brackets.\bigskip

In addition, we can mix the two to create half-open intervals, where one inequality is strict and the other isn't.
For instance, $(2, 5]$ refers to the set $\{x \in \mathbb{R} \mid x < 2 \leq 5\}$
Finally, if the interval is unbounded in either direction, we use the notations $-\infty$ and $\infty$ to indicate that there is no minimum or maximum, respectively.

\begin{example}
	Is $8 \in (-\infty, 4) \cup [8, 100)$?
\end{example}
\begin{answer}
	Since $8 \leq 8 < 100$ is a true statement, $8 \in [8, 100)$.
	Since we are taking the union with another set, all of the members of the right interval will also be members of the union of intervals.
	Therefore, the statement is true.
\end{answer}


\subsection{Einstein summation convention}

A vector can be written as a sum of its components.

\(v=\sum_i e_i v^i\)

The Einstein summation convention is to remove the \(\sum_i \) symbols where they are implicit.

For example we would instead write the vector as:

\(v=e_iv^i\)

\subsubsection{Adding vectors}

\(v+w=(\sum_i e_i v^i)+(\sum_i f_iw^i)\)

\(v+w=\sum_i (e_iv^i+f_iw^i)\)

\(v+w=e_iv^i+f_iw^i\)

If the bases are the same then:

\(v+w=e_i (v^i+w^i)\)

\subsubsection{Scalar multiplication}

\(cv=c\sum_ie_iv^i\)

\(cv=\sum_i ce_iv^i\)

\(cv=ce_iv^i\)

\subsubsection{Matrix multiplication}

\(AB_{ik}=\sum_jA_{ij}B_{jk}\)

\(AB_{ik}=A_{ij}B_{jk}\)

\subsubsection{Inner products}

\(\langle v, w\rangle =\langle \sum_i e_iv^i, \sum_j f_jw^j\rangle \)

\(\langle v, w\rangle =\sum_iv^i\langle  e_i, \sum_j f_iw^j\rangle \)

\(\langle v, w\rangle =\sum_i \sum_jv^i\overline {w^j}\langle e_i, f_j\rangle\)

If the two bases are the same then:

\(\langle v, w\rangle =\sum_i \sum_jv^i\overline {w^j}\langle e_i, e_j\rangle\)

We can define the metric as:

\(g_{ij}:=\langle e_i,e_j\rangle \)

\(\langle v, w\rangle =v^i\overline {w^j}g_{ij}\)


\subsection{Gamma function}

The gamma function expands the factorial function to the real (and complex) numbers

We want:

\(f(1)=1\)

\(f(x+1)=xf(x)\)

There are an infinite number of functions which fit this. The function could fluctuate between the natural numbers.

The function we use is:

\(\Gamma (z)=\int_0^\infty x^{z-1}e^{-x}dx\)


\chapter{Matrices}
\section{Vector space}
A vector space is a collection of objects called vectors, which may be added together and multiplied (``scaled'') by numbers, called scalars.\par
Let $F$ be the field\footnote{a field is a set on which addition, subtraction, multiplication, and division are defined, and behave as when they are applied to rational and real numbers.} and $X$ be abelian group\footnote{an abelian group, also called a commutative group, is a group in which the result of applying the group operation to two group elements does not depend on the order in which they are written.}. The pair $\left(X,\odot \right)$ is a vector space if $\odot \, : F \times X \rightarrow X$ satisfies $\forall s,t \in F$ and $\forall u,v \in X$:
\begin{equation*}
\begin{cases}
	s \odot \left( t \odot u \right) &= \left(s \cdot t \right) \odot u \\
	s \odot \left( u+v \right) &= \left(s \odot u \right) + \left(s \odot v \right) \odot u \\
	\left( s+t \right) \odot u &= \left(s + u \right) \odot \left(s + v \right) \\
	1 \odot u &= u
\end{cases}
\end{equation*}
The elements of $F$ (meaning $s,t$) are called ``scalars''. The elements of $X$ (meaning $u,v$) are called ``vectors''. The habit to denote vectors in this notebook, say $u \in X$, by $\vect{u}$.\par
In this notebook, $F=\mathbb{R}$, thus we only discuss vector spaces. Additionally, we omit the symbol $\odot$, thus $s \odot \vect{u}$ is writing $s\vect{u}$.
\begin{example}
$\mathbb{R}$ is a vector space.
\end{example}

\begin{example}
$\mathbb{R}^2$ is also a vector space, where for $\vect{u}=\left(u_1,u_2\right)$ and $\vect{v}=\left(v_1,v_2\right)$ and $s \in \mathbb{R}$:
	\begin{equation*}
	\begin{cases}
		s\vect{u} &= \left(su_1,su_2\right) \\
		\vect{u}+\vect{v} &= \left(u_1 + u_2 , u_2 + v_2 \right) \\
		\vect{0} &= (0,0)
	\end{cases}
	\end{equation*}
\end{example}

\begin{example}
Any $\mathbb{R}^n$ is a vector space, where for $\vect{u}=\left(u_1,u_2,\ldots ,u_n\right)$ and $\vect{v}=\left(v_1,v_2,\ldots ,v_n\right)$ and $s \in \mathbb{R}$ satisfies:
    \begin{equation*}
    	\begin{cases}
		s\vect{u} &= \left(su_1,su_2,\ldots ,su_n\right) \\
		\vect{u}+\vect{v} &= \left(u_1 + u_2 , u_2 + v_2 ,\ldots ,u_n + v_n \right) \\
		\vect{0} &= (\underbrace{0,0,\ldots ,0}_\text{n times})
	\end{cases}
    \end{equation*}
\end{example}

\note If $\vect{u} \in \mathbb{R}^2$ and $\vect{v} \in \mathbb{R}^3$ then $\vect{u} + \vect{v}$ is not defined because $\vect{u}$ and $\vect{v}$ do not belong to the same vector space.

\section{Definition}
Let $\mathbb{R}^{m \times n}$ be the set of all tables with $m$ rows and $n$ columns such that they consist of real numbers. For example, $\begin{mtrx} 2 & 3 & -1 \\ 2 & 1 & 4 \end{mtrx}$ is a table of $2 \times 3$
Let define a table $\vect{A}$ such that:
\begin{equation*}
    \vect{A}=
    \begin{mtrx}
		a_{11} & a_{12} & \ldots & a_{1n} \\
		a_{21} & a_{22} & \ldots & a_{2n} \\
		\vdots & \vdots & \ddots & \vdots \\
		a_{m1} & a_{m2} & \ldots & a_{mn}
    \end{mtrx}
\end{equation*}
Note that the element $a_{ij}$, called the ij-entry, appears in the \emph{i}th row and the \emph{j}th column. We simply denote $\vect{A}=\left[a_{ij}\right]$, where $i \in {1,2,\ldots ,m}$ and $j \in {1,2,\ldots ,n}$.\par
Now, $\mathbb{R}^{m \times n}$ is a vector space if $\vect{A}=\left[a_{ij}\right]$ and $\vect{B}=\left[b_{ij}\right]$ and $s \in \mathbb{R}$ satisfies:
\begin{equation*}
\begin{cases}
\vect{A} + \vect{B} &= \left[ a_{ij} + a_{ij} \right] \\
s\vect{A} &= \left[sa_{ij}\right] \\
\left[0\right] & \text{is the zero-element}
\end{cases}
\end{equation*}
In this case, $\left[0\right]$ is an $m\times n$ table whose entries are all zero. $\vect{A},\vect{B},\left[0\right]$ are now called matrices. Notice that a vector can be regarded as a special type of matrix. A row vector is a $1\times n$ matrix, and a column vector is a $m\times 1$ matrix.
\begin{example}
Vector $\vect{s}=(1,2)$ can be written as a matrix $\rvect{1,2}$ (row vector) or $\cvect{1,2}$ (column vector).
\end{example}
\section{Basic operations}
\subsection{Matrix addition}
Let $\vect{A}$ and $\vect{B}$ are two matrices of the same vector space. The sum of $\vect{A}$ and $\vect{B}$, written $\vect{A}+\vect{B}$, is the matrix obtained by adding corresponding elements from $\vect{A}$ and $\vect{B}$:
\begin{equation*}
    \begin{mtrx}
		a_{11} & a_{12} & \ldots & a_{1n} \\
		a_{21} & a_{22} & \ldots & a_{2n} \\
		\vdots & \vdots & \ddots & \vdots \\
		a_{m1} & a_{m2} & \ldots & a_{mn}
    \end{mtrx}
    +
    \begin{mtrx}
		b_{11} & b_{12} & \ldots & b_{1n} \\
		b_{21} & b_{22} & \ldots & b_{2n} \\
		\vdots & \vdots & \ddots & \vdots \\
		b_{m1} & b_{m2} & \ldots & b_{mn}
    \end{mtrx}
    =
    \begin{mtrx}
		a_{11}+b_{11} & a_{12}+b_{12} & \ldots & a_{1n}+b_{1n} \\
		a_{21}+b_{21} & a_{22}+b_{22} & \ldots & a_{2n}+b_{2n} \\
		\vdots & \vdots & \ddots & \vdots \\
		a_{m1}+b_{m1} & a_{m2}+b_{m2} & \ldots & a_{mn}+b_{mn}
    \end{mtrx}
\end{equation*}
\subsection{Scalar multiplication}
The product of a scalar $k$ and a matrix $\vect{A}$, written $k\vect{A}$ or $\vect{A} k$, is the matrix obtained by muliplying each element of $\vect{A}$ by $k$:
\begin{equation*}
    k
    \begin{mtrx}
		a_{11} & a_{12} & \ldots & a_{1n} \\
		a_{21} & a_{22} & \ldots & a_{2n} \\
		\vdots & \vdots & \ddots & \vdots \\
		a_{m1} & a_{m2} & \ldots & a_{mn}
    \end{mtrx}
    =
    \begin{mtrx}
		ka_{11} & ka_{12} & \ldots & ka_{1n} \\
		ka_{21} & ka_{22} & \ldots & ka_{2n} \\
		\vdots & \vdots & \ddots & \vdots \\
		ka_{m1} & ka_{m2} & \ldots & ka_{mn}
    \end{mtrx}
\end{equation*}
We also define $-\vect{A}=(-1)\vect{A}$ and $\vect{A}-\vect{B}=\vect{A}+(-\vect{B})$. The matrix $-\vect{A}$ is called the \emph{negative} of the matrix $\vect{A}$.
\subsection{Matrix multiplication}
Now suppose $\vect{A}$ and $\vect{B}$ are two matrices such that the number of columns of $\vect{A}$ is equal to the number of rows of $\vect{B}$, say $\vect{A}$ is an $m\times p$ matrix and $\vect{B}$ is an $p\times n$. Then the product of $\vect{A}$ and $\vect{B}$, written $\vect{A}\vect{B}$, is the $m\times n$ matrix whose ij-entry is obtained by muliplying the elements of \emph{i}th row of $\vect{A}$ by the corresponding elements of the \emph{j}th column of $\vect{B}$ and then adding:
\begin{equation*}
    \begin{mtrx}
		a_{11} & a_{12} & \ldots & a_{1p} \\
		  .    &   .    & \ldots &   .    \\
		a_{i1} & a_{i2} & \ldots & a_{ip} \\
		  .    &   .    & \ldots &   .    \\
		a_{m1} & a_{m2} & \ldots & a_{mp}
    \end{mtrx}
    \quad
    \begin{mtrx}
		b_{11} & \ldots & b_{1j} & b_{1n} \\
		\vdots & \vdots & \vdots & \vdots \\
		b_{m1} & b_{m2} & \ldots & b_{mn}
    \end{mtrx}
    =
    \begin{mtrx}
		c_{11} & \ldots & c_{1n} \\
		\vdots & \vdots & \vdots \\
		\vdots & c_{ij} & \vdots \\
		\vdots & \vdots & \vdots \\
		c_{m1} & \ldots & c_{mn}
    \end{mtrx}
\end{equation*}
where \[ c_{ij} = a_{i1}b_{1j} + a_{i1}b_{1j} + \ldots + a_{ip}b_{pj} = \sum_{k=1}^p a_{ik}b_{kj} \]
If the number of columns of $\vect{A}$ is not equal to the number of rows of $\vect{B}$, then the product $\vect{A}\vect{B}$ is not defined.

\begin{example}
    Find $\vect{A}\vect{B}$, where
    \begin{equation*}
        A=
        \begin{mtrx}
            1&3\\
            2& -1
        \end{mtrx}
        \qquad
        B=
        \begin{mtrx}
            2&0& -4 \\
            3& -2 &6
        \end{mtrx}
    \end{equation*}
    Since $\vect{A}$ is a $2\times 2$ matrix, $\vect{B}$ is a $2\times 3$, the product matrix $\vect{A}\vect{B}$ is defined and is a $2\times 3$ matrix. To obtain the elements in the first row of the product matrix $\vect{A}\vect{B}$, multiply the first row $\rvect{1,3}$ of $\vect{A}$ by the columns:
    \[ \cvect{2,3} \qquad \cvect{0,-2} \qquad \text{and} \cvect{-4,6} \]
    of $\vect{B}$ respectively:
    \begin{meq*}
        \smtrx{1,3\\2,-1} \smtrx{2,0,-4\\3,-2,6} & = &
	        \smtrx{
	            1 \cdot 2 + 3 \cdot 3 ,
	            1 \cdot 0 + 3(-2) ,
	            1(-4) + 3 \cdot 6\\
	             ,,
            }\\
        & = & \smtrx{11,-6,14\\,,}
    \end{meq*}
    To obtain the elements in the second row of the product matrix   $\vect{A}\vect{B}$, multiply the second row $\rvect{2,-1}$ of $\vect{A}$ by the columns of $\vect{B}$ respectively:
    \begin{meq*}
        \smtrx{1,3\\2,-1} \smtrx{2,0,-4\\3,-2,6} & = &
	        \smtrx{
                11,-6,14 \\
                2 \cdot 2 + (-1) \cdot 3 ,
                2 \cdot 0 + (-1) \cdot (-2),
                2 \cdot (-4) + (-1) \cdot 6
            }\\
        & = & \smtrx{11,-6,14\\1,2,-14}
    \end{meq*}
\end{example}

\subsection{Transpose}
The transpose of a matrix is an operator which flips a matrix over its diagonal, that is, it switches the row and column indices of the matrix by producing another matrix.\par
Let $\vect{A}\in \mathbb{R}^{m\times n}$. The transpose of $\vect{A}$, denote $\trans{A}$, is a matrix $\trans{A}\in \mathbb{R}^{n\times m}$ such that for $\vect{A}=\smtrx{a_{ij}}$, we have $\trans{A}=\smtrx{a_{ji}}$.\par
\begin{example}
    The transpose of $\vect{A}=\smtrx{2,3,1\\ 0,7,8}$ is $\trans{A}=\smtrx{2,0\\ 3,7\\ 1,8}$.
\end{example}
For matrices $\vect{A}\vect{B}$ and scalar $k$, we have the following properties of transpose:
\begin{itemize}
\item The operation of taking the transpose is an involution (self-inverse), meaning that $\trans{\left( \trans{A} \right)}=\vect{A}$.
\item The transpose respects addition, $\trans{\left( \vect{A}+\vect{B} \right)}=\trans{A}+\trans{B}$.
\item The order of the factors reverses when taking tranpose of a product matrix, $\trans{ \left(\vect{A}\vect{B}\right) }=\trans{B}\trans{A}$. From this, one can deduce that a square matrix $\vect{A}$ is invertible if and only if its transpose $\trans{A}$ is invertible, and in this case, we have $\trans{\left( \inverse{A} \right)}=\inverse{\left( \trans{A} \right)}$.
\item $\trans{\left( c\vect{A} \right)}=c\trans{A}$.
\end{itemize}

\section{Square matrices}
\subsection{Definition}
A matrix with the same number of rows as columns is called a \emph{square matrix}. A square matrix with \emph{n} rows and \emph{n} columns is said to be of \emph{order n}, and is called \emph{n-square matrix}. The diagonal of an n-square matrix $\vect{A}=\smtrx{a_{ij}}$ consists of elements $a_{11},a_{22},\ldots , a_{mn}$.
\begin{example}
The matrix \[ \smtrx{1,-2,0 \\ 0,-4,-1 \\ 5,3,2} \] is a square matrix of order 3. The numbers along the diagonal are 1, -4, and 2.
\end{example}
\subsection{Unit matrix}
The n-square matrix with 1s along the diagonal and 0s elsewhere, e.g., \[ \smtrx{1,0,0\\ 0,1,0\\ 0,0,1} \] is called \emph{unit matrix} and will be denoted by $\vect{I}$. The unit matrix $\vect{I}$ plays the same role in matrix multplication as the number 1 does in the usual multiplication of number. Specifically, \[ \vect{A}\vect{I}=\vect{I}\vect{A}=\vect{A} \] for any square matrix $\vect{A}$.\par
We can form powers of a square matrix $\vect{X}$ by defining:\[ \vect{X}^2=\vect{X}\vect{X}, \quad \vect{X}^3=\vect{X}^2 \vect{X} \quad \ldots \vect{X}^0=\vect{I} \]
\subsection{Invertible matrix}
An n-square matrix $\vect{A}$ is said to be invertible if there exists an n-square matrix $\vect{B}$ with the property \[ \vect{A}\vect{B}=\vect{B}\vect{A}=\vect{I}_n \] Such a matrix $\vect{B}$ is unique, and is called the \emph{inverse} of $\vect{A}$, and is denoted by $\inverse{A}$. Observe that $\vect{B}$ is the inverse of $\vect{A}$ if and only if $\vect{A}$ is the inverse of $\vect{B}$.
\begin{example}
Suppose \[ \vect{A}=\smtrx{2,5\\ 1,3} \quad \text{and} \quad \vect{B}=\smtrx{3,-5\\ -1,2} \] Then \[ \vect{A}\vect{B}=\smtrx{6-5,-10+10\\ 3-3,-5+6}=\smtrx{1,0\\ 0,1}=\vect{I}_2 \]
\[ \vect{B}\vect{A}=\smtrx{6-5,15-15\\ -2+2,-5+6}=\smtrx{1,0\\ 0,1}=\vect{I}_2 \] Thus $\vect{A}$ and $\vect{B}$ are inverses.
\end{example}
\subsection{Determinants}
    \label{sec:Determinants}
To each n-square matrix $\vect{A}=\smtrx{a_{ij}}$ we assign a specific number called the \emph{determinant} of $\vect{A}$, denoted $\dt{A}$ or
\begin{equation*}
\dmtrx{
    a_{11},a_{12},\ldots ,a_{1n}\\
    a_{21},a_{22},\ldots ,a_{2n}\\
    \vdots,\vdots,\ddots,\vdots \\
    a_{n1},a_{n2},\ldots ,a_{nn}\\
}
\end{equation*}
The determinants of matrices of order one, two, three are defined as follows:
\begin{meq*}
\dmtrx{a_{11}} &=& a_{11} \\
\dmtrx{a_{11},a_{12}\\a_{21},a_{22}} &=& a_{11}a_{22}-a_{12}a_{21}\\
\dmtrx{a_{11},a_{12},a_{13}\\a_{21},a_{22},a_{23}\\a_{31},a_{32},a_{33}} &=& a_{11}a_{22}a_{33}+a_{21}a_{23}a_{31}+a_{13}a_{21}a_{32}-a_{13}a_{22}a_{31}-a_{12}a_{21}a_{33}-a_{11}a_{23}a_{32}
\end{meq*}
Below is another way to calculate determinant of a $3\times 3$ matrix:
\begin{equation}\label{det-3matrix}
\dmtrx{
    a_{11},a_{12},a_{13}\\
    a_{21},a_{22},a_{23}\\
    a_{31},a_{32},a_{33}
}
= \dmtrx{a_{22},a_{23}\\a_{32},a_{33}} a_{11} - \dmtrx{a_{21},a_{23}\\a_{31},a_{33}} a_{12} + \dmtrx{a_{21},a_{22}\\a_{31},a_{32}} a_{13}
\end{equation}
In general, one can calculate determinant of an n-square matrix $\vect{A}$ using the following formula: \[ \dt{A}=\sum^n_{j=1} (-1)^{i+j}a_{ij} \dt{A_{ij}} \]
Using determinant, we can calculate the inverse of an invertible matrix. For example, the inverse of a $2\times 2$ matrix with nonzero determinant can be calculated as follow: \[ \inverse{A}=\smtrx{a,b\\c,d}^{-1}=\frac{1}{\dt{A}} \smtrx{d,-b\\-c,a} \]
For n-square matrix $\vect{A}=\smtrx{a_{ij}}$ with nonzero determinant, the inverse would be:
\[ \inverse{A}= \frac{1}{\dt{A}}
\dmtrx{
    c_{11},c_{12},\ldots ,c_{1n}\\
    c_{21},c_{22},\ldots ,c_{2n}\\
    \vdots,\vdots,\ddots,\vdots \\
    c_{n1},c_{n2},\ldots ,c_{nn}\\
}
\]
where $c_{ij}=(-1)^{i+j} \dt{A_{ij}}$.\par
For matrices $\vect{A},\vect{B}$ and scalar $k \neq 0$, we have the following properties of determinants:
\begin{itemize}
\item $\det (\vect{A}\vect{B})=\dt{A} \cdot \dt{B}$
\item A \emph{square} matrix is invertible if and only if it has a nonzero determinant.
\item Swapping two rows of a matrix produces the negative matrix. If $\vect{B}$ is a matrix $\vect{A}$ with any two rows interchanged, then $\dt{B}=-\dt{A}$.
\item If $\vect{B}$ is a matrix $\vect{A}$ but one row multiplied by $k$ then $\dt{B}=k\dt{A}$.
\item If $\vect{B}$ is a matrix $\vect{A}$ but row \emph{i}th, say $R_i$, is replaced by $R_i + kR_t, \forall t \neq i$, then $\dt{B}=\dt{A}$.
\end{itemize}
\begin{example}
Given matrix $\vect{A}$:
\[ \vect{A}=\smtrx{-2,-1,4\\ 6,-3,-2\\ 4,1,2} \quad \dt{A}=100 \]
Interchange any two rows of $\vect{A}$, we have matrix $\vect{B}$:
\[ \vect{B}=\smtrx{6,-3,-2\\ -2,-1,4\\ 4,1,2} \quad \dt{B}=-\dt{A}=-100 \]
Multiply first row of $\vect{A}$ with 4 , we have matrix $\vect{B}$:
\[ \vect{B}=\smtrx{-8,-4,16\\ 6,-3,-2\\ 4,1,2} \quad \dt{B}=4\dt{A}=400 \]
Replace the first row $R_1$ by $R_1+\dfrac{1}{2}R_3$
\[ \vect{B}=\smtrx{1,-5/2,3\\ 6,-3,-2\\ 4,1,2} \quad \dt{B}=\dt{A}=100 \]
\end{example}
\subsection{Eigenvectors and eigenvalues}
Let $\vect{A}$ be an n-square matrix. The eigenvector of $\vect{A}$ is a column vector $\vect{x}$ that satisfies:
\begin{equation*}
\vect{A}\vect{x}=\lambda\vect{x}
\end{equation*}
Let us start to find $\vect{x}$ such that
\begin{meq*}
\vect{A}\vect{x} &=& \lambda\vect{x} \\
\Leftrightarrow \vect{A}\vect{x}-\lambda\vect{x} &=& \vect{0} \\
\Leftrightarrow \left( \vect{A}-\lambda\vect{I} \right)\vect{x} &=& \vect{0} \\
\end{meq*}
where $\vect{I}$ is the identity matrix living in the same vector space with $\vect{A}$. There are infinite number of solutions for $\vect{x}$ if there exists $\lambda$ that makes $\det \left( \vect{A}-\lambda\vect{I} \right) =\vect{0}$. In that case, $\lambda$ is called eigenvalue associated with the eigenvector $\vect{x}$.\par
\note There are no more than $n$ distinct eigenvalues for an n-square matrix.
\begin{example}
To calculate the eigenvalues and eigenvectors of $\vect{A}=\smtrx{2,1\\1,4}$, we need to solve the following equation:
\begin{meq*}
\det \left( \vect{A}- \lambda\vect{I} \right) =0 &\Leftrightarrow & \dmtrx{2-\lambda,1\\1,4-\lambda}=0 \\
\Leftrightarrow (2-\lambda)(4-\lambda)=0 &\Leftrightarrow & {\lambda}^2-6\lambda +7=0 \\
\Leftrightarrow {\lambda}_1=3+\sqrt{2} &\quad\text{and}\quad & {\lambda}_2=3-\sqrt{2}
\end{meq*}
If the eigenvalue is ${\lambda}_1=3+\sqrt{2}$, then
\begin{IEEEeqnarray*}{l}
\left( \vect{A} - \left(3+\sqrt{2}\right) \vect{I} \right)\vect{x} = \vect{0} \\
\smtrx{-1-\sqrt{2},1\\1,1-\sqrt{2}}\cvect{x_1,x_2}=\vect{0}\\
\Leftrightarrow
	\begin{cases}
	    \left( -1-\sqrt{2} \right)x_1+x_2 &=0\\
	    x_1+\left( 1-\sqrt{2} \right)x_2 &=0
	\end{cases}\\
\Leftrightarrow x_1 = \left( 1+\sqrt{2} \right)x_2
\end{IEEEeqnarray*}
Eigenvectors corresponding to ${\lambda}_1=3+\sqrt{2}$ are
\[ \vect{x}=\cvect{1,1+\sqrt{2}}k, \quad k\in\mathbb{R}\backslash\lbrace 0 \rbrace \]
Likewise, If the eigenvalue is ${\lambda}_1=3-\sqrt{2}$, then the corresponding eigenvectors are
\[ \vect{x}=\cvect{1,1-\sqrt{2}}k, \quad k\in\mathbb{R}\backslash\lbrace 0 \rbrace \]
\end{example}
\note The sum of diagonal members of the matrix equals to the sum of eigenvalues.
\section{Vector operations}
\subsection{Inner product}
Let $X$ be a vector space. If one can define a binary operation $\cdot \, : X \times X \rightarrow \mathbb{R}$ (take 2 vectors and produce a scalar) such that $\forall \vect{w},\vect{u},\vect{v}\in X$ and $\forall s\in \mathbb{R}$, we have:
\begin{equation*}
\begin{cases}
    \vect{u} \cdot \vect{v} &= \vect{v} \cdot \vect{u} \\
    \vect{u} \cdot \left( \vect{v}+\vect{w} \right) &= \vect{u} \cdot \vect{v} + \vect{u} \cdot \vect{w} \\
    s\left( \vect{u} \cdot \vect{v} \right) &= \left( s\vect{u} \right)\cdot \vect{v}=\vect{u} \cdot \left( s\vect{v} \right) \\
    \vect{u} \cdot \vect{u} & \geqslant 0 \\
    \vect{u} \cdot \vect{u} = 0 \Leftrightarrow \vect{u}=0
\end{cases}
\end{equation*}
then $X$ is called inner product space. The binary operation $\cdot$ is called inner product.\par
Inner product is used to calculate norm of vectors. For any vector $\vect{u}\in X$, one can define norm $\norm{u}$ by \[ \norm{u}=\sqrt{\vect{u} \cdot \vect{u}} \]
For any two vectors $\vect{u},\vect{v}\in X$, we have \[ \vect{u} \cdot \vect{v} = \norm{u}\norm{v}\cos \alpha \]
A vector whose norm is 1, is called a unit vector. One can define a unit vector $\uvect{x}$ by the following formula: \[ \uvect{x}=\frac{1}{\norm{x}}\vect{x} \]
\begin{example}
Vector $\vect{x}=(-2,5,3,6)$ has inner product norm of $\norm{x}=\sqrt{(-2)^2+5^2+3^2+6^2}=\sqrt{74}$. Thus, \[ \uvect{x}=\frac{1}{\norm{x}}\vect{x}=\frac{1}{\sqrt{74}} (-2,5,3,6) \]
\end{example}
\subsection{Cross product}
Let $\mathbb{R}^3$ be a vector space. If one can define a binary operation $\times \, : X \times X \rightarrow X$ (take 2 vectors and produce a vector) such that $\forall \vect{a},\vect{b},\vect{c}\in \mathbb{R}^3$, we have:
\begin{equation}\label{cross-product}
\vect{c}=\vect{a}\times\vect{b}=\dmtrx{\vect{i},\vect{j},\vect{k}\\a_1,a_2,a_3\\b_1,b_2,b_3}
\end{equation}
where $\vect{i},\vect{j},\vect{k}$ are the base vectors, and $\vect{a}=(a_1,a_2,a_3), \quad \vect{b}=(b_1,b_2,b_3)$. Note that the determinant in \eqref{cross-product} produces a vector instead of a scalar. It is also called \emph{symbolic determinant}.
\begin{example}
Let $\vect{a}=(1,0,5),\quad\vect{b}=(-1,2,1)$. Applying the formula \eqref{det-3matrix}, the cross product $\vect{a}\times\vect{b}$ is
\begin{meq*}
\vect{c}=\dmtrx{\vect{i},\vect{j},\vect{k}\\1,0,5\\-1,2,1} &=& \dmtrx{0,5\\2,1}\vect{i}-\dmtrx{1,5\\-1,1}\vect{j}+\dmtrx{1,0\\-1,2}\vect{k} \\
&=& (-10)\vect{i}-6\vect{j}+2\vect{k}
\end{meq*}
which means that $\vect{c}=(-10,-6,2)$
\end{example}
If we draw $\vect{a},\vect{b}$ and $\vect{c}=\vect{a}\times\vect{b}$ in a right-handed three-dimensional coordinate system, then $\vect{c}$ is perpendicular to both $\vect{a}$ and $\vect{b}$. Moreover, if vectors $\vect{a}$ and $\vect{b}$ are considered as edges of a parallelogram then $A=\Vert\vect{a}\times\vect{b}\Vert$ is the area of that parallelogram.\par
For vectors $\vect{a},\vect{b},\vect{c}$ and scalar $k \neq 0$, we have the following properties of cros products:
\begin{itemize}
\item $\Vert\vect{a}\times\vect{b}\Vert = \norm{a}\norm{b}\sin\alpha$, where $\alpha=\angle (\vect{a},\vect{b})$.
\item $\vect{a}\times\vect{b}=-\left( \vect{b}\times\vect{a} \right)$
\item $\vect{a}\times\vect{a}=\vect{0}$, where $\vect{0}$ is zero-vector (not a scalar).
\item $\left( k\vect{a} \right)\times\vect{b}=\vect{a}\times\left( k\vect{b} \right)=k\left( \vect{a}\times\vect{b} \right)$
\item $\vect{c}\times\left( \vect{a}+\vect{b} \right)=\vect{c}\times\vect{a}+\vect{c}\times\vect{b}$
\item Cross product is not associative, $\vect{c}\times\left( \vect{a}\times\vect{b} \right)$ may not equal to $\left( \vect{c}\times\vect{a} \right)\times\vect{b}$.
\item Given three vectors $\vect{a}=(a_1,a_2,a_3),\vect{b}=(b_1,b_2,b_3)$ and $\vect{c}=(c_1,c_2,c_3)$. The combination of cross product and inner product as follow produces a scalar:
	\begin{equation}
	\left( \vect{a}\times\vect{b} \right)\cdot\vect{c}=\dmtrx{c_1,c_2,c_3\\a_1,a_2,a_3\\b_1,b_2,b_3}
	\end{equation}
\end{itemize}

\section{Matrix applications}
\subsection{Orthogonal projection}
The orthogonal projection of $\vect{v}$ onto the line spanned by a nonzero $\vect{s}$ (see figure \ref{Linalg_projection}) is:
\[ \vect{v}_{\vect{s}}=\frac{\vect{v}\cdot\vect{s}}{\norm{s}^2} \, \vect{s} \]

\begin{figure}[hbtp]
\caption{Orthogonal projection}
\label{Linalg_projection}
\centering
    \begin{tikzpicture}
	\tkzInit[xmin=-1,xmax=6,ymin=-1,ymax=6]
	\tkzDrawX[noticks] \tkzDrawY[noticks]
	\tkzDefPoint(0,0){O} \tkzDefPoint(3,4){A} \tkzDefPoint(2,0.5){B}
	\tkzDefPoint(-0.5,-0.125){C} \tkzDefPoint(4,1){D}
	\tkzDefPointBy[projection=onto O--C](A) \tkzGetPoint{P}
	\tkzDrawVectors(O,A O,B O,P)
	\tkzDrawLine(C,D)
	\tkzDrawSegment(A,P)
	\tkzLabelSegment[above=3pt](O,A){$\vect{u}$}
	\tkzLabelSegment[below=1pt](O,B){$\vect{v}$}
	\tkzLabelSegment[above=1pt](O,P){$\vect{v}_{\vect{s}}$}
	\tkzLabelAngle[pos = 0.5](B,O,A){$\alpha$}
	\tkzMarkAngle[fill= yellow,size=0.75cm,opacity=.3](B,O,A)
	\tkzMarkRightAngle(C,P,A)
	\end{tikzpicture}
\end{figure}

\subsection{Rotation}
In linear algebra, a rotation matrix is a matrix that is used to perform a rotation in Euclidean space.
\subsubsection{In two dimensions}
In two dimensions, every rotation matrix has the following form,
\[ \vect{R}=\smtrx{\cos\alpha,-\sin\alpha\\ \sin\alpha,\cos\alpha} \]
rotates points in the xy-plane counterclockwise through an angle $\alpha$ about the origin of the Cartesian coordinate system. The column vectors are calculated by means of the following matrix multiplication,
\begin{equation*}
\cvect{x',y'}=\smtrx{\cos\alpha,-\sin\alpha\\ \sin\alpha,\cos\alpha}\cvect{x,y}
\end{equation*}
So the new coordinates $\left( x',y' \right)$ of the point $\left( x,y \right)$ after rotation are
\[
 x'=x\cos \alpha -y\sin \alpha \, \quad
 y'=x\sin \alpha +y\cos \alpha \,.
\]
\subsubsection{In three dimensions}
A basic rotation (also called elemental rotation) is a rotation about one of the axes of a Coordinate system. The following three basic rotation matrices rotate vectors by an angle $\theta$ about the x-, y-, or z-axis, in three dimensions, using the right-hand rule:
\[ {\begin{alignedat}{1}R_{x}(\theta )&={\begin{bmatrix}1&0&0\\0&\cos \theta &-\sin \theta \\[3pt]0&\sin \theta &\cos \theta \\[3pt]\end{bmatrix}}\\[6pt]R_{y}(\theta )&={\begin{bmatrix}\cos \theta &0&\sin \theta \\[3pt]0&1&0\\[3pt]-\sin \theta &0&\cos \theta \\\end{bmatrix}}\\[6pt]R_{z}(\theta )&={\begin{bmatrix}\cos \theta &-\sin \theta &0\\[3pt]\sin \theta &\cos \theta &0\\[3pt]0&0&1\\\end{bmatrix}}\end{alignedat}}\]

\section{Exercises}
\begin{exercise}
Consider an object living in 3D real place. Its current position is $P(2,5,3)$. The object is heading towards the point $Q(4,10,5)$, and moves to that direction exactly 3 length units. Calculate the position of this object after movement.
\end{exercise}

\begin{solution}
Let $\vect{y}$ be the vector of the movement and $\vect{x}$ be the distance between P and Q. We have:
\begin{meq*}
\vect{x} &=& \vect{Q}-\vect{P}=(4,10,5)-(2,5,3)=(2,5,2) \\
\norm{x} &=& \sqrt{2^2+5^2+2^2}=\sqrt{33},\quad \uvect{x}=\frac{1}{\sqrt{33}}(2,5,2) \\
\vect{y} &=& \vect{P}+3\uvect{x}=(2,5,3)+\frac{3}{\sqrt{33}}(2,5,2) \qedhere
\end{meq*}
\end{solution}

\begin{exercise}
Let $\vect{a}=(2,4)$ and $\vect{b}=(1,-3)$ be vectors in $\mathbb{R}^2$. If these vectors are considered as edges of a parallelogram then calculate its area A.
\end{exercise}

\begin{solution}
Let $\vect{A}$ be the matrix formed by $\vect{a}$ and $\vect{b}$
\[ \vect{A}=\smtrx{2,1\\4,-3} \]
The area of the parallelogram is the absolute value of the determinant of $\vect{A}$
\[ S=\vert \dt{A}\vert = \vert 2(-3)-4\cdot 1 \vert =10 \qedhere \]
\end{solution}

\begin{exercise}\label{change-origin}
Let $\vect{p}_0 \in \mathbb{R}^2$ be such that $\vect{p}_0 =(5,3)$ and the corresponding point in $\mathbb{R}^2$ is $P(5,3)$. We define the function $f:\mathbb{R}^2\rightarrow\mathbb{R}^2$ such that $f(\vect{x})=\vect{x}-\vect{p}_0$. Calculate $f((0,0)),f((-5,9)),f((\vect{p}_0))$. Define the meaning of this function.
\end{exercise}

\begin{solution}
This function moves the origin of the coordinate system from $O(0,0)$ to $P(5,3)$, and then calculates the new coordinate of vector $\vect{x}$. For example, the coordinate of $O(0,0)$ in the new coordinate system is $f((0,0))=(-5,3)$. Point $(-5,9)$ now becomes $f((-5,9))=(-10,6)$. And, of course, because $P(5,3)$ becomes the origin of the coordinate system, its coordinate is $(0,0)$.
\end{solution}

\begin{exercise}
Suppose we have a cube in $\mathbb{R}^3$ such that the vertices are at the point (0,0,0), (0,0,1), (1,0,0), (1,0,1), (1,1,0) and (1,1,1). Determine a function $f:\mathbb{R}^{3\times8}\rightarrow\mathbb{R}^{3\times8}$ such that cube is centered at the origin of the coordinate system O(0,0,0), thus the center of the cube is mapped to 0.
\end{exercise}

\begin{solution}
We write each point of the cube as a column in a single matrix $\vect{C}$:
\[ \vect{C}=\smtrx{0,0,0,0,1,1,1,1\\0,0,1,1,0,0,1,1\\0,1,0,1,0,1,0,1} \]
The center of the cube is $C_0=(1/2,1/2,1/2)$. The function $f$ moves the origin of the coordinate from point O(0,0,0) to $C_0$. According to exercise \ref{change-origin}, that function is
\[ f(\vect{C})=\vect{C} - \cvect{1/2,1/2,1/2}\rvect{1,1,1,1,1,1,1,1}\qedhere \]
\end{solution}


\section{Geometrical Probability}
\subsection{Buffon's Needle}
Suppose we have parallel horizontal lines, each with distance $L$ apart from each other and we have a needle with length $\ell\le L$.
Throw the needle at random, then we want to know the probbaility that it intersects at least one line.
Suppose we have dropped the needle, then let $\Theta$ be its horizontal inclination and $X$ the distance between the distance between the left end to the line above.
So we take $X\sim\operatorname{Unif}[0,L]$ and $\Theta\sim\operatorname{Unif}[0,\pi]$ and they are independent.
Hence
$$p=\mathbb P(\text{The needle intersects the lines})=\mathbb P(X\le\ell\sin\Theta)$$
So we can now calculate this by
\begin{align*}
    p&=\mathbb P(\text{The needle intersects the lines})\\
    &=\mathbb P(X\le\ell\sin\Theta)\\
    &=\int_0^L\int_0^\pi 1_{x\le l\sin\theta}f_{X,\Theta}(x,\theta)\,\mathrm d\theta\,\mathrm dx\\
    &=\int_0^L\int_0^\pi  1_{x\le l\sin\theta}\frac{1}{\pi L}\,\mathrm d\theta\,\mathrm dx\\
    &=\frac{1}{\pi L}\int_0^\pi\ell\sin\theta\,\mathrm d\theta\\
    &=\frac{2\ell}{\pi L}
\end{align*}
Hence $\pi=2\ell/(pL)$.
Now we want to approximate $\pi$ by this experiment.
Throw $n$ needles independently and let $\hat{p}_n$ be the proportion of needles intersecting a line.
We want to approximate $p$ by $\hat{p}_n$ thus approximate $\pi$ by $\hat\pi_n=2\ell/(\hat{p}_nL)$.
Suppose we want $\mathbb P(|\hat\pi_n-\pi|\le 0.001)\ge 0.99$, we want to know how large $n$ has to be.\\
Define $f(x)=2\ell/(xL)$, then $f(p)=\pi$ and $f^\prime(p)=-\pi/p$.
Also $f(\hat{p}_n)=\hat\pi_n$.
Let $S_n$ be the number of needles intersecting a line, then $S_n\sim\operatorname{Bin}(n,p)$, so $S_n\approx np+\sqrt{np(1-p)}Z$ where $Z\sim\mathcal N(0,1)$.
So $\hat{p}_n\approx p+\sqrt{p(1-p)/n}Z$.
By Taylor's Theorem,
$$\hat\pi_n=f(\hat{p}_n)\approx f(p)+(\hat{p}_n-p)f^\prime(p)=\pi-(\hat{p}_n-p)\pi/p$$
So when we substitute back, we obtain
$$\hat\pi_n-\pi\approx-\pi\sqrt{\frac{1-p}{pn}}Z$$
So
$$\mathbb P(|\hat\pi_n-\pi|\le 0.001)=\mathbb P\left( \pi\sqrt{\frac{1-p}{pn}}|Z|<0.001 \right)$$
Now $\mathbb P(|z|\ge 2.58)<0.01$.
Also the variance of $\pi\sqrt{(1-p)/(pn)}Z$ is $\pi^2(1-p)/(pn)$ which is decreasing in $p$.
We can minimize the variance by taking $\ell=L$, so $p=2/\pi$ and the variance is $\pi^2(\pi/2-1)/n$, so in this case we need
$$\sqrt{\frac{\pi^2}{n}(\frac{\pi}{2}-1)}2.58=0.001\implies n=3.75\times 10^7$$
which is quite large.
\subsection{Bertrand's Paradox}
We have a circle of radius $r$ and draw a chord at random.
We want to know the probability that it has length at most $r$.
There are two ways to do this.
The first approach is let $X\sim\operatorname{Unif}(0,r)$ to be the perpendicular distance between the chord and the center of the circle.
Let $C$ be the length, then $C\le r\iff 4X^2\ge 3r^2$, so the probability is $1-\sqrt{3}/2\approx 0.134$.\\
There is a second approach.
Fix one point of the chord and choose $\Theta\sim\operatorname{Unif}(0,2\pi)$ to be the angle between this point and the other point of the chord.
So $C\le r\iff \Theta\le\pi/3\lor\Theta\ge 2\pi-\pi/3$, hence the probability is $1/3$ which is far enough from $0.134$.\\
But this is not a paradox since we are using essentially different sample spaces.


\section*{Exercise 26.1-4}
\subsubsection*{Prove that the flows in a network form a convex set.}
Let $f_1,f_2,\alpha$ be as given in the exercise description.

We want to prove that $f_{\alpha}\equiv\alpha f_1 + (1- \alpha)f_2$ $\forall \alpha \in (0,1)$ is a flow.

We start by showing the capacity constraint i.e.
\begin{align}
\forall u,v \in V \text{ it holds that } 0\leq f_{\alpha}(u,v)\leq c(u,v)\label{Ex.26.1.4:ScalarCapacityConstraint}.
\end{align}

Since $f_1$ and $f_2$ are flows, the capacity constraint holds for both of them. Since the capacity function $c$ is a property of the network, and not the individual flows, the capacity constraint for $f_1$ and $f_2$ are identical to \eqref{Ex.26.1.4:ScalarCapacityConstraint} i.e they are bounded by the same upper and lower bounds.

Hence $\forall \alpha \in (0,1)$ and $\forall u,v \in V$ the following equations hold
\begin{align*}
f_{\alpha}(u,v) &= \alpha f_1(u,v) + (1- \alpha)f_2(u,v)\\
                &\geq \alpha 0 + (1- \alpha)0 \\
								&\geq 0
\end{align*}
and
\begin{align*}
f_{\alpha}(u,v) &= \alpha f_1(u,v) + (1- \alpha)f_2(u,v)\\
                &\leq \alpha c(u,v) + (1- \alpha)c(u,v) \\
								&= c(u,v)
\end{align*}
Combining the two inequalities above yields that \eqref{Ex.26.1.4:ScalarCapacityConstraint} holds.

We then want to show that the flow conservation property holds. i.e
\begin{align}
\forall u \in V\setminus\{s,t\} \text{ it holds that } \sum_{v\in V}f_{\alpha}(v,u) = \sum_{v\in V}f_{\alpha}(u,v)\label{Ex.26.1.4:FlowConservationConstraint}.
\end{align}
First note that since $f_1$ and $f_2$ are flows, the flow conservation property holds for both of them individually.

Pick a vertex $u$ such that $u\in V\setminus\{s,t\}$ then
\begin{align*}
  \sum_{v\in V}f_{\alpha}(v,u) &= \sum_{v\in V} \left(\alpha f_1(v,u) + (1- \alpha)f_2(v,u) \right)\\
    &= \alpha \sum_{v\in V} f_1(v,u) + (1- \alpha) \sum_{v\in V} f_2(v,u)\\
    &= \alpha \sum_{v\in V} f_1(u,v) + (1- \alpha) \sum_{v\in V} f_2(u,v)\\
    &= \sum_{v\in V} \left(\alpha f_1(u,v) + (1- \alpha)f_2(u,v) \right)\\
    &= \sum_{v\in V}f_{\alpha}(u,v)
\end{align*}
Since this holds for all $u\in V\setminus\{s,t\}$, we have now shown \eqref{Ex.26.1.4:FlowConservationConstraint}.

We have now shown the capacity constraint and the flow conservation property for $f_{\alpha}$, hence $f_{\alpha}$ is a flow. So the flows in a network form a convex set.


\section{Weierstrass Theorem}
To approximate any continuous function, a very simple idea is to approximate the function in a polynomial space.
An important property of this space is that polynomials can approximate any reasonable function!
\begin{itemize}
\item $P_n(\mathbb{R}^d)$ is dense in $C(\Omega)$ [Weierstrass theorem]
\item $P_n(\mathbb{R}^d)$ is dense in all Sobolev spaces: $L^2(\Omega), W^{m,p}(\Omega), \ldots$
\end{itemize}

\input{6DL/WTheoremProof}

\subsection{Curse of dimensionality}
Number of coefficients for polynomial space $P_n(\mathbb{R}^d)$  is
$$
	N = \binom{d+n}{n} = \frac{(n+d)!}{d!n!}.
$$
For example $n = 100$:
		\begin{table}
			\centering
			\begin{tabular}{|c|c|c|c|}
				\hline
				$d = $&  $2$ &  $4$ & $8$\\
				\hline
				$N=$  & $5\times10^3$ & $4.6\times10^6$  & $3.5\times10^{11}$ 	\\
				\hline
			\end{tabular}
		\end{table}
As the this table shows, the dimension of the polynomial space $P_n(\mathbb{R}^d)$   increases rapidly as the degree $n$ increases. This leads to an extremely large space therefore very expensive to approximate functions in polynomial spaces in high dimensions.
\input{6DL/Runge}
\input{6DL/Fourier}
\input{6DL/DNN_Qualitative}

497-6DL/5 Polynomials and Weierstrass theorem/5.1-PolyWeierstrass.tex


\subsection{Types of matrices}
\subsubsection{Empty matrix}

A matrix where every element is \(0\). There is one for each dimension of matrix.

\(A=\begin{bmatrix}0& 0&...&0\\0 & 0&...&0\\...&...&...&...\\0&0&...&0\end{bmatrix}\)

\subsection{Triangular matrix}

A matrix where \(a_{ij}=0\) where \(i < j\) is upper triangular.

A matrix where \(a_{ij}=0\) where \(i > j\) is lower triangular.

A matrix which is either upper or lower triangular is a triangular matrix.

\subsection{Symmetric matrices}

All symmetric matrices are square.

The identity matrix is an example.

A matrix where \(a_{ij}=a_{ji}\) is symmetric.

\subsection{Diagonal matrix}

A matrix where \(a_ij=0\) where \(i\ne j\) is diagonal.

All diagonal matrices are symmetric.

The identity matrix is an example.


\subsection{Partial sum}

Take a series. We can define the partial sum as:

\(s_k=\sum_{i=1}^ka_i\)


\subsection{Green's theorem}
Green's theorem tells us that
$$\oint P\,dx+Q\,dy=\int\!\!\!\int
\left(\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}\right)
dx\,dy$$

\noindent
In other words, a line integral and a surface integral can yield
the same result.

\bigskip
\noindent
Example 1.
The following exercise is from {\it Advanced Calculus}
by Wilfred Kaplan, p.~287.
Evaluate $\oint (2x^3-y^3)\,dx+(x^3+y^3)\,dy$ around the circle
$x^2+y^2=1$ using Green's theorem.

\bigskip
\noindent
It turns out that Eigenmath cannot solve the double integral over
$x$ and $y$ directly.
Polar coordinates are used instead.

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
P = 2x^3 - y^3
Q = x^3 + y^3
f = d(Q,x) - d(P,y)
x = r cos(theta)
y = r sin(theta)
defint(f r,r,0,1,theta,0,2pi)
\end{Verbatim}

\noindent
$\displaystyle \tfrac{3}{2}\pi$

\bigskip
\noindent
The $defint$ integrand is $f\,r$ because $r\,dr\,d\theta=dx\,dy$.

\bigskip
\noindent
Now let us try computing the line integral side of Green's theorem
and see if we get the same result.
We need to use the trick of converting sine and cosine to exponentials
so that Eigenmath can find a solution.

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
x = cos(t)
y = sin(t)
P = 2x^3 - y^3
Q = x^3 + y^3
f = P d(x,t) + Q d(y,t)
f = circexp(f)
defint(f,t,0,2pi)
\end{Verbatim}

\noindent
$\displaystyle \tfrac{3}{2}\pi$

\bigskip
\noindent
Example 2.
Compute both sides of Green's theorem for
$F=(1-y,x)$ over the disk $x^2+y^2\le4$.

\bigskip
\noindent
First compute the line integral along the boundary of the disk.
Note that the radius of the disk is 2.

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
-- Line integral
P = 1 - y
Q = x
x = 2 cos(t)
y = 2 sin(t)
defint(P d(x,t) + Q d(y,t),t,0,2pi)
\end{Verbatim}

\noindent
$\displaystyle 8\pi$

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
-- Surface integral
x = quote(x) --clear x
y = quote(y) --clear y
h = sqrt(4-x^2)
defint(d(Q,x)-d(P,y),y,-h,h,x,-2,2)
\end{Verbatim}

\noindent
$\displaystyle 8\pi$

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
-- Try computing the surface integral using polar coordinates.
f = d(Q,x) - d(P,y) --do before change of coordinates
x = r cos(theta)
y = r sin(theta)
defint(f r,r,0,2,theta,0,2pi)
\end{Verbatim}

\noindent
$\displaystyle 8\pi$

\begin{Verbatim}[formatcom=\color{blue},samepage=true]
defint(f r,theta,0,2pi,r,0,2) --try integrating over theta first
\end{Verbatim}

\noindent
$\displaystyle 8\pi$

\bigskip
\noindent
In this case, Eigenmath solved both forms of the polar integral.
However, in cases where Eigenmath fails to solve a double integral, try
changing the order of integration.