% -*- latex -*-
% FILE: "/home/evmik/jobs/wm/2015_fall_practical_computing_for_scientists/hw05/hw05.tex"
% LAST MODIFICATION: "Wed, 23 Sep 2015 10:49:24 -0400 (evmik)"
% (C) 2010 by Eugeniy Mikhailov, <evgmik@gmail.com>
% $Id:$
\documentclass[letter,12pt]{article}

%---------------------------------------------------------------
\usepackage{listings}
\usepackage{color}
\usepackage{fullpage}
%---------------------------------------------------------------

\begin{document}
\newcommand{\problem}[1]{%
	{\flushleft  \bf #1\\}
}
\newcommand{\hw}[1]{%
	\begin{center}
		\Large  \bf Homework #1%
	\end{center}%
}
\newcommand{\mat}[1]{% matlab code
{\color{blue}\texttt{#1}}%
}

%---------------------------------------------------------------
\hw{05}

General comments: 
\begin{itemize}
	\item Do not forget to run some test cases. 
	\item Matlab has built-in numerical integration methods.  For
		example \mat{quad} is one of them. You might check
		validity of your implementations with answers produced by
		this Matlab built-in function. \mat{quad}
		{\bf requires your function to be able to work with an array of x
			points},
		otherwise it will fail.
	\begin{itemize}
		\item Of course, it is always better to compare to the exact
			analytically calculated value.
	\end{itemize}
\end{itemize}

\problem{Problem 1 (2 points)}
%---------------------------------------------------------------
Implement the rectangle numerical integration method. Call you function
\texttt{rectInt(f,a,b,N)}, where a and b  are left and right limits of integration,
N the number of points, and f is handle to the function.


\problem{Problem 2 (3 points)}
%---------------------------------------------------------------
Implement the trapezoidal numerical integration method. Call you function
\texttt{trapezInt(f,a,b,N)}.


\problem{Problem 3 (5 points)}
%---------------------------------------------------------------
Implement the Simpson numerical integration method. Call you function
\texttt{simpsonInt(f,a,b,N)}.
Remember about special form of N=2k+1.

\problem{Problem 4 (5 points)}
%---------------------------------------------------------------
Implement the Monte-Carlo numerical integration method. Call you function
\texttt{montecarloInt(f,a,b,N)}.

\problem{Problem 5 (5 points)}
%---------------------------------------------------------------
For your tests calculate 
\begin{eqnarray*}
	\int_0^{10} [\exp(-x)+(x/1000)^3] dx
\end{eqnarray*}
Plot the integral absolute error (not the estimates provided in class) 
for the above 4 methods vs different number of
points N. Try to do it from small N=3 to N=$10^6$. Use \texttt{loglog}
plotting function for better representation (make sure that you have enough
points in all areas of the plot).
Why the error start to grow with a larger N? Does it grow for all methods?

\problem{Problem 6 (5 points)}
%---------------------------------------------------------------
Calculate
\begin{eqnarray*}
	\int_0^{\pi/2}  \sin( 401 x) dx
\end{eqnarray*}
Compare your result with the exact answer 1/401.
Provide a discussion about required number of points to calculate
this integral. 
%---------------------------------------------------------------
\end{document}
%---------------------------------------------------------------
