% -*- latex -*-
% FILE: "/home/evmik/jobs/wm/2015_fall_practical_computing_for_scientists/hw09/hw09.tex"
% LAST MODIFICATION: "Sat, 07 Nov 2015 22:19:11 -0500 (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{09}

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

\problem{Problem 1 (5 points)}
%---------------------------------------------------------------
The model for a more realistic pendulum. 
Solve  numerically (using the built-in \mat{ode45} solver) the following
physical problem of a pendulum's motions
\begin{eqnarray*}
	\theta''(t) = - \frac{g}{L} \sin(\theta)
\end{eqnarray*}
where $g$ is acceleration due to gravity ($g$=9.8 m/s$^2$), $L=1$ is the
length of the pendulum, and $\theta$ is the  angular deviation of the pendulum
from the vertical.

Assuming that the initial angular velocity ($\beta$) is zero, i.e., 
$\beta(0)=\theta'(0)=0$,
solve this problem (i.e., plot  $\theta(t)$ and $\beta(t)$) for two values of the
initial deflection $\theta(0)=\pi/10$ and $\theta(0)=\pi/3$. Both solutions
must be presented on the same plot.
Make final time large enough to include at least 10 periods.
Show that the period of the pendulum depends on the initial deflection.
Does it takes longer to make one swing with a larger or smaller initial
deflection?

\problem{Problem 2 (5 points)}
%---------------------------------------------------------------
Implement the forth-order Runge-Kutta method (RK4) according to the recipe
outlined in the slides for lecture 20. It should be input compatible to the
home-made Euler's implementation \mat{odeeuler.m}. Compare the solution of
the above problem done with your own RK4 implementation to the built-in \mat{ode45}
solver.



\problem{Problem 3 (5 points)}
%---------------------------------------------------------------
Have a look at the predator and prey model (the \mat{ode\_predator\_prey\_model.m}
file provided with lecture 20 notes).

Find non trivial solution (i.e. $x_0 \ne 0$ and $y_0 \ne 0$) for which
population of wolves and rabbits is independent of time (i.e.
$dx/dt=dy/dt=0$). You should get a system of two linear equations which is
super simple. However, I ask you to solve it using  matlab numerical solver
methods which we discussed during the lecture 21, i.e., form the matrix A
and the column vector
B, and find x which satisfies $A*x=B$.  Note: use constants a, b, c, and d provided
in matlab file.

So, we see that it possible to have stable populations (or economy without
ups and downs) but you need to be smart about initial conditions.

What is the expected shape of the plot of the  wolves population vs  rabbit's
one with calculated above initial conditions? 
Plot it. 


\problem{Problem 4 (5 points)}
%---------------------------------------------------------------
It is possible to draw a parabola through any 3 points in a plane.
Using the matlab linear equations solver find coefficients $a, b$ and $c$ for parabola
described as
$y=a x^2 +b x +c$. This parabola passes through points $p_1=(-10,10), p_2=(-2,12)$,
and $p_3=(12,10)$.

\problem{Problem 5 (5 points)}
%---------------------------------------------------------------
Using the matlab \mat{interp1} with \mat{spline} method, find where
the interpolation line crosses $y=0$ level. The interpolation is done over the
following points [(x,y) notation]: (2,10), (3,8), (4,4), (5,1), (6,-2).

Would it be wise  to search crossing with $x=0$ line using the above data? Why
so?

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