% -*- latex -*-
% FILE: "/home/evmik/jobs/wm/2012_fall_practical_computing_for_scientists/hw08/hw08.tex"
% LAST MODIFICATION: "Wed, 31 Oct 2012 09:54:31 -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{08}

General comments: 
\begin{itemize}
	\item Do not forget to run some test cases. 
\end{itemize}

\problem{Problem 1 (5 points)}
%---------------------------------------------------------------
Modify provided traveler salesman combinatorial algorithm to solve 
a slightly different problem. You are looking for the shortest route which
goes through all cities, while starts and stops in the same city (first
one), i.e. the close loop route. 

Coordinates of cities are provided in the 'cities\_for\_combinatorial\_search.dat' file:
the first column  of
the data file is 'x' coordinate and second one contains 'y' coordinates.
The coordinates of the beginning/end route city are in the first string.  

What is the sequence of the cities in the shortest route?

What is the total length of the best route?

Provide the plot of the cities and the shortest route.



\problem{Problem 2 (10 points)}
%---------------------------------------------------------------
Implement Metropolis algorithm to solve above problem. Good way to obtain
new test route is to randomly swap two cities  along the route.
Tweak the algorithm number of cycles,  initial and final  temperature ($kT$).

Compare this algorithm solution  with the above combinatorial one.

Now load the cities coordinates from the 
'cities\_for\_metropolis\_search.dat' file.  Find the shortest route for
this cities.

What is the sequence of the cities in the shortest route?

What is the total length of the best route?

Provide the plot of cities and the shortest route.

\problem{Problem 3 (5 points)}
%---------------------------------------------------------------
Solve  numerically (using built-in \mat{ode45} solver) the following physical problem if the oscillatory motion
\begin{eqnarray*}
	x''(t) = - x(t)^p 
\end{eqnarray*}
with following initial conditions
\begin{eqnarray*}
	x(0)=0 \\
	v(0)=x'(0)=v_0
\end{eqnarray*}
Here the $x$ is position of the  particle, $t$ is time , $v$ is velocity,
$v_0$ is initial velocity, and $p$ is a parameter which takes odd values.

When $p=1$ the problem resembles the equation of motions for the well known
harmonic oscillator with $k/m=1$.

Solve this problem (i.e. plot  $x(t)$ and $v(t)$) for two values of the
parameter $p=1$ and $5$,  and  the initial velocity
$v_0=1$. Make sure to choose final time large
enough so you see at least 10 periods.

\problem{Problem 4 (5 points)}
%---------------------------------------------------------------
Show that the period of the oscillation is independent of $v_0$ for the
harmonic oscillator and  depends on $v_0$ for the case of $p=5$. 
Do it for at least five different values of $v_0$ to convince yourself.





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