%Monte Carlo Integration
%If you modify this file, please indicate here and in the footnote
%Math263B
\documentclass[12pt]{article}
\usepackage{times}
\pagestyle{empty}
\topmargin -.2in
\headheight 0in
\addtolength{\textwidth}{1.2in}
\addtolength{\textheight}{1.2in}
\addtolength{\oddsidemargin}{-.58in}
\addtolength{\evensidemargin}{-.58in}
\renewcommand{\baselinestretch}{1.0}
\parindent = 0cm
\parskip = .1cm
\begin{document}
\begin{center}
\Large
Monte Carlo Integration\footnote{Copyright \copyright 2002 Larry Snyder and Todd Young.
All rights reserved. Please address comments to young@math.ohiou.edu.}
%modified by 2006 by Todd Young}
\end{center}
\begin{enumerate}
\item Type \verb& help rand & and read the first paragraph of resulting help page.
Next enter the following:\\
\verb& x = rand(10,1) &\\
\verb& y = x.^3 &\\
\verb& avg = sum(y)/10 &\\
Figure out what happens in these command before you proceed.
\item Enter the following sequence commands:
\begin{enumerate}
\item \verb&n = 10&
\item \verb&x = rand(n,1); avg=sum(x.^3)/n&
\item Use the $\uparrow$ key to recall this line
and then press \verb&Enter& again.
\item Obtain 10 estimates this way and record the values
you get along with the absolute error of each estimate.
You can have \textsc{MatLab} calculate the absolute error for
you conveniently by including at the end of line of \#1(b):
\verb& error = abs(.25 - avg)&.
\item Explain why this is an approximation of
$\int_0^1 x^3 \, dx$. (It has to do with the average of a function.)
\end{enumerate}
\item\label{exp} Enter the command \verb& n = 100 & and use the
$\uparrow$ key to recall the line in \#1(b) again. Press the
enter key to execute this line. Obtain and
record 10 estimates this way along with the absolute errors.
\item Repeat this process using \verb& n = 1000 & and \verb& n = 10000&.
\item Make a chart showing the relationship between the sample size
\verb&n& and the arithmetic mean of the absolute errors of
the estimates with sample size \textsf{n}. The data should reflect
the relationship $|E_n| \approx Kn^{-r}$. Use the data and
logarithms to determine the constants $K$ and $r$.
\item For the Trapezoid rule \verb$r = 2$ and for Simpson's rule \verb$r = 4$.
How does the random method introduced here compare with the Trapezoid and
Simpson's methods of numerical integration? Which is the most accurate, which
the least?
\item Prepare a brief written report answering all
the questions. Use complete sentences and standard mathematical notation.
Do {\bf not} get a printout.
\end{enumerate}
\vfill
\noindent
\textsf{This demonstrates the connection between averages and integrals.
Because this technique is efficient in
higher dimensions, variants (known as Monte Carlo methods) are actually used
in practice to evaluate integrals.}
\end{document}