% -*- latex -*-
% FILE: "/home/evmik/jobs/wm/2012_fall_practical_computing_for_scientists/hw04/hw04.tex"
% LAST MODIFICATION: "Mon, 17 Sep 2012 11:17:44 -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{04}

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 a vector
		argument},
		otherwise it will fail requires your function to be able to
		work with arrays, otherwise it will fail
	\begin{itemize}
		\item Of course it is always better when you  do it vs the
			analytically calculated integral.
	\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  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)}, where a and b  limits of integration,
N the number of points, and f is handle to the function.


\problem{Problem 3 (5 points)}
%---------------------------------------------------------------
Implement the Simpson numerical integration method. Call you function
\texttt{simpsonInt(f, a,b,N)}, where a and b  limits of integration,
N the number of points, and f is handle to the function.
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)}, where a and b  limits of integration,
N the number of points, and f is handle to the function.

\problem{Problem 5 (5 points)}
%---------------------------------------------------------------
For your tests calculate 
\begin{eqnarray*}
	\int_0^{10} [\exp(-x)+(x/1000)^3] dx
\end{eqnarray*}
Plot the absolute error of integration of 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 error start to grow with a larger N? Does it grows 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 exact answer 1/401.
Provide a discussion about required number of point to calculate
such integral. 
%---------------------------------------------------------------
\end{document}
%---------------------------------------------------------------
