% -*- latex -*-
% FILE: "/home/evmik/jobs/wm/2016_fall_practical_computing_for_scientists/hw03/hw03.tex"
% LAST MODIFICATION: "Mon, 12 Sep 2016 11:09:19 -0400 (evmik)"
% (C) 2010 by Eugeniy Mikhailov, <evgmik@gmail.com>
% $Id:$
\documentclass[letter,12pt]{article}

%---------------------------------------------------------------
%\usepackage{listings}
\usepackage[framed]{matlab-prettifier}
\usepackage{color}
\usepackage{fullpage}
\usepackage{enumitem} % control over itemize, list environment
%---------------------------------------------------------------

\begin{document}
\newcommand{\hwtitle}[1]{%
	\begin{center}
		\Large  \bf Homework #1%
	\end{center}%
}

\newcommand{\mat}[1]{% matlab code
%{\color{blue}\texttt{#1}}%
	% this one does not work inside of captions
	{\lstinline[style = Matlab-editor, basicstyle = \mlttfamily, columns=fixed]!#1!}%
	% this one work but style is different
	%{\lstinline[columns=fixed]!#1!}%
}
%---------------------------------------------------------------
\newcommand{\problem}[1]{% homework problem
	%{\item  \bf #1%}
\item {\bf #1{}:}% the next blank line is important

}

\newenvironment{homework}[2]%
{%
	\hwtitle{#1}
	#2% Prerequisits

	\begin{enumerate}[
		label={\bf Problem\ \arabic*}, 
		leftmargin=0pt,
		start,
		labelindent=0pt,
		widest=20, align=left, itemindent=!
		]
}%
{%
	\end{enumerate}
}%
%---------------------------------------------------------------

%---------------------------------------------------------------
\begin{homework}{03}{
%Prerequisites:
General requirements/comments: 
\begin{itemize}
	\item Review the function handle operator
		\mat{@}: use \mat{help function_handle}.
	\item Pay attention to error bars/uncertainties; {\bf report them}.
	\item Everywhere in this homework use built-in \mat{fittype}
		to define a fitting function with the following call to \mat{fit}
		to do the fitting.
	\item All data files are provided at the class web page.
\end{itemize}
}

\problem{(5 points)}
%---------------------------------------------------------------
Recall one of the problems from the previous homework 2.

Download  data   file  \mat{'hw02dataset.dat'}  from  the   class  web page.  It
represents the result  of someone's attempt  to find  the 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.
Judging  by the  number of  samples it  was an  automated
measurement.

Using Ohm's law $V=R I$  and a linear fit of the data  with one free parameter ($R$)
find the resistance ($R$) of this sample. What are the
errorbars/uncertainty of this estimate? Does it come close to the one which
you obtained via the method used in homework 2? Do not use the fitting menu available
via the GUI interface, use a script or a function to do it.

\problem{(5 points)}
%---------------------------------------------------------------
You are making a speed detector based on the Doppler effect. Your device detects
dependence of the signal strength vs. time, which is recorded in the
\mat{'hw_fit_cos_problem.dat'} file (the first column is time and the second is the
signal strength).

Fit the data with 
\begin{eqnarray*}
	A \cos(\omega t +\phi)
\end{eqnarray*}
where $A$,  $\omega$ and $\phi$ are the amplitude, the frequency and the phase of the signal, and $t$ is time.

Find fit parameters (the amplitude, the frequency and the phase of the
signal) and their uncertainties. 

\problem{(Bonus 2 points)}
This is for the physicists among us.
Provided that the above radar was using radio frequency, could you estimate
the velocity measurement uncertainty? Is it a good detector to measure a
car's velocity?


\problem{(5 points)}
%---------------------------------------------------------------
Experiment to do at home. Make a pendulum of variable length (0.1m, 0.2m,
0.3m, and so on up to 1m). Measure how many round trip (back and forth) swings the
pendulum with each particular length does in 20 seconds (clearly you will have to round to the nearest
integer).
Save your observations into the simple text file with 'tab' separated
columns. The first column should be the length of the pendulum in meters,
the second column the number of full swings in 20 seconds.

Write a script which loads this data file, and extract acceleration due to
gravity ($g$) from the properly fitted experimental data.
Recall that the period of the oscillation of
a pendulum with the length $L$ is given by the following formula
\begin{eqnarray*}
	T = 2 \pi \sqrt{ \frac{L}{g} }
\end{eqnarray*}

\problem{(5 points)}
%---------------------------------------------------------------
In optics, the propagation of the laser beams is often described in the
Gaussian beams formalism. Among other things, it says that the optical beam
intensity cross section is described by the Gaussian profile (hence, the name of
the beams)
\begin{eqnarray*}
	I(x) = A \exp{\left( -\frac{(x-x_o)^2}{w^2} \right)} + B
\end{eqnarray*}
where $A$ is the amplitude, $x_o$ is the position of the maximum intensity,
$w$ is the characteristic width of the beam (width at $1/e$ intensity
level), and $B$ is the background illumination of the sensor.

Extract  the  $A$, $x_o$, $w$, and  $B$ with their uncertainties  from the real
experimental data  contained in the file  \mat{'gaussian_beam.dat'}, where the
first column is the position ($x$) in  meters and the second column is the beam
intensity in arbitrary units. 

Is the suggested model describe the experimental data well? Why so?

\problem{(Bonus 2 points)}
Fit the data from the file \mat{'data_to_fit_with_Lorenz.dat'} with the above Gaussian
profile. Is the resulting fit  good one or not? Why so? Compare it to the
Lorentzian model, which we discussed during the lecture.

\end{homework}
\end{document}
