% begin preamble
\documentclass[11pt,titlepage]{article}
\usepackage[margin=1in,noheadfoot]{geometry}
\usepackage[parfill]{parskip}
\usepackage{graphicx}
\usepackage[colorlinks,urlcolor=blue]{hyperref}
\usepackage{amssymb}
\usepackage{amsbsy}
\usepackage{wrapfig}

\newcommand{\e}[1]{\times 10^{#1}}
\newcommand{\q}{\mathrm}
\newcommand{\where}[1][where]{\qquad\mbox{#1}\qquad}
\newcommand{\bs}[1]{\boldsymbol{#1}}
\newcommand{\bh}[1]{\hat{\boldsymbol{#1}}}
\newcommand{\bv}[1]{\vec{\boldsymbol{#1}}}
\newcommand{\bt}[1]{\tilde{\boldsymbol{#1}}}
\newcommand{\ad}{^{\dagger}}
\newcommand{\flow}[1]{\mathcal{E}_{#1}}
\newcommand{\flux}[1]{\Phi_{#1}}
\newcommand{\dslash}{d \hspace{-0.5ex}\rule[1.2ex]{0.6ex}{.1ex}}
\newcommand{\ts}{\textsuperscript}
\def\rcurs{{\mbox{$\resizebox{.16in}{.08in}{\includegraphics{ScriptR}}$}\!\!}}
\def\brcurs{{\mbox{$\resizebox{.16in}{.08in}{\includegraphics{BoldR}}$}\!\!}}
\def\hrcurs{{\mbox{$\hat \brcurs$}\!}}
%end preamble

\begin{document}
\begin{center}
  {\bf University of Kentucky, Physics 335 \\
    Homework \#6, Rev. A, due Monday, 2024-10-21 }
\end{center}

\vspace{.3 in}

{\bf 2-d: Gaussian Generator}---The $\chi^{2}$ distribution with $\nu=2$ degrees of freedom can be used to create a more efficient and accurate Gaussian generator.

{\bf \quad a)} Integrate joint Gaussian distribution $p(\vec\chi)=p_{G}(z_{1}) p_{G}(z_{2})$ of the vector $\vec\chi=(z_{1},z_{2})=(\chi\cos\phi,\chi\sin\phi)$ over $\phi$ in cylindrical coordinates $(\chi,\phi)$ to obtain the $\chi^{2}$ distribution $p_{\chi}(u;2)$ where $u=\chi^{2}=\vec\chi\cdot\vec\chi=z_{1}{}^{2}+z_{2}{}^{2}$.

{\bf \quad b)} Histogram the distribution of $u=z_{1}{}^{2}+z_{2}{}^{2}$ into 1000 bins over $0\leq u\leq 10$, using 100,000 pairs ($z_{1},z_{2}$) from 1b) with $n=100$ again, and plot together with $p_{\chi}(u;2)$ from 2a).

{\bf \quad c)} Working backwards, use the fact that $p_{u}(x)dx=p_{e}(u)du$ to determine the function $u(x)$ which transforms the uniform deviate $x$ into $u$ following the exponential distribution $p_{e}(u)=\frac12\exp(-u/2)$ defined on $0\leq u <\infty$.

{\bf \quad d)} Generate a 100,000 pairs of Gaussian deviates $\vec\chi=(z_{1},z_{2})$ by generating $\chi=\sqrt{u}$ from the exponential deviate $u$ of 2c) and a uniform deviate $\phi$ in the range $0\leq \phi < 2\pi$, and finally transforming $(\chi,\phi)$ back to rectangular coordinates $(z_{1},z_{2})$.  Histogram both $z$'s in 1000 bins over $-5\leq z < 5$ and plot each together with the normalized Gaussian distribution.


{\bf 2-d. Gaussian Generator (Reprise)}---The general 2-d Gaussian, including both the {\it variances} $\sigma^{2}_{x}$, $\sigma^{2}_{y}$ and {\it covariance} $\sigma^{2}_{xy}=\sigma^{2}_{yx}$, takes the form $p_{G}(x_{1},x_{2})=N e^{-\chi^{2}/2}$, where $N$ is the normalization, $\vec\chi = \vec x-\vec \mu = (x_{1}-\mu_{1}, x_{2}-\mu_{2})$, is the vector of {\it deviances}, and $\chi^{2} = \vec\chi\cdot\vec\chi = \chi^{T} W \chi$ is {\it weighted} by the {\it metric} $W=\Sigma^{-1}$, which is the inverse of the symmetric {\it covariance matrix} $$\Sigma={\small\pmatrix{\sigma_{x}^{2} & \sigma_{xy}^{2} \cr \sigma_{yx}^{2} & \sigma_{y}^{2} }}.$$

If all covariances vanish (for example, in 1-d), this reduces to $\chi^{2}=z_{1}^{2}+z_{2}^{2}+\ldots$ of H05, where the variances have been absorbed into $z_{i}=(x_{i}-\mu_{i})/\sigma_{i}$, as before.  In this case the distribution factorizes into the simple product $p_{G}(z_{1},z_{2},\ldots)=p_{G}(z_{1})p_{G}(z_{2})\cdots$  of 1-d Gaussians.  Otherwise, one must transform to new variables $\vec\chi'=(u_{1},u_{2},\ldots)$ to perform this factorization.

{\bf \quad a)} To generate a $p_{G}(x_{1},x_{2})$ with covariance, let $u=x+y$ and $v=x-y$ be independent.  Generate $n=$100,000 random points $(u,v)$ centered at $\vec\mu=(0,0)$ with $\sigma_{u}=1$ and $\sigma_{v}=2$.  Draw a {\it scatter plot} of $(x,y)$. [{\it bonus}: draw the $u$ and $v$ axes on the same plot]

{\bf \quad b)} Calculate the means $\mu_{x}$, $\mu_{y}$, variances $\sigma^{2}_{x}=\sigma^{2}_{xx}$, $\sigma^{2}_{y}=\sigma^{2}_{yy}$, and covariance $\sigma^{2}_{xy}$, where $\sigma^{2}_{ij}=\sum (x_{i}-\mu_{i})(x_{j}-\mu_{j})/n$, for $i,j=x,y$.  Calculate the {\it correlation coefficient} $r={\sigma_{xy}^{2}}/\sigma_{x}\sigma_{y}$.

{\bf \quad c)} Derive the distribution $p_{G}(x,y)$ from $p_{G}(u)$ and $p_{G}(v)$ used in a) to determine the covariance matrix $\Sigma$ and compare with b). [{\it bonus}: graph the contours $\chi^{2}=1$ and $\chi^{2}=2$ in a)]

{\bf \quad d)} Plot a 2d histogram of $(x,y)$ and calculate the $\chi^{2}$ statistic on all bins with greater than 10 entries.  What is the likelihood of the these random points following this distribution?

{\bf \quad e)} [{\it bonus}: Describe the procedure for generating random pairs $(x,y)$ from a general Gaussian distribution with means $\vec\mu$ and covariances $\Sigma$.  How does this generalize to higher dimension?]

\newpage

{\bf 3-d:} [{\it bonus}: The {\bf \href{}{Maxwell distribution}} of the energy of atoms in an ideal gas is just the $\chi^{2}$ distribution for $\nu=3$ degrees of freedom because each component of $\vec v=(v_{x},v_{y},v_{z})$ is normally distributed according to its Boltzmann factor $p_{B}(v_{x})=e^{-E/kT}$, where $E=v_{x}^{2}/2m$, etc.

{\bf \quad a)} Integrate the 3-d velocity distribution over spherical shells of thickness $dv$ to derive the Maxwell distribution of velocities $p_{M}(v)$.  Use the Gaussian generator of 2d) to generate 100,000 velocities in units of $\sqrt{mkT}$ and histogram them together with a plot of $p_{M}(v)$.

{\bf \quad b)} Equivalently, integrate the joint normal distribution $p(\vec\chi)=p_{G}(z_{1})p_{G}(z_{2})p_{G}(z_{2})$ over spherical shells of radius $du$ for $u=\vec\chi\cdot\vec\chi$ in the vector space $\vec\chi=(z_{1},z_{2},z_{3})$ to obtain $p_{\chi}(u;3)$.  Thus, show that the Maxwell energy distribution equals $p_{\chi}(v^{2}/mkT;3)$.

{\bf \quad c)} Calculate the mode $v_{max}$, mean $\bar v$, and RMS $v_{rms}=\sqrt{\langle v^{2}\rangle}$ of the Maxwell velocity distribution.
\ldots

{\bf $\bs \nu$-d:} [{\it bonus}: Higher dimensional $\chi^{2}$ distributions are used to test the consistency of distributions, for example, in labs X03 and X04.  Data are least-squares fit to a curve by minimizing a $\chi^{2}$ function.  In this case $\nu$ equals the number of Gaussian distributions (for example, the bins you are comparing) minus the number of constraints (for example, the parameters of a distribution or fit function).

{\bf \quad a)} Using the volume of a \href{https://en.wikipedia.org/wiki/Volume_of_an_n-ball}{$\nu$-dimensional ball} $V_{\nu}(\chi)=\pi^{n/2}\chi^{n}/\Gamma(n/2+1)$, integrate the $\nu$-d joint Gaussian distribution over hypershells to derive the $\chi^{2}$ distribution $p_{\chi}(u;\nu)$.  Plot the distribution for $\nu=1,2,3,\ldots,10$.

{\bf \quad b)} Show that as $\nu\to\infty$, $p_{\chi}(u;\nu)$ tends to the Gaussian distribution $p_{G}(u;\nu;2\nu)$.]

%{\bf \quad a)} Calculate the moments $M_{n_{1}n_{2}}=\int x_{1}^{n_{1}}dx_{1}x_{2}^{n_{2}}dx_{2}\, p_{G}(x_{1},x_{2})$ for $n_{0,1}=0,1,2$ to normalize $p_{G}$ and confirm the $\mu_{i}=\langle x_{i}$, variances $\Sigma_{i}=\langle x_{i}^{2}\rangle$, and covariance $\Sigma_{12}=\langle x_{1}x_{2}\rangle$ of $p_{G}$.

% For $\vec\mu=(2,1)$ and $\Sigma=\pmatrix{}$

% This readily generalizes to the $n$-dimensional Gaussian with the $n$-vector $\chi$ and $n\times n$ covariance matrix $\Sigma=W^{-1}$.

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
