% -*- latex -*-
% FILE: "/home/evmik/jobs/wm/2015_fall_practical_computing_for_scientists/final_exam.2015/final_exam_2015.tex"
% LAST MODIFICATION: "Mon, 07 Dec 2015 22:40:49 -0500 (evmik)"
% (C) 2010 by Eugeniy Mikhailov, <evgmik@gmail.com>
% $Id:$
\documentclass[letter,12pt]{article}

%---------------------------------------------------------------
\usepackage{wrapfig}
\usepackage{graphicx}% Include figure files
\usepackage{listings}
\usepackage{color}
\usepackage[margin=1in,letterpaper]{geometry}
%---------------------------------------------------------------

\begin{document}
\newcommand{\problem}[2]{%
	{\flushleft  \bf Problem #1 (#2 points)\\}
}
\newcommand{\mat}[1]{% matlab code
{\color{blue}\texttt{#1}}%
}
\newcommand{\subproblem}[1]{%
{\flushleft  {\bf Subproblem:} #1\\}
}

\newcommand{\tabme}[2] {
 {\flushleft%
		 \parbox{1in}{#1 }    \parbox{5in}{#2}%
 }%
}
%%
\renewcommand{\section}[1] {% do nothing 
%fake section to force vim latexsuite check spelling
}%

%---------------------------------------------------------------
%\title{Midterm 02}
%\author{Eugeniy E. Mikhailov}
%\date{\today}
%\date{}
%\maketitle
\begin{center}
{ \Large{Final Exam}} 
\end{center}

\section*{}% 
\begin{center}
	{\Large I am tired waiting for take off.} \\
	{ \bf Due date  for the electronic submission is Monday December 14th of 2015 at 1pm.}  \\
\end{center}

{\flushleft  \bf Your  goal  is to provide the best firing solution (aim
	parameters) for the launch platform.
125 potential points  total (95 for
writeup  + 5 maximum possible for competition + 25 for  the
presentation.}

We  will meet  at  2pm on  Tuesday  December  15th of  2015  for the  final
presentation and the project defense.

During  this time,  your team  will give  a 10  min presentation  about key
aspects  of  your  algorithm  with  other  relevant  information  presented
(equations, algorithms, plots, etc). Plan ahead and distribute presentation
time among teammates,  so everyone has a chance to  talk. The presentation value
is 25 points and it will be assigned to each speaker separately.

Members of other  teams are encouraged to ask questions related  to the project
and will be granted extra points depending on questions relevance.

{\flushleft \bf Algorithm evaluation:}

Your answers will be compared against those of  other teams. Each team's
solution will  be ranked  based on  the closest distance to a target and
the maximal relative velocity separation (see more below),  which are
achieved with aiming parameters provided by the team.
If  several teams get similar deviations
then the speed  of the
algorithm will decide who gets more points. The best team will get
5.0 points, the next best team, 4.5 points, and so on till 0.

The  competition  will  have  several   rounds:  one  with  solution  parameters
calculated  based on  the posted on  the web  problem files  for this  final and
others where  the aiming  problem  files will  be supplied during  the final
exam according to the specification outlined in the text below.

Your  code should  provide  {\bf  parameters} for  the  catapult aim  (see
requirements below).  To  solve the  problem, you need  your own
model simulation code, but it will not be  used in the competition. The simulation of
the solution will be done with the instructor's computer and code using the
input parameters supplied by your algorithm. So, make sure that physics is
done correctly.

All  tests will  be  run  during the  competition  on  the desktop  computer
available in the  class room. You are welcome to  test your algorithm there
before the competition.

%---------------------------------------------------------------


{\flushleft \bf Written report requirements:}

\begin{itemize}
	\item
		All regular requirements outlined in the syllabus.
	\item
		Discuss relevant  equations, describe your solution, show results.
	\item
		All Matlab code/scripts must be present in the carbon copy as well.
	\item
		Report should be less than 10 pages long (listings length
		is not counted).
	\item
		{Make all your calculations in the S.I. units (m, kg, s).}
\end{itemize}


\pagebreak

%---------------------------------------------------------------
{\flushleft \bf The problem:}
Aren't we all tired to wait for a take off time in an airport. This usually 
a place of the majors delay. Landing and taking off not only the most
dangerous part of an airborne journey, but also the most stressful time
for a plane's hardware, this is the time when something is likely to break
and,  then, repairs are needed which also contributes to delays.

Your start up decided to circumvent all of the above by removing necessity
of planes to take off and land. Food, fuel,  passengers,  and even pilots
will be delivered to the planes which never land with the help of a
catapult. If someone arrives to a destination, she just takes a parachute and
jumps, which is perfectly safe and can be done at your own desire. No more
annoying "buckle your belt and switch off your electronics".

The whole enterprise works like this, planes at different heights fly over
the catapult location one at a time, you on the ground aim the catapult with
certain elevation angle above the horizon (measured in radians) and
launch a capsule with a precious cargo toward the plane. The launch
parameters, i.e., the speed, the launch time, and the elevation angle, 
must be calculated in such
a way, that the capsule reaches the plane with zero relative velocity.
If this is not satisfied, the capsule would crush the plane and itself, and
you would lose all money in a law suit against you.

%---------------------------------------------------------------
{\flushleft \bf The model:}
To succeed,
you need to write  a capsule flight simulator.
A capsule is a sphere with a variable (from a capsule to
another capsule)   diameter ($D$); it has the launch/take off velocity ($V_e$), the  final speed of a capsule after escaping
from the  catapult at zero height; capsule  the drag coefficient ($C_d$), and the total, combined with the cargo, mass ($m$).

With these parameters, a capsule could fly through the stratosphere with much
smaller air density, so you need to take this into account, since future
planes might fly higher than the current cruising altitude of 10~km.
The crude approximation of the air density  ($\rho$) dependence on the altitude ($h$) 
above the Earth's surface is
\begin{eqnarray*}
	\rho(h) &=&  \rho_0  2^{-h/h_{1/2}}
\end{eqnarray*}
where $\rho_0=1.2$~kg/m$^3$
is the density of air at the Earth's surface, and $h_{1/2}=6800$~m is the
altitude at which density of air drops by factor of 2. Assume, that these 2
parameters are constant (it is unlikely that you would expand your business
to other planets in any near future).
Fortunately, you do not need to account for the curvature of the Earth or
change of the acceleration due to gravity ($g=9.80$~m/s$^2$).
We will assume that only gravity and the air drag are acting on the flying
capsule
\begin{eqnarray*}
	\vec{F} &=& m \vec{a} =  \vec{F}_g + \vec{F}_d \\
	\vec{F}_g  &=&  - m g \hat{y} \\
	\vec{F}_d &=&  - \frac{1}{2} \rho(h)  C_{d}  A  v \vec{v} \\
\end{eqnarray*}
where  $\vec{F}_g$ is the gravitational pull force, $\vec{F}_d$ air drag
force, $\hat{y}$ is the unit vector in the 'y' direction (we assume it
points up), $A$ is the area of the capsule, and $\vec{v}$ is the velocity of
the projectile.

The plane, to which we need to land our capsule, moves strictly horizontally in
the positive $\hat{x}$ direction, and at time $t_0=0$ is directly above the
catapult.

We assume that our catapult is surrounded
by a flat landscape.

{\flushleft \bf For the following assignments, make sure that you follow
the exact specification of the functions.}

\problem{1}{20}
Write a capsule flight simulator, which takes a given capsule  launch
parameters and calculates the x and y position of the capsule vs. time. The
time {\bf must} span from zero till the time when the capsule hits the ground,
i.e., no underground motion and  a trajectory truncation in mid-flight are permitted. 
Clearly, there is some uncertainty. So, the trajectory may be cut when
\mat{abs( y(time(end)) ) <= 0.001}~m.
The function must follow  {\bf precisely} the specification below

\lstset{language=matlab}
\lstinputlisting[]{functions_template/capsule_flight_simulator.m}

Where \mat{m} is the capsule mass, \mat{D} is its diameter, \mat{Ve} is the
capsule escape/launch velocity,
\mat{Cd} is the capsule drag coefficient, and  \mat{ElAng} is the elevation angle in {\bf radians}.

Plot the trajectory of the capsule for parameters supplied at the web.

\problem{2}{20}
Write the function which finds the maximum height which capsule can reach,
the time after the launch when the maximum height is reached, the x
coordinate and the x velocity
component of the capsule at this time.
The solution function must comply to the following specification

\lstset{language=matlab}
\lstinputlisting[]{functions_template/capsule_max_height_parameters.m}

Present the results of this function in your report for the parameters
posted at the web.


\problem{3}{35}

Write the function {\bf precisely} following the specification which
finds a launch parameters for the capsule and the plane parameters  provided in a file.
\lstset{language=matlab}
\lstinputlisting[]{functions_template/capsule_launch_solution.m}

Where \mat{ElevationAngle} is the launch elevation angle in radians with
respect to horizon and positive x direction, \mat{Vescape} is the capsule
escape velocity at separation with the catapult time, and \mat{Tlaunch} is
the time of launch. The \mat{Tlaunch} could be negative if needed. Recall
that 0 time is the time when the plane is directly above the catapult.

The parameters file will contain variables defining the capsule properties
\mat{m}, \mat{Cd}, \mat{D}, and variables regarding the horizontal velocity
component  of the plane (\mat{Vxplane}) and its altitude/height (\mat{Hplane}).

The solution is evaluated by how small will be the following {\bf at the capsule
maximum height}
\begin{equation}
	E = | \vec{r}_{plane} - \vec{r}_{capsule} |^2 + | \vec{v}_{plane} -
	\vec{v}_{capsule}|^2
\end{equation}

During the final you will be provided with different parameters files.
You algorithm should be able to work with all of them them.

\problem{4}{20}

This is  a problem to  solve at  home.

To launch  the capsule you  need the permission  codes from a customer,
after all, the customer decides when he wants to departure.
This code is delivered  to you as a radio voice  message. However, a
competing company tries to  jam the  transmission. The voice message
recording  will have  a lot  of  noise. Each  team  will get  its own voice recording 
of the code, available  on the  web site.  What is your
code (it should be a 6 digit number)?



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