\documentclass[12pt, twocolumn]{article}
\usepackage{hyperref}
\usepackage{graphicx}

\pagestyle{empty}

\begin{document}

\noindent \textbf{Physics 567}\\
\noindent \textbf{Homework 3}\\
\noindent Due Friday, February 9, 2024 \\

\vspace{0.5 in}

\noindent The Mandelbrot set is a fractal structure in the complex plane defined by the iterative mapping

\[
z_{n+1} = z_n^2 + z_0.
\]

If $\left| z_n \right| < 2$ as $n\rightarrow \infty$, then the point
$z_0$ is within the Mandelbrot set. Points outside the set will escape after some number of iterations; this number is called the \textit{count}. The set of points remaining in bounds after $n$ iterations is called the $n$th lemniscate.

\begin{center}
\includegraphics[width=\columnwidth]{plot_10Mpts_crop.png}
\end{center}

Write a program to estimate the area of the Mandelbrot set by Monte Carlo with random sampling. For a particular set of random complex values $z_0$ on the 2D interval $-2 < \mathrm{Re} (z_0) < 2$, $-2 < \mathrm{Im} (z_0) < 2$, the lemniscate area estimate will decrease as iteration count $n$ increases. Plot the change in area, $A_{n-1} - A_n$, as a function of $n$. Estimate \& plot a power law trend. 

Next, write a modified version of your program that chooses points $z_0$ by stratified sampling. Run both versions of your program for a range of $N$, the total number of points. Repeat enough times to get a reasonable estimate of the standard deviation at a given $N$. Plot how this converges with increasing $N$, and estimate \& plot power law trends for both kinds of sampling. In class, we estimated the convergence rate for stratified sampling, based on the premise of finding the volume of a $\nu $-dimensional object bounded by a $\nu - 1$-dimensional surface:
\begin{equation}\label{eq:dim}
   \mbox{fractional error} = 
   O \left( N^{ -\frac{1}{2} -\frac{1}{2\nu} } \right)
\end{equation}
The border of the Mandelbrot set, however, is not 1-dimensional!

Modify your code to generate an illustration of the Mandelbrot
set. There are many ways to do this. The picture above has varying color according to the count. It is a scatter plot of $10^7$ randomly distributed, color coded points---a very inefficient approach.
      
\textit{Hints.} Your code will run faster if it is vectorized, unless you waste cycles by continuing to iterate points that have already escaped ($|z|>2$). Octave/MATLAB has many features to facilitate efficient coding; for example, see ``using logicals in array indexing'' in the online MATLAB documentation. With the plots, the idea is to make accurate estimates at low computational cost, and extrapolate trends to large $n$ and large $N$. 

Feel free to consult outside references to check your work, but you should estimate errors and convergence rates based solely on your own calculations. Hand in all parts via email to the grader, including:

\begin{enumerate}
\item Your source code, commented so that it is readable.
\item All commands used to complete the assignment.
\item The requested plots:
   \begin{enumerate}
      \item Convergence (decrease in area from lemniscate $n-1$ to $n$) vs.\ $n$, with power law
         trend overplotted.
      \item Convergence (standard deviation in multiple independent area estimates) vs.\ total points $N$,
         for both sampling methods, with power law trends overplotted.
      \item Picture of the Mandelbrot set, generated by your code.
   \end{enumerate}
\item Include in the body of your email a concise, written discussion of the following questions:
   \begin{enumerate}
      \item Give your stratified sampling result for the area of the 
         Mandelbrot set, as displayed by MATLAB/Octave. What maximum 
         count, $n$, did you use, and how many points?
      \item Use the observed trend to extrapolate to
         $n \rightarrow \infty$, and give a corrected area.
      \item What statistical convergence rates, $O(N^{\mbox{what}})$, 
         do you observe for random sampling and for stratified sampling? 
      \item Estimate the uncertainty in your corrected area, and explain 
         the basis of your estimate.
      \item Generalize expression (\ref{eq:dim}) to the case where 
         the boundary
         has some dimension $q$, $0 \le q \le \nu $.
      \item Estimate the dimensionality of the boundary of 
         the Mandelbrot 
         set based on the actual rate of convergence for stratified 
         sampling.\footnote{
            Since the boundary can pass through a given
            sampling subdomain more than once, or even an infinite 
            number of times, the boundary
            dimension may easily exceed our numerical estimate.
            It has been shown that the fractal dimension of the
            Mandelbrot boundary is actually 2. This was not arrived
            at easily---there was controversy for years in the
            literature. 
         }
   \end{enumerate}
\end{enumerate}
\emph{In this and all future homework assignments, I encourage  you to make use of existing code including my examples and the built-in functions in Octave and Matlab.}

Useful references:
\begin{itemize}
   \item \url{http://en.wikipedia.org/wiki/Mandelbrot_set}
   \item \url{http://mathworld.wolfram.com/MandelbrotSet.html}
\end{itemize}

\end{document}