% -*- latex -*-
% FILE: "/home/evmik/jobs/wm/2012_fall_practical_computing_for_scientists/hw02/hw02.tex"
% LAST MODIFICATION: "Fri, 07 Sep 2012 23:00:37 -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}%
}


%---------------------------------------------------------------
%\title{Homework 02}
%\author{Eugeniy E. Mikhailov}
%\date{\today}
%\date{}
%\maketitle
\hw{02}

Prerequisites: read help about 'plot', 'linspace', and 'print'. Do not
forget about test cases.

\problem{Problem 1 (2 points)}
%---------------------------------------------------------------
Plot the function $f(x)=\exp(-x^2/10)*\sin(x)$ for 400 linearly spaced points of $x$
in the region from $0$ to $2 \pi$. 
Points should be joined with solid lines.

Do not use any cycles or loops. Include the resulting figure in your report.

\problem{Problem 2 (2 points)}
%---------------------------------------------------------------
Plot functions $x^2$ and $x^3/2+0.5$ for $100$ linearly spaced points of $x$
in the region from $-1$ to $+1$. 
$x^2$ should be red solid line and $x^3$ should be black dashed line.
Do not worry about black and white printouts as long as colors are present
in pdf report file.

Do not use any cycles or loops. Include the resulting figure in your report.

\problem{Problem 3 (3 points)}
%---------------------------------------------------------------
Write a script which calculates
\begin{equation}
	1+\sum_{i=1}^N \frac{1}{x^i}
\end{equation}
for $N=10$ and $x=0.1$

Use loops as much as you wish from now.

\problem{Problem 4 (3 points)}
%---------------------------------------------------------------
Write a script which calculates for $N=100$.
\begin{equation}
	S_N = \sum_{k=1}^N a_k
\end{equation}
where $a_k={1}/{k^{2k}}$ for odd $k$ and $a_k={1}/{k^{3k}}$ for even $k$. 

Hint: you may find {\bf mod} function useful to check for even and odd
numbers.

\problem{Problem 5 (5 points)}
%---------------------------------------------------------------
Write a function \texttt{mycos} which calculates a value of a $\cos(x)$ at the
given point $x$ via the Taylor series up to N members.
Define your function as\\
\texttt{ function cosValue = mycos(x, N) }

Does  it  handle well  the  situation  with  large  $x$? Take  for  example
$x=10\pi$. How  far do  you need  to expand Taylor  series to  get absolute
precision of $10^-4$, what value of $N$  do you find reasonable (no need to
state it beyond one significant digit), why so?


\problem{Problem 6 (5 points)}
%---------------------------------------------------------------

Download  data   file  ``hw02dataset.dat''  from  the   class  webpage.  It
represents result  of someone attempt  to find  resistance of a  sample via
measuring voltage  drop ($V$),  which is  the data in  the 1st  column, and
current ($I$) listed in the 2nd  column passing through the resistor at the
same  conditions. Judging  by the  number of  samples it  was an  automated
measurement.

\begin{itemize}
	\item Using Ohms law $R=V/I$ find the resistance ($R$) of this sample 
		(no need to print it out for each point at this step)
	\item Estimate the resistance of the sample (i.e. find the
		average resistance)  and  estimate the error bars of this estimate
		(i.e. find the standard deviation).
\end{itemize}

For standard deviation use the following definition
\begin{equation}
\sigma (x) = \sqrt{\frac{1}{N-1} \sum_{i=1}^N (x_i - \bar{x})^2}
\end{equation}
where $x$ is the set (vector) of data points, $\bar{x}$ its average (mean),
and $N$ is the number of the points in the set.

{\bf Do not use} standard built in \texttt{mean} and \texttt{std} functions
in your solution. You need to make your own code to do it. But feel free to 
test against these matlab functions.

Note: read  help for matlab's \texttt{std}  it has an option  and you might
want to know about it.

%---------------------------------------------------------------
\end{document}
%---------------------------------------------------------------
