\documentclass[11pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage{setspace}
\onehalfspacing
\usepackage{graphicx}
\graphicspath{report_images/}
\usepackage{appendix}
\usepackage{listings}
\usepackage{float}

% DOCUMENT INFORMATION =================================================
\title {ECEN 429: Introduction to Digital Systems Design Laboratory \\ North Carolina Agricultural and Technical State University \\ Department of Electrical and Computer Engineering} % Declare Title
\author{Reporter: Chris Cannon \\ \and Partner: Nikiyah Beaulah} % Declare authors
\date{February 1, 2018}
% ======================================================================

\begin{document}

\maketitle % Render Title, Author, and Date

\begin{center}
Lab	1
\end{center}

\pagebreak

\section{Introduction}
For this first lab our task was to familiarize ourselves with Xilinx Vivado Design Suite and the Digilent Basys3 FPGA Development Board that is used in this lab. During these tasks we learned how to configure the settings on Vivado for our board and how to load a program to the board. We also have three programming assignments for this lab. The first assignment was to write a simple VHDL program using an AND gate with two inputs and one output. The second assignment was to write a VHDL program using the car alarm example which that we derived in class. Our car alarm consists of 3 inputs using switches and 2 outputs using LED lights.  The third assignment was to create our own design implementation and write a VHDL program using only 4 inputs and 3 outputs. For our third assignment, we elected to build an adder for two 2-bit numbers. Upon successfully completing this lab, we will be able to work comfortable translating our circuit designs and VHDL code to a Vivado project and implement it on the Basys3 board.

\section{Background, Design Solution, and Results}
\subsection{Problem 1: 2-bit AND Gate}
The objective of this problem is to implement a single 2-bit AND gate and a single 2-bit OR gate in VHDL using the Basys3. The circuit diagram for this problem is in Figure 1.

\subsubsection{Background and Design Solution}

\begin{figure}[h]
	\includegraphics[width=\textwidth]{report_images/img1}
	\caption{\label{fig:figure-name}Circuit diagram for AND gate and OR gate.}
\end{figure}

The inputs for this problem are labeled as 'A', 'B', and 'C'. The outputs are labeled 'D' and 'E'. The outputs are the product of an AND gate and an OR gate, respectively. This is demonstrated by the truth table shown in Table 1. The assignments for these pins were given by the instructions, and are shown in Table 2.

\begin{table}[h]
\begin{center}
	\begin{tabular}{| l | l | l | l | l |}
		\hline
		A & B & C & D & E \\ \hline
		0 & 0 & 0 & 0 & 0 \\ \hline
		0 & 0 & 1 & 0 & 1 \\ \hline
		0 & 1 & 0 & 0 & 1 \\ \hline
		0 & 1 & 1 & 0 & 1 \\ \hline
		1 & 0 & 0 & 0 & 0 \\ \hline
		1 & 0 & 1 & 0 & 1 \\ \hline
		1 & 1 & 0 & 1 & 1 \\ \hline
		1 & 1 & 1 & 1 & 1 \\ \hline
	\end{tabular}
	\caption{\label{tab:table-name}Truth Table for Problem 1.}
\end{center}
\end{table}

\begin{table}[h]
\begin{center}
	\begin{tabular}{| l | l | l |}
		\hline
		Bit & Label & Address\\ \hline
		A & Switch 0 & V17 \\ \hline
		B & Switch 1 & V16 \\ \hline
		C & Switch 2 & W16 \\ \hline
		D & LED 7 & V14 \\ \hline
		E & LED 6 & U14 \\ \hline
	\end{tabular}
	\caption{\label{tab:table-name}Input and output bit specifications for problem 1.}
\end{center}
\end{table}

\subsubsection{Results}

This design functioned very easily, and we were able to observe each output 'D' and 'E' for every combination of 'A', 'B', and 'C'. They are shown in Figures 2-9.

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part1/IMG_0403.jpg}
	\caption{\label{fig:figure-name}All switches (Switch 0, Switch 1, and Switch 2) are off, therefore all outputs are off (LED 6 and LED 7)}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part1/IMG_0404.jpg}
	\caption{\label{fig:figure-name}Only input 'A' is on, shown at Switch 0, therefore both outputs are off (LED 6 and LED 7)}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part1/IMG_0405.jpg}
	\caption{\label{fig:figure-name}Only input 'B' is on, shown at Switch 1, therefore Output 'D' is on (LED 6) and 'E' is off (LED 7).}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part1/IMG_0406.jpg}
	\caption{\label{fig:figure-name}Inputs 'A' and 'B' are on, shown at Switch 0 and Switch 1 respectively, therefore both outputs are on (LED 6 and LED 7).}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part1/IMG_0407.jpg}
	\caption{\label{fig:figure-name}Only input 'C' is on, shown at Switch 2, therefore Output 'D' is on (LED 6) and 'E' is off (LED 7).}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part1/IMG_0408.jpg}
	\caption{\label{fig:figure-name}Inputs 'A' and 'C' are on, shown at Switch 0 and Switch 2 respectively., therefore only Output 'D' is on (LED 6) and 'E' is off (LED 7).}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part1/IMG_0409.jpg}
	\caption{\label{fig:figure-name}Both inputs 'B' and 'C' are on, shown at Switch 1 and Swtich 2 respectively, therefore Output 'D' is on (LED 6) and 'E' is off (LED 7).}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part1/IMG_0410.jpg}
	\caption{\label{fig:figure-name}All inputs are on (Switch 1, Switch 2, Switch 3), therefore both outputs are on (LED 6 and LED 7).}
\end{figure}

\subsection{Problem 2: Car Alarm}

Problem 2 referenced a car alarm system designed in class. The car alarm is made up of two sensors, a vibration sensor ('V') and a door sensor ('D'). The system is considered "active" when the master switch ('M') is activated. The car alarm has one output, an alarm siren ('S'). The logical circuit diagram for this is Figure 10.

\subsubsection{Background and Design Solution}

\begin{figure}[h]
	\includegraphics[width=\textwidth]{report_images/img2}
	\caption{\label{fig:figure-name}Circuit diagram for car alarm.}
\end{figure}

As shown in Figure 10, the inputs 'V' and 'D' are tied to the same OR gate, because either the vibration sensor or the door sensor can trigger an alarm if and only if the master switch is activated. Input 'M' is tied to an AND gate to show that the sensors can only trigger an alarm when this input is active. 'S' is the only output and we assume, based on the instructions of this exercise, that this output would be tied to some siren device such as the vehicle's horn or another audio device. The pin assignments for each input and output was given as part of the assignment and is summarized in Table 4.

\begin{table}[h]
\begin{center}
	\begin{tabular}{| l | l | l | l |}
	\hline
	D & V & M & S \\ \hline
	0 & 0 & 0 & 0 \\ \hline
	0 & 0 & 1 & 0 \\ \hline
	0 & 1 & 0 & 0 \\ \hline
	\end{tabular}
	\caption{\label{tab:table-name}Truth table for the car alarm.}
\end{center}
\end{table}

\begin{table}[h]
\begin{center}
	\begin{tabular}{| l | l | l |}
		\hline
		Bit & Label & Address \\ \hline
		D & Button L & W19 \\ \hline
		V & Switch 15 & R2 \\ \hline
		M & Button R & T17 \\ \hline
		S & LED 0 & U16 \\ \hline
	\end{tabular}
	\caption{\label{tab:table-name}Input and output bit specification for car alarm.}
\end{center}
\end{table}

\subsubsection{Results}

The design created in class functioned well and we were able to test each possible combination of inputs and observe their output. We compared these results to our truth table to find that this design worked properly. The results of these trials can be viewed in Figures 11-17.

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part2/IMG_0411.jpg}
	\caption{\label{fig:figure-name}With no inputs active, the output (LED 0) is off. }
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part2/IMG_0412.jpg}
	\caption{\label{fig:figure-name}With the vibration sensor (Switch 15) active, output (LED 0) is still off because the master switch (Button R) is not active.}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part2/IMG_0413.jpg}
	\caption{\label{fig:figure-name}With the vibration sensor active (Switch 15) and the master switch (Button R) active, output (LED 0) is active.}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part2/IMG_0414.jpg}
	\caption{\label{fig:figure-name}With the door switch active (Button L) and the master switch inactive (Button R) the output is not active (LED 0).}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part2/IMG_0415.jpg}
	\caption{\label{fig:figure-name}With both the master switch (Button R) and the door switch (Button L) active, the output is active (LED 0).}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part2/IMG_0416.jpg}
	\caption{\label{fig:figure-name}With all inputs (Switch 15, Button R, Button L active, the output is active (LED 0).}
\end{figure}

\begin{figure}[H]
	\includegraphics[width=\textwidth]{report_images/Lab1BoardPictures/Lab1Part2/IMG_0417.jpg}
	\caption{\label{fig:figure-name}With only the master switch active (Button R), the output is not active (LED 0). }
\end{figure}

\subsection{Problem 3: Design Our Own Circuit}

\subsubsection{Background and Design Solution}

For our own circuit design, we implemented a simple adder for two 2-bit numbers. Our circuit consists of two full adders with ripple carry. There is assumed to be no carry-in for this system so the carry-in for our least significant bit adder is tied to 0. This design utilizes a component that reuses VHDL code for each full bit adder. This improved our practical understanding of components and streamlined the code process. The two bit numbers x and y are denoted as 'X1', 'X0', 'Y1', and 'Y0' where 1 is the most significant bit and 0 is the least significant bit of the respective number. The output, z, is represented as the bits 'Z1' and 'Z0', where 1 is the most significant bit and 0 is the least significant bit. The carry-out bit is represented by 'cout'. The full adder circuit is displayed in Figure 3 and the 2-bit adder is shown in Figure 18.

\begin{figure}
	\includegraphics[width=\textwidth]{report_images/img3}
	\caption{\label{fig:figure-name}Circuit diagram for a full adder}
\end{figure}

\begin{figure}
	\includegraphics[width=\textwidth]{report_images/img4}
	\caption{\label{fig:figure-name}Circuit diagram for the 2-bit adder implemented for this assignment}
\end{figure}

When completing the pin-mapping for this problem, we prioritize ease-of-use and readability for the user. All bits are entered and displayed with the most significant bit on the right, and each 2-bit number is in a distinct location on the Basys3 board. These assignments are summarized in Table 5. The truth table for the addition of two 2-bit numbers is outlined in Table 6.

\begin{table}[h]
\begin{center}
	\begin{tabular}{| l | l | l |}
		\hline
		Bit & Label & Address \\ \hline
		X0 & Switch 0 & V17 \\ \hline
		X1 & Switch 1 & V16 \\ \hline
		Y0 & Switch 14 & T1 \\ \hline
		Y1 & Switch 15 & R2 \\ \hline
		Z0 & LED 0 & U16 \\ \hline
		Z1 & LED 1 & E19 \\ \hline
		Cout & LED 15 & L1 \\ \hline
	\end{tabular}
	\caption{\label{tab:table-name}Input and output bit specification for adding two 2-bit numbers.}
\end{center}
\end{table}

\begin{table}[h]
\begin{center}
	\begin{tabular}{| l | l | l | l | l | l | l |}
		\hline
		X1 & X0 & Y1 & Y0 & Cout & Z1 & Z0 \\ \hline
		0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \hline
		0 & 0 & 0 & 1 & 0 & 0 & 1 \\ \hline
		0 & 0 & 1 & 0 & 0 & 1 & 0 \\ \hline
		0 & 0 & 1 & 1 & 0 & 1 & 1 \\ \hline
		0 & 1 & 0 & 0 & 0 & 0 & 1 \\ \hline
		0 & 1 & 0 & 1 & 0 & 1 & 0 \\ \hline
		0 & 1 & 1 & 0 & 0 & 1 & 1 \\ \hline
		0 & 1 & 1 & 1 & 1 & 0 & 0 \\ \hline
		1 & 0 & 0 & 0 & 0 & 1 & 0 \\ \hline
		1 & 0 & 0 & 1 & 0 & 1 & 1 \\ \hline
		1 & 0 & 1 & 0 & 1 & 0 & 0 \\ \hline
		1 & 0 & 1 & 1 & 1 & 0 & 1 \\ \hline
		1 & 1 & 0 & 0 & 0 & 1 & 0 \\ \hline
		1 & 1 & 0 & 1 & 1 & 0 & 0 \\ \hline
		1 & 1 & 1 & 0 & 1 & 0 & 1 \\ \hline
		1 & 1 & 1 & 1 & 1 & 1 & 0 \\ \hline
	\end{tabular}
	\caption{\label{tab:table-name}Truth table for adding two 2-bit numbers}
\end{center}
\end{table}

\subsubsection{Results}

While this circuit did require our own design, we were able to successfully implement the full adder component in VHDL. This can be viewed in Appendix E. Once again, we were able to view the combination of inputs and resulting output. By comparing these to our truth table, we verified that our design worked properly. These trials are documented in Figure PICS.

\section{Conclusion}

In conclusion, all three design challenges were successfully implemented on the Basys3 board. Moreover, by successfully implementing these designs we have been able to accomplish the primary goal of the lab, which was gaining proficiency with both the Vivado Design Suite and the Digilent Basys3 Development board. The most challenging part of this lab was continuing to fine-tune designs after lab hours. Technically, configuring Vivado to run on a personal computer was quite challenging, but it offered a deeper insight to the overall operations of the design suite, which aided the lab in accomplishing it's mission. Implementing a full program including a component in VHDL also offered a challenge as there are several additional lines of code, such as a USE statement, that needed to be repeated for different entities. At first, this caused a code compilation error, but was corrected. Overall, the results of this lab are as expected, we were able to complete all three tasks, and have gained confidence in using the Vivado Design Suite with the Digilent Basys3.

\pagebreak

\begin{appendices}

\section{Part 1 VHDL Code}

\begin{lstlisting}[language=VHDL]
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- This entity will perform 2 operations with 3 inputs. The result of
-- each operation will be output to a bit.
entity lab1part1 is
    Port ( a : in STD_LOGIC;
        b : in STD_LOGIC;
        c : in STD_LOGIC;
        d : out STD_LOGIC;
        e : out STD_LOGIC);
	end lab1part1;

architecture Behavioral of lab1part1 is

begin
   	-- Output 'D' will be the result of 'A' AND 'B'
   	d <= a and b;
   	-- Output 'E' will be the result of 'B' OR 'C'
   	e <= b or c;

end Behavioral;
\end{lstlisting}

\section{Part 1 Constraints File}

\begin{figure}[h]
	\includegraphics[width=\textwidth]{report_images/img5}
\end{figure}

\section{Part 2 VHDL Code}

\begin{lstlisting}[language=VHDL]
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- This entity has 3 inputs, the master switch, vibration sensor, and door sensor
-- described in the car alarm problem. The siren is the only output.
entity lab1part2 is
    Port ( m : in STD_LOGIC;
           v : in STD_LOGIC;
           d : in STD_LOGIC;
           s : out STD_LOGIC);
end lab1part2;

architecture Behavioral of lab1part2 is

-- tmp1 is required to carry the sensor state from the sensor OR gate to the master
-- switch AND gate
signal tmp1 : STD_LOGIC;

begin

    --tmp1 tells whether or not a sensor is active
    tmp1 <= v or d;
    --'S' will be set to high when both the master switch AND a sensor are active
    s <= m and tmp1;

end Behavioral;
\end{lstlisting}

\pagebreak

\section{Part 2 Constraints File}

\begin{figure}[h]
	\includegraphics[width=\textwidth]{report_images/img6}
\end{figure}

\section{Part 3 VHDL Code}

\begin{lstlisting}[language=VHDL]
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- The following two lines declare the full_adder, which will later be
-- used as acomponent. The full adder takes two 1-bit numbers and a
-- carry-in, and adds them.
entity full_adder is port(a, b, cin: in STD_LOGIC; sum, cout :out STD_LOGIC);
end entity full_adder;

architecture adder_arch of full_adder is
begin
    -- The comparison of a, b, and cin will determine the output
    process(a, b, cin);
    begin
    -- Every possible case is documented and outputs are assigned.
    if (a = '0' and b = '0' and cin = '0') then (cout <= '0' & sum <= '0');
		elsif (a = '0' and b = '0' and cin = '1')
			then (cout <= '0' & sum <= '1');
		elsif (a = '0' and b = '1' and cin = '0')
			then (cout <= '0' & sum <= '1');
		elsif (a = '0' and b = '1' and cin = '1')
			then (cout <= '1' & sum <= '0');
		elsif (a = '1' and b = '0' and cin = '0')
			then (cout <= '0' & sum <= '1');
		elsif (a = '1' and b = '0' and cin = '1')
			then (cout <= '1' & sum <= '1');
		elsif (a = '1' and b = '1' and cin = '0')
			then (cout <= '1' & sum <= '0');
		elsif (a = '1' and b = '1' and cin = '1')
			then (cout <= '1' & sum <= '1');
	end if;
	end process;
end architecture adder_arch;

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- This entity is the top-level entity of this program. It will add two
-- 2-bit numbers. The carry-in for the least significant bit addition
-- is assumed to be 0 for this closed system.
entity lab1part3 is
    Port ( x1 : in STD_LOGIC;
           x0 : in STD_LOGIC;
           y1 : in STD_LOGIC;
           y0 : in STD_LOGIC;
           z1 : out STD_LOGIC;
           z0 : out STD_LOGIC;
           cout : out STD_LOGIC);
end lab1part3;

architecture adder of lab1part3 is
-- This signal is needed to relay the carry-out of the least significant
--  bit operation to the carry-in of the most significant bit operation.
signal tmpcarry:STD_LOGIC;

-- This declares a full_adder component based on the entity above. This
-- declaration is only needed once in order to use the full_adder twice.
component full_adder port(a,b,cin : in STD_LOGIC; sum, cout : out STD_LOGIC);
end component full_adder;

begin
    -- This adder performs the least significant bit operation
    component_0 : full_adder port map (x0, y0, '0', z0, tmpcarry);
    -- This adder performs the most significant bit operation
    component_2 : full_adder port map (x1, y1, tmpcarry, z1, cout);

end adder;
\end{lstlisting}

\section{Part 3 Constraints File}

\begin{figure}[h]
	\includegraphics[width=\textwidth]{report_images/img7}
\end{figure}

\end{appendices}

\end{document}


%%
%% Automatically generated file from DocOnce source
%% (https://github.com/hplgit/doconce/)
%%
%%

%-------------------- begin preamble ----------------------

\documentclass[%
oneside,                 % oneside: electronic viewing, twoside: printing
final,                   % draft: marks overfull hboxes, figures with paths
10pt]{article}

\listfiles               %  print all files needed to compile this document

\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
\usepackage[table]{xcolor}
\usepackage{bm,ltablex,microtype}

\usepackage[pdftex]{graphicx}

\usepackage{fancyvrb} % packages needed for verbatim environments

\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

\usepackage{lmodern}         % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF:
\definecolor{linkcolor}{rgb}{0,0,0.4}
\usepackage{hyperref}
\hypersetup{
    breaklinks=true,
    colorlinks=true,
    linkcolor=linkcolor,
    urlcolor=linkcolor,
    citecolor=black,
    filecolor=black,
    %filecolor=blue,
    pdfmenubar=true,
    pdftoolbar=true,
    bookmarksdepth=3   % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
    }
%\hyperbaseurl{}   % hyperlinks are relative to this root

\setcounter{tocdepth}{2}  % levels in table of contents

% prevent orhpans and widows
\clubpenalty = 10000
\widowpenalty = 10000

% --- end of standard preamble for documents ---

% insert custom LaTeX commands...

\raggedbottom
\makeindex
\usepackage[totoc]{idxlayout}   % for index in the toc
\usepackage[nottoc]{tocbibind}  % for references/bibliography in the toc

%-------------------- end preamble ----------------------

\begin{document}

% matching end for #ifdef PREAMBLE

\newcommand{\exercisesection}[1]{\subsection*{#1}}

% ------------------- main content ----------------------

% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center}
{\LARGE\bf
\begin{spacing}{1.25}
PHY321: Classical Mechanics 1
\end{spacing}
}
\end{center}

% ----------------- author(s) -------------------------

\begin{center}
{\bf Homework 9, due Monday  April 5${}^{}$} \\ [0mm]
\end{center}

\begin{center}
% List of all institutions:
\end{center}

% ----------------- end author(s) -------------------------

% --- begin date ---
\begin{center}
Mar 31, 2021
\end{center}
% --- end date ---

\vspace{1cm}

\paragraph{Practicalities about  homeworks and projects.}
\begin{enumerate}
\item You can work in groups (optimal groups are often 2-3 people) or by yourself. If you work as a group you can hand in one answer only if you wish. \textbf{Remember to write your name(s)}!

\item Homeworks are available  the week before the deadline.

\item How do I(we)  hand in?  Due to the corona virus and many of you not being on campus, we recommend that you scan your handwritten notes and upload them to D2L. If you are ok with typing mathematical formulae using say Latex, you can hand in everything as a single jupyter notebook at D2L. The numerical exercise(s) should always be handed in as a jupyter notebook by the deadline at D2L.
\end{enumerate}

\noindent
\paragraph{Introduction to homework 9.}
This week's exercises focus on solving
two-body  problems with central forces. It is based on what you did in hw7 and hw8, see also their respective solutions.

\paragraph{Exercise 1: Attractive Potential (10pt).}
Consider a particle in an attractive potential
\[
U(r)=-\alpha/r.
\]

The quantity $r$ is the absolute value of the relative position. We
will use the reduced mass $\mu$ and the angular momentum $L$, as
discussed during the lectures. With the transformation of a two-body
problem to the center-of-mass frame, the actual equations look like an
\emph{effective} one-body problem. The energy of the system is $E$ and the
minimum of the effective potential is $r_{\rm min}$.

The analytical solution to the radial equation of motion is
\[
r(\phi) = \frac{1}{\frac{\mu\alpha}{L^2}+A\cos{(\phi)}}.
\]

Find the value of $A$. Hint: Use the fact that at $r_{\rm min}$
there is no radial kinetic energy and $E=-\alpha/r_{\rm min}+L^2/2mr_{\rm min}^2$.

\paragraph{Exercise 2 (20pt) Inverse-square force.}
Consider again the same effective potential as in exercise 1. This leads to an attractive inverse-square-law force, $F=-\alpha/r^2$. Consider a particle of mass $m$ with angular momentum $L$. Taylor sections 8.4-8.7 are relevant background material.  See also the harmonic oscillator potential from hw8. The equation of motion for the radial degrees of freedom is (see also hw8) in the center-of-mass frame in two dimensions with $x=r\cos{(\phi)}$ and $y=r\sin{(\phi)}$ and
$r\in [0,\infty)$, $\phi\in [0,2\pi]$ and $r=\sqrt{x^2+y^2}$ are given by
\[
\ddot{r}=-\frac{1}{m}\frac{dV(r)}{dr}+r\dot{\phi}^2,
\]
and
\[
\dot{\phi}=\frac{L}{m r^2}.
\]
Here $V(r)$ is any central force which depends only on the relative coordinate.

\begin{itemize}
\item 2a (5pt)  Find the radius of a circular orbit by solving for the position of the minimum of the effective potential.

\item 2b (5pt) At the minimum, the radial velocity is zero and it is only the \href{{https://en.wikipedia.org/wiki/Centripetal_force}}{centripetal velocity} which is nonzero. This implies that $\ddot{r}=0$.  What is the angular frequency, $\dot{\theta}$, of the orbit? Solve this by setting $\ddot{r}=0=F/m+\dot{\theta}^2r$.

\item 2c (5pt) Find the effective spring constant for the particle at the minimum.

\item 2d (5pt) What is the angular frequency for small vibrations about the minimum? How does this compare with the answer to 2b?
\end{itemize}

\noindent
\paragraph{Exercise 3, Inverse-square force again (10pt).}
Consider again a  particle of mass $m$ in the same attractive potential, $U(r)=-\alpha/r$, with angular momentum $L$ with just the right energy so that

\[
A=m\alpha/L^2
\]
where $A$ comes from the expression
\[
r=\frac{1}{(m\alpha/L^2)+A\cos{(\phi)}}.
\]
The trajectory can then be rewritten as
\[
r=\frac{2r_0}{1+\cos\theta},~~~r_0=\frac{L^2}{2m\alpha}.
\]

\begin{itemize}
\item 3a (5pt) Show that for this case the total energy $E$ approaches zero.

\item 3b (5pt) With zero energy $E=0$, write this trajectory in a more recognizable parabolic form, that is express $x_0$ and $R$ in terms of $r_0$ using
\end{itemize}

\noindent
\[
x=x_0-\frac{y^2}{R}.
\]

\paragraph{Exercise 4, parabolic and hyperbolic orbits (10pt).}
The solution to the radial function for an inverse-square-law force, see for example Taylor equation (8.59) or the equation above, is
\[
r(\phi) = \frac{c}{1+\epsilon\cos{(\phi)}}.
\]

For $\epsilon=1$ (or the energy $E=0$) the orbit reduces to a parabola as we saw in the previous exercise,
while for $\epsilon > 1$ (or energy positive) the orbit becomes a hyperbola. The equation for a hyperbola in Cartesian coordinates is
\[
\frac{(x-\delta)^2}{\alpha^2}-\frac{y^2}{\beta^2}=1.
\]
For a hyperbola, identify the constants $\alpha$, $\beta$ and $\delta$ in terms of the constants $c$ and $\epsilon$ for $r(\phi)$.

\paragraph{Exercise 5, Testing orbit types (50 pt).}
In this exercise we can use the program for $r(\phi)$ we developed in hw8. We will use an inverse-square-law force as in exercises 1, 2, 3 and 4. The aim is to see that the orbits we get for $E<0$ become ellipses (or circles), parabola for $E=0$ and hyperbola for $E>0$.  An example code is shown here.

Here we have defined the constants $L=m=\alpha=1$. Feel free to set new values. \textbf{You need also to set the initial conditions} in order to study the different types of orbits. It may be useful to plot the potential here and find the values for the initial conditions that fit $E<0$, $E=0$ and $E>0$.

\begin{verbatim}
# Common imports
import numpy as np
import pandas as pd
from math import *
import matplotlib.pyplot as plt
# Simple Gravitational Force   -alpha/r

DeltaT = 0.01
#set up arrays
tfinal = 100.0
n = ceil(tfinal/DeltaT)
# set up arrays for t, v and r
t = np.zeros(n)
v = np.zeros(n)
r = np.zeros(n)
# Constants of the model, setting all variables to one for simplicity
alpha = 1.0
AngMom = 1.0  #  The angular momentum
m = 1.0  # scale mass to one
c1 = AngMom*AngMom/(m*m)
c2 = AngMom*AngMom/m
# You need to specify the initial conditions
r0 = 0.0
v0 = 0.0
r[0] = r0
v[0] = v0
# Start integrating using the Velocity-Verlet  method
for i in range(n-1):
    # Set up acceleration
    a = -alpha/(r[i]**2)+c1/(r[i]**3)
    # update velocity, time and position using the Velocity-Verlet method
    r[i+1] = r[i] + DeltaT*v[i]+0.5*(DeltaT**2)*a
    anew = -alpha/(r[i+1]**2)+c1/(r[i+1]**3)
    v[i+1] = v[i] + 0.5*DeltaT*(a+anew)
    t[i+1] = t[i] + DeltaT
    # Plot position as function of time
fig, ax = plt.subplots(2,1)
ax[0].set_xlabel('time')
ax[0].set_ylabel('radius')
ax[0].plot(t,r)
ax[1].set_xlabel('time')
ax[1].set_ylabel('Velocity')
ax[1].plot(t,v)

plt.show()

\end{verbatim}

Run your code and study and discuss the situations where you have
elliptical, parabolic and hyperbolic orbits. Discuss the physics of
these cases. The results from exercises 1, 2, 3 and 4 may be useful
here.

\paragraph{Additional Bonus Exercise (10pt).}
You don't need to do this exercise, but it gives you a bonus score of 10 points.

This time the additional bonus exercise is a simple survey. We are now moving
into our last month  and we would very much have your feedback on how
things are functioning so that we can improve and correct.

\begin{itemize}
\item Is the weekly load with paper and pencil exercises and the numerical exercises reasonable?

\item Is there enough material (lectures and lecture material) to get you started with the exercises?  We are thinking of both the paper and pencil and the numerical exercises?

\item Is the pace during the lectures reasonable? And do the lectures link well with the exercises?

\item In the beginning there will always be some elements of repetition of material many of you have seen before. Do you find the choice of material the first 4 weeks adequate? Too easy? Too difficult?

\item For those of you who have taken CMSE 201 Introduction to Computational Modeling, do you feel the material taught there links well with the exercises you have done in this course? Is there is something we are missing?

\item Any other topic you would like to comment on?
\end{itemize}

\noindent
\paragraph{Classical Mechanics Extra Credit Assignment: Scientific Writing and attending Talks.}
The following gives you an opportunity to earn \textbf{five extra credit
points} on each of the remaining homeworks and \textbf{ten extra credit points}
on the midterms and finals.  This assignment also covers an aspect of
the scientific process that is not taught in most undergraduate
programs: scientific writing.  Writing scientific reports is how
scientist communicate their results to the rest of the field.  Knowing
how to assemble a well written scientific report will greatly benefit
you in you upper level classes, in graduate school, and in the work
place.

The full information on extra credits is found at \href{{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/}}{\nolinkurl{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/}}. There you will also find examples on how to write a scientific article.
Below you can also find a description on how to gain extra credits by attending scientific talks.

This assignment allows you to gain extra credit points by practicing
your scientific writing.  For each of the remaining homeworks you can
submit the specified section of a scientific report (written about the
numerical aspect of the homework) for five extra credit points on the
assignment.  For the two midterms and the final, submitting a full
scientific report covering the numerical analysis problem will be
worth ten extra points.  For credit the grader must be able to tell
that you put effort into the assignment (i.e.~well written, well
formatted, etc.).  If you are unfamiliar with writing scientific
reports, \href{{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/IntroductionScientificWriting.md}}{see the information here}

The following table explains what aspect of a scientific report is due
with which homework.  You can submit the assignment in any format you
like, in the same document as your homework, or in a different one.
Remember to cite any external references you use and include a
reference list.  There are no length requirements, but make sure what
you turn in is complete and through.  If you have any questions,
please contact Julie Butler at butler@frib.msu.edu.

\begin{quote}
\begin{tabular}{ccc}
\hline
\multicolumn{1}{c}{ HW/Project } & \multicolumn{1}{c}{ Due Date } & \multicolumn{1}{c}{ Extra Credit Assignment } \\
\hline
HW 3               & 2-8           & Abstract                   \\
HW 4               & 2-15          & Introduction               \\
HW 5               & 2-22          & Methods                    \\
HW 6               & 3-1           & Results and Discussion     \\
\textbf{Midterm 1} & \textbf{3-12} & \emph{Full Written Report} \\
HW 7               & 3-22          & Abstract                   \\
HW 8               & 3-29          & Introduction               \\
HW 9               & 4-5           & Results and Discussion     \\
\textbf{Midterm 2} & \textbf{4-16} & \emph{Full Written Report} \\
HW 10              & 4-26          & Abstract                   \\
\textbf{Final}     & \textbf{4-30} & \emph{Full Written Report} \\
\hline
\end{tabular}
\end{quote}

\noindent

You can also gain extra credits if you attend scientific talks.
This is described here.

\paragraph{Integrating Classwork With Research.}
This opportunity will allow you to earn up to 5 extra credit points on a Homework per week. These points can push you above 100\% or help make up for missed exercises.
In order to earn all points you must:

\begin{enumerate}
\item Attend an MSU research talk (recommended research oriented Clubs is  provided below)

\item Summarize the talk using at least 150 words

\item Turn in the summary along with your Homework.
\end{enumerate}

\noindent
Approved talks:
Talks given by researchers through the following clubs:
\begin{itemize}
\item Research and Idea Sharing Enterprise (RAISE): Meets Wednesday Nights Society for Physics Students (SPS): Meets Monday Nights

\item Astronomy Club: Meets Monday Nights

\item Facility For Rare Isotope Beam (FRIB) Seminars: Occur multiple times a week
\end{itemize}

\noindent
If you have any questions please consult Jeremy Rebenstock, rebensto@msu.edu.

All the material on extra credits is at \href{{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/}}{\nolinkurl{https://github.com/mhjensen/Physics321/blob/master/doc/Homeworks/ExtraCredits/}}.

% ------------------- end of main content ---------------

\end{document}


% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}

\usepackage{longtable,booktabs}
\usepackage[french,english]{babel}
\usepackage{natbib}
\usepackage{numprint}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{fancyhdr}
\usepackage{multicol}\usepackage{amsmath,amssymb,amsfonts,textcomp}
\usepackage{color}
\usepackage{calc}
\usepackage[normalem]{ulem}
 \setlength{\tabcolsep}{8pt}
\usepackage{setspace}
\onehalfspacing
\usepackage{longtable}
\usepackage{graphicx}
\usepackage[margin=1in]{geometry}
\setlength{\parindent}{0pt}
\usepackage[bottom]{footmisc}
\pagestyle{fancy}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage{cancel}
\usepackage{hyperref}

\title{EC200: Problem Set 3}
\author{}
\date{2020-09-25}

\begin{document}
\maketitle

\hypertarget{exercises}{%
\subsection*{Exercises}\label{exercises}}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  The following table shows, for eight vintages of delicious wine,
  purchases per buyer (\(y\)) and the wine buyer's rating (\(x\)) in a
  given year:

  \begin{longtable}[]{@{}lcccccccc@{}}
  \toprule
  \(x\) & 3.6 & 3.3 & 2.8 & 2.6 & 2.7 & 2.9 & 2.0 & 2.6\tabularnewline
  \midrule
  \endhead
  \(y\) & 24 & 21 & 22 & 22 & 18 & 13 & 9 & 6\tabularnewline
  \bottomrule
  \end{longtable}

  \begin{enumerate}
  \def\labelenumii{\alph{enumii}.}
  \item
    Estimate \emph{by hand} the regression of purchases per buyer on the
    buyer's rating.\\
  \item
    Interpret the slope of the estimated regression line.\\
  \item
    Interpret the intercept of the estimated regression line .\\
  \end{enumerate}
\item
  (SW4.2) Suppose that a random sample of 200 20-year-old men is
  selected from a population and that these men's height and weight are
  recorded. A regression of weight (measured in pounds) on height
  (measured in inches) yields

  \[\widehat{Weight}=-99.41 + 3.94 Height\]

  \(R^2 = 0.81\); \(SER = 10.2\)

  \begin{enumerate}
  \def\labelenumii{\alph{enumii}.}
  \item
    What is the predicted weight for someone who is 70 inches tall? 65
    inches tall?
  \item
    One 20-year-old man has a late growth spurt and grows 1.5 inches
    over the course of the year. What is the regression's prediction for
    the increase in his weight?
  \item
    Suppose that you want to translate the results of this equation into
    centimeters and kilograms. What are the regression estimates from
    this new regression? Give all results, including estimated
    coefficients, \(R^2\), and \(SER\).
  \item
    Interpret the \(R^2\) value. Does it indicate anything about whether
    these estimates are likely to be biased? Explain.
  \end{enumerate}
  \clearpage
\item
  Consider the savings function:

\[sav =  \beta_0 + \beta_1 inc + u, u = e\sqrt{inc}\]

where \(e\) is a random variable with \(E(e) = 0\) and
\(Var(e) = \sigma^2_e\). Assume that \(e\) is independent of \(inc\).

\begin{enumerate}
\def\labelenumi{\alph{enumi}.}

\item
  Show that \(E(u|inc)=0\), so that the key zero conditional mean
  assumptionis satisfied. {[}Hint: If \(e\) is independent of \(inc\),
  then \(E(e|inc) = E(e)\){]}
\item
  Show that \(Var(u|inc) = \sigma^2_einc\), so that the homoskedasticity
  assumption is violated. In particular, the variance of \(sav\)
  increases with \(inc\). {[}Hint: \(Var(e|inc) = Var(e)\) if \(inc\)
  and \(e\) are independent!{]}
\item
  Why might it be reasonable to assume that the variance of savings
  increases with family income?
\end{enumerate}

\item
  The data file \href{../collegedistance.dta}{CollegeDistance} contains
  data from a random sample of high school seniors interviewed in 1980
  and re-interviewed in 1986\footnote{These data were provided by
    Professor Cecilia Rouse of Princeton University and were used in her
    paper ``Democratization or Diversion? The Effect of Community
    Colleges on Educational Attainment,'' Journal of Business and
    Economic Statistics, April 1995, 12(2): 217--224.} Use these data to
  investigate the relationship between the number of completed years of
  education for young adults and the distance from each student's high
  school to the nearest four-year college. (Proximity to college lowers
  the cost of education, so that students who live closer to a four-year
  college should, on average, complete more years of higher education.)

\begin{enumerate}
\def\labelenumi{\alph{enumi}.}
\item
  Run a regression of years of completed education (\(ED\)) on distance
  to the nearest college (\(Dist\)), where \(Dist\) is measured in tens
  of miles. (For example, \(Dist=2\) means that the distance is 20
  miles.)\footnote{Though we haven't covered regressions in our stata
    labs, I talk thorugh interpreting regression output in the
    \href{https://youtu.be/DZo5m5q3bmA}{Chapter 5 Video}. You can
    regress a dependent variable \texttt{y} on an independent variable
    \texttt{x} with the command \texttt{regress\ y\ x}}. Write the
  equation you estimated in the form
  \(\widehat{ED} = \beta_0 + \beta_1 Dist\)
\item
  How does the average value of years of completed schooling change when
  colleges are built close to where students go to high school?
\item
  Bob's high school was 20 miles from the nearest college. Predict Bob's
  years of completed education using the estimated regression. How would
  the prediction change if Bob lived 10 miles from the nearest college?
\item
  Does distance to college explain a large fraction of the variance in
  educational attainment across individuals? Explain.
\item
  Provide an example of a factor that might cause this model to violate
  the zero conditional mean assumption. Explain your reasoning.
\item
  What is the value of the standard error of the regression?\footnote{There
    are a few ways to find it in Stata's output. The easiest is to note
    that ``root MSE'' is the square root of the SER} What are the units
  for the standard error (meters, grams, years, dollars, cents, or
  something else)?
\item
  Is the estimated regression slope coefficient statistically
  significant at the 5\% level? What is the p-value associated with
  coefficient's t-statistic?
\item
  Construct a 95\% confidence interval for the slope coefficient.
\item
  Estimate a regression that restricts the sample to men, and calculate
  a 95\% confidence interval for the slope. Do the same, restricting the
  sample to women. Does it look like the effect of distance on completed
  years of education is different?\footnote{Note that we cannot make
    claims about whether they are statistically different because the
    estimates come from two different samples! A hypothesis test here
    would be awesome, but we need to build a few more skills to do this.}
\end{enumerate}
\end{enumerate}
\end{document}


\documentclass[10pt]{beamer}

\mode<presentation>
{
 \usetheme{Boadilla}
\pagestyle{empty}

\setbeamerfont*{frametitle}{size=\normalsize,series=\bfseries}
\setbeamerfont*{block}{size=\normalsize,series=\bfseries}
%\setbeamertemplate{blocks}[rounded][shadow=true]
}

\definecolor{links}{HTML}{2A1B81}
\hypersetup{colorlinks,linkcolor=,urlcolor=links}

\usepackage[pdf]{pstricks}
\usepackage{pst-sigsys}

\definecolor{darkblue}{rgb}{0.0, 0.0, 0.40}
\setbeamercolor{title}{fg=darkblue}
\setbeamercolor{frametitle}{fg=darkblue}
\definecolor{darkgreen}{rgb}{0.0, 0.4, 0.0}

\usepackage{bbm}

\def\nn{\nonumber}
\def\xt{x(t)}
\def\xn{x[n]}
\def\xeven{x_{\text{even}}}
\def\xodd{x_{\text{odd}}}

\newcommand{\fs}[2]{#2}

\title[]{Periodicity, Energy and Power}
\author[\textcolor{blue}{Systems and Circuits}]{\textcolor{darkblue}{Pablo M. Olmos} (olmos@tsc.uc3m.es)\\ \textcolor{darkblue}{Emilio Parrado} (emipar@tsc.uc3m.es)}
\institute{\textcolor{white}{UC3M}}

\AtBeginSection[]
{
  \begin{frame}<beamer>{Index}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}

%%%%%%%%%%%%%%%%
\begin{document}

\frame{
\titlepage
\thispagestyle{empty}
\begin{center}
\includegraphics[scale=0.05]{Figures/uc3m-logo2.pdf}
\end{center}
}

\section{Properties of signals}

\subsection{Symmetry}

\frame{
\frametitle{Even and odd signals}

\begin{exampleblock}{Even signal}
$\xt$ presents even symmetry (shortly, it is an even signal) if:
\begin{align}\nn
\xt=x(-t) \qquad \forall t
\end{align}
The same definition holds for sequences: $\xn$ is even if $\xn=x[-n]$ $\forall n$.
\end{exampleblock}

By definition, an even signal is symmetric with respect to the coordinate axis.

}

\frame{

\begin{figure}
\includegraphics[scale=0.6]{Figures/Signal29.pdf}
\end{figure}

}

\frame{

\begin{exampleblock}{Odd signal}
$\xt$ presents odd symmetry (shortly, it is an odd signal) if:
\begin{align}\nn
\xt=-x(-t) \qquad \forall t
\end{align}
The same definition holds for sequences: $\xn$ is odd if $\xn=-x[-n]$ $\forall n$.
\end{exampleblock}

\begin{alertblock}{}
Necessarily, if $\xt$ ($\xn$) is odd, then $x(0)=0$ ($x[0]=0$)!!!
\end{alertblock}

}

\frame{

\begin{figure}
\includegraphics[scale=0.6]{Figures/Signal_32.pdf}
\end{figure}

}

\frame{
\frametitle{Even and Odd parts of a signal}
\begin{block}{}
Any signal $x(t)$ can be decomposed as the sum of an even signal $\xeven(t)$ plus an odd signal $\xodd(t)$:
\begin{align}\nn
x(t)=\xeven(t)+\xodd(t)\\\nn
x[n]=\xeven[n]+\xodd[n]
\end{align}
\end{block}

\begin{alertblock}{}
$\xeven$ and $\xodd$ are simply computed as follows:
\begin{align}\nn
&\xeven(t)=\frac{x(t)+x(-t)}{2}\qquad \xeven[n]=\frac{x[n]+x[-n]}{2}\\\nn
&\xodd(t)=\frac{x(t)-x(-t)}{2}\qquad \;\;\xodd[n]=\frac{x[n]-x[-n]}{2}
\end{align}
\end{alertblock}

}

\frame{

\begin{figure}
\includegraphics[scale=0.5]{Figures/Signal_36.pdf}
\end{figure}

}

\subsection{Periodicity}

\frame{
\frametitle{Periodic continuous signals}

\begin{block}{}
$x(t)$ is periodic if there exists a real number $T$ such that $x(t)=x(t+T)$ for any $t$.
\end{block}

\begin{exampleblock}{$\cos(\frac{2}{3}\pi t)$}
\begin{align}\nn
&\cos(\frac{2}{3}\pi (t+T))=\cos(\frac{2}{3}\pi t) \Leftrightarrow \frac{2}{3}\pi T=2\pi k\quad k\in\mathbb{Z}\\\nn
&\Rightarrow T=3k\qquad k=1,2,3,\ldots
\end{align}
\textbf{$T=3$ is the \color{red}{fundamental period.}}
\end{exampleblock}

}

\frame{
Given $x(t)=\cos(2\pi t)+\sin (\frac{\pi}{3}t)$:
\begin{itemize}
\item Is $x(t)$ periodic?
\item What is the fundamental period?
\end{itemize}

%\textbf{Sol.:}
%
%\begin{enumerate}
%\item $\cos(2\pi t)$ is periodic with period $T_1=k$ for $k=1,2,\ldots$
%\item $\sin (\frac{\pi}{3}t)$ is periodic with period $T_2=6k$ for $k=1,2,\ldots$
%\item Least common multiple: $6k$.
%\item Thus $x(t)$ is periodic with period $T=6k$ and fundamental period $T=6$.
%\end{enumerate}

}

\frame{
\frametitle{Example}
Given $x(t)=\cos(2\pi t)+\sin (\frac{\pi}{3}t)$:
\begin{itemize}
\item Is $x(t)$ periodic?
\item What is the fundamental period?
\end{itemize}

\textbf{Sol.:}

\begin{enumerate}
\item $\cos(2\pi t)$ is periodic with period $T_1=k$ for $k=1,2,\ldots$
\item $\sin (\frac{\pi}{3}t)$ is periodic with period $T_2=6k$ for $k=1,2,\ldots$
\item Least common multiple: $6k$.
\item Thus $x(t)$ is periodic with period $T=6k$ and fundamental period $T=6$.
\end{enumerate}

}

\frame{

$x(t)=\cos(2\pi t)+\sin (\frac{\pi}{3}t)$
\begin{figure}
\includegraphics[scale=0.3]{Figures/Signal35.pdf}
\end{figure}

}

\frame{
\frametitle{Periodic sequences}

\begin{block}{}
$x[n]$ is periodic if there exists an integer number $N$ such that $x[n]=x[n+N]$ for any $n$.
\end{block}

\begin{exampleblock}{$\cos(\frac{1}{7}\pi n)$}
\begin{align}\nn
&\cos(\frac{1}{7}\pi (n+N))=\cos(\frac{1}{7}\pi n) \Leftrightarrow \frac{1}{7}\pi N=2\pi k\quad k\in\mathbb{Z}\\\nn
&\Rightarrow N=14k\qquad k=1,2,3,\ldots
\end{align}
\textbf{$N=14$ is the \color{red}{fundamental period.}}
\end{exampleblock}

}

\frame{

\begin{alertblock}{$\cos(\frac{1}{7} n)$}
\begin{align}\nn
&\cos(\frac{1}{7} (n+N))=\cos(\frac{1}{7} n) \Leftrightarrow \frac{1}{7} N=2\pi k\quad k\in\mathbb{Z}\\\nn
&\color{red}{\Rightarrow N=14\pi k\qquad k=1,2,3,\ldots \text{ Never an integer!!}}
\end{align}
\textbf{$\cos(\frac{1}{7} n)$ is not periodic!! Though it may look as periodic...}
\end{alertblock}

\begin{figure}
\includegraphics[scale=0.5]{Figures/Signal41.pdf}
\end{figure}

}

\subsection{Average value}

\frame{
\frametitle{Signal average value}

\begin{block}{Average value over a given interval (partial average)}
\begin{align}\nn
<x(t)>_{t_a,t_a+L}=\frac{1}{L}\int_{t_a}^{t_a+L}x(t) dt\\\nn
<x[n]>_{n_a,n_a+I}=\frac{1}{I+1}\sum_{n_a}^{n_a+I}x[n]
\end{align}
\end{block}

%\begin{alertblock}{}
%$T_0$ and $N_0$ are just the interval lengths!
%\end{alertblock}

}

\frame{
\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_21.pdf}
\end{figure}
\begin{align}\nn
<x(t)>_{0,\frac{1}{2}}=\frac{1}{1/2}\int_0^{1/2}\sin(2\pi t) dt=-\frac{1}{\pi}[\cos(2\pi t)]_0^{1/2}=\frac{2}{\pi}
\end{align}

}

\frame{
\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_22.pdf}
\end{figure}
\begin{align}\nn
&<x[n]>_{-3,3}=\frac{3}{7}\\\nn
&<x[n]>_{-9,9}=\frac{4.5}{19}
\end{align}

}

\frame{

\begin{block}{Average value}
\begin{align}\nn
<x(t)>=\lim_{L\rightarrow\infty} \frac{1}{2L}\int_{-L}^{L}x(t) dt\\\nn
<x[n]>=\lim_{I\rightarrow\infty} \frac{1}{2I+1}\sum_{-I}^{I}x[n]
\end{align}
\end{block}

%\begin{exampleblock}{}
%If the signal $x(t)$ is defined only for $t\in[a,b]$, by average value we mean the partial average value computed across $[a,b]$.
%\end{exampleblock}

}

\frame{
\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_26.pdf}
\end{figure}

\begin{align*}
<x(t)>&=?\\
<x(t)>&_{0,2}=?
\end{align*}
}

\frame{
\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_26.pdf}
\end{figure}

\begin{align*}
<x(t)>&=\lim_{L\rightarrow\infty} \frac{1}{2L}\int_{-L}^{L}x(t) dt=\lim_{L\rightarrow\infty} \frac{1}{2L}\int_{0}^{2}y(t)dt\\&=\lim_{L\rightarrow\infty} \frac{1}{2L} \left[\int_{0}^{1}tdt+\int_{1}^{2}1dt \right]=\lim_{L\rightarrow\infty}\frac{1}{2L}\left(\frac{1}{2}+1\right)=0\\
\color{red}{}<x(t)>&_{\color{red}{}0,2}\color{red}{}=3/4
\end{align*}
}

\frame{
\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_26.pdf}
\end{figure}

\begin{align*}
<x(t)>&=\lim_{L\rightarrow\infty} \frac{1}{2L}\int_{-L}^{L}x(t) dt=\lim_{L\rightarrow\infty} \frac{1}{2L}\int_{0}^{2}y(t)dt\\&=\lim_{L\rightarrow\infty} \frac{1}{2L} \left[\int_{0}^{1}tdt+\int_{1}^{2}1dt \right]=\lim_{L\rightarrow\infty}\frac{1}{2L}\left(\frac{1}{2}+1\right)=0\\
\color{red}{}<x(t)>&_{\color{red}{}0,2}\color{red}{}=3/4
\end{align*}
}

\frame{
\begin{alertblock}{Average value: Periodic signals}
If $x(t)$ is periodic with fundamental period $T$, then for any $t_0\in\mathbb{R}$
\begin{align}\nn
<x(t)>= \frac{1}{T}\int_{t_0-\frac{T}{2}}^{t_0+\frac{T}{2}}x(t) dt
\end{align}
\end{alertblock}
\begin{alertblock}{Average value: Periodic signals}
If $x[n]$ is periodic with fundamental period $N$, then for any $n_0\in\mathbb{Z}$
\begin{align}\nn
<x[n]>=\frac{1}{N}\sum_{n_0}^{n_0+N-1}x[n]
\end{align}
\end{alertblock}
}

\frame{
\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_24.pdf}
\end{figure}
\begin{align}\nn
<x(t)>=\int_0^{1}\sin(2\pi t) dt=-\frac{1}{2\pi}[\cos(2\pi t)]_0^{1}=0
\end{align}

}

\subsection{Power and Energy}

\frame{
\frametitle{Signal Power}

Assume $x(t)$ is a voltage signal in an electric circuit.
\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_25.pdf}
\end{figure}

\begin{exampleblock}{}
$p_x(t)=|x(t)|^{2}$ is defined as the power signal associated to $x(t)$ (\textbf{It is a signal}!!).
\end{exampleblock}

\begin{exampleblock}{}
The same definition holds for sequences. $p_x[n]=|x[n]|^2$ is the power signal associated to $x[n]$.
\end{exampleblock}

}

\frame{
\frametitle{Average signal power}

\begin{block}{Average signal power in a given interval}
\begin{align}\nn
<p_x(t)>_{t_a,t_a+L}=\frac{1}{L}\int_{t_a}^{t_a+L}|x(t)|^{2} dt\quad \text{W}\\\nn
<p_x[n]>_{n_a,I}=\frac{1}{I+1}\sum_{n_a}^{n_a+I}|x[n]|^{2}  \quad \text{W}
\end{align}
\end{block}

\begin{block}{Average power}
\begin{align}\nn
P_x=\lim_{L\rightarrow\infty} \frac{1}{2L}\int_{-L}^{L}|x(t)|^{2} dt \quad \text{W}\\\nn
P_x=\lim_{I\rightarrow\infty} \frac{1}{2I+1}\sum_{-I}^{I}|x[n]|^{2} \quad \text{W}
\end{align}
\end{block}

}

\frame{

\frametitle{Average power: periodic signals}

If $x(t)$ (or $x[n]$) is periodic with fundamental period $T$, then $p_x(t)$ ($p_x[n]$) is also periodic and $T$ is a valid period. Thus,

\begin{alertblock}{Average Power: Periodic signals}
If $x(t)$ is periodic with fundamental period $T$, then for any $t_0\in\mathbb{R}$
\begin{align}\nn
P_x= \frac{1}{T}\int_{t_0-\frac{T}{2}}^{t_0+\frac{T}{2}}|x(t)|^{2} dt \quad \text{W}
\end{align}
\end{alertblock}

\begin{alertblock}{Average value: Periodic signals}
If $x[n]$ is periodic with fundamental period $N$, then for any $n_0\in\mathbb{Z}$
\begin{align}\nn
P_x=\frac{1}{N}\sum_{no}^{n_0+N-1}|x[n]|^{2} \quad \text{W}
\end{align}
\end{alertblock}

}

\frame{
\begin{figure}
\includegraphics[scale=0.5]{Figures/Signal55.pdf}
\end{figure}

\begin{exampleblock}{}
$\sin(2\pi t)$ has fundamental period $T=1$ s. $\sin^{2}(2\pi t)$ has fundamental period $T=0.5$ s but $T=1$ is a valid period.
\end{exampleblock}
}

\frame{
\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_24.pdf}
\end{figure}
\begin{align}\nn
P_x=\int_0^{1}\sin^2(2\pi t) dt=\frac{1}{2}\int_0^{1} (1-\cos(4\pi t)) dt=\frac{1}{2} \quad \text{W}
\end{align}

\url{http://www.mathwords.com/t/trig_identities.htm}

%\begin{alertblock}{Trigonometric identities}
%You have to remember them! $\sin(a)\cos(b)$, $\sin(a+b)$, $\cos(a+b)$, $\sin^2(a)$, $\sin^2(b)$, etc...
%\end{alertblock}
}

\frame{
\frametitle{Signal energy}

Given $x(t)$, its energy measured over an interval $[t_a,t_b]$ is the integral of the power signal $p_x(t)$:

\begin{align}\nn
E_x(t_a,t_b)=\int_{t_a}^{t_b}|x(t)|^{2}dt \quad \text{J (joules)}
\end{align}

For sequences,

\begin{align}\nn
E_x[n_a,n_b]=\sum_{n_a}^{n_b}|x[n]|^{2} \quad \text{J}
\end{align}

The total energy of a signal is defined as

\begin{align}\nn
E_x=\int_{-\infty}^{\infty}|x(t)|^{2}dt\qquad E_x=\sum_{-\infty}^{\infty}|x[n]|^{2} \quad \text{J}
\end{align}

}

\frame{

\begin{figure}
\includegraphics[scale=0.7]{Figures/Signal_26.pdf}
\end{figure}

\begin{align}\nn
E_y=\int_{0}^{1} t^2 dt+\int_{1}^{2} 1 dt =\frac{1}{3} [t^3]_{0}^{1}+1=\frac{4}{3} \quad \text{J}
\end{align}

}

\frame{
\frametitle{Energy signals and Power signals}
Given $x(t)$,

\begin{itemize}
\item If $E_x< \infty$, then $x(t)$ is an energy signal (or a signal defined in terms of energy)
\item If $E_x\rightarrow \infty$, then $x(t)$ is NOT an energy signal. Besides, if $P_x< \infty$, then $x(t)$ is a power signal (or a signal defined in terms of power).
\item If $P_x\rightarrow \infty$, then is neither an energy signal nor a power signal.
\end{itemize}

}
%
%
%\section{Unit step and impulse}
%
%
%\frame{
%\begin{exampleblock}{In the rest of this class and next Wednesday}
%We describe a set of  basic signal models whose properties are extremely important to analyze and design complex signal processing systems.
%\end{exampleblock}
%
%\begin{figure}
%\includegraphics[scale=0.2]{Figures/Signal70.pdf}
%\end{figure}
%
%}
%
%\subsection{Discrete-time Unit Impulse and Unit Step}
%
%
%\frame{
%\frametitle{Unit Impulse Sequence (Kronecker delta)}
%
%Probably the simplest sequence we can imagine:
%\begin{align}\nn
%\delta[n]=\left\{
%\begin{array}{cc}
%1 & n=0\\
%0 & n\neq 0
%\end{array}
%\right.
%\qquad
%\delta[n-n_0]=\left\{
%\begin{array}{cc}
%1 & n=n_0\\
%0 & n\neq n_0
%\end{array}
%\right.
%\end{align}
%
%
%\begin{figure}
%\includegraphics[scale=0.45]{Figures/Signal62.pdf}
%\end{figure}
%
%}
%
%\frame{
%\frametitle{Unit Impulse Sequence. Properties}
%\begin{block}{}
%It is an even signal: $\delta[n]=\delta[-n]$.
%\end{block}
%\begin{alertblock}{}
% Is $\delta[n-n_0]$ an even signal?
%\end{alertblock}
%\begin{exampleblock}{}
%\begin{align}\nn
%x[n]\delta[n-n_0]=\left\{
%\begin{array}{cc}
%x[n_0] & n=n_0\\
%0 & n\neq n_0
%\end{array}
%\right.
%\end{align}
%\end{exampleblock}
%
%\begin{block}{}
%\begin{align}\nn
%\sum_{n=-\infty}^{\infty}\delta[n]=1
%\end{align}
%\end{block}
%
%\begin{exampleblock}{}
%$\delta[n]$ is a signal of finite energy.
%\end{exampleblock}
%
%}
%
%\frame{
%\frametitle{Unit Impulse Sequence. Properties}
%
%\begin{block}{}
%Any signal can be decomposed as a sum of unit impulse sequences:
%\begin{align}\nn
%x[n]=\sum_{k=-\infty}^{\infty}x[k]\delta[n-k]
%\end{align}
%\end{block}
%
%\begin{figure}
%\includegraphics[scale=0.35]{Figures/Signal64.pdf}
%\end{figure}
%}
%
%\frame{
%\frametitle{Unit Step Sequence}
%
% \begin{align}\nn
%u[n]=\left\{
%\begin{array}{cc}
%1 & n\geq0\\
%0 & n< 0
%\end{array}
%\right.
%\end{align}
%
%\begin{block}{From $\delta[n]$ to $u[n]$}
%As we have seen, we can decompose it as a sum of unit impulse sequences:
%\begin{align}\nn
%u[n]&=\sum_{k=-\infty}^{\infty}u[k]\delta[n-k]=\sum_{0}^{\infty}\delta[n-k]\\\nn
%u[n-n_0]&=\sum_{k=-\infty}^{\infty}u[k-n_0]\delta[n-k]=\sum_{n_0}^{\infty}\delta[n-k]
%\end{align}
%\end{block}
%}
%
%\frame{
%\frametitle{Unit Step Sequence}
%
%\begin{block}{From $u[n]$ to $\delta[n]$}
%
%We can also obtain $\delta[n]$ from $u[n]$:
%
%\begin{align}\nn
%\delta[n]&=u[n]-u[n-1]\\\nn
%\delta[n-n_0]&=u[n-n_0]-u[n-n_0-1]
%\end{align}
%\end{block}
%
%
%}
%
%\subsection{Continuous-time Unit Step and Unit Impulse}
%
%\frame{
%\frametitle{Unit Step signal}
%Similar to the discrete case:
%\begin{align}
%\nn
%u(t)=\left\{
%\begin{array}{cc}
%1 & t\geq0\\
%0 & t< 0
%\end{array}
%\right.
%\end{align}
%
%\begin{block}{Continuous approximation}
%Let
%\begin{align}
%\nn
%u_L(t)=\left\{
%\begin{array}{cc}
%0 & t<0\\
%t/L & 0<t<L\\
%1 & t\geq L
%\end{array}
%\right.
%\end{align}
%then
%\begin{align}\nn
%\lim_{L\rightarrow 0}u_L(t)=u(t)
%\end{align}
%\end{block}
%
%
%}
%
%
%%\frame{
%%\frametitle{Rectangular pulse}
%%
%%\begin{align}
%%\nn
%%\Pi(t)=\left\{
%%\begin{array}{cc}
%%1 & |t|\leq\frac{1}{2}\\
%%0 & \text{otherwise}
%%\end{array}
%%\right.
%%\end{align}
%%
%%In general:
%%\begin{align}
%%\nn
%%\Pi\left(\frac{t-a}{b}\right)=\left\{
%%\begin{array}{cc}
%%1 & |t-a|\leq\frac{b}{2}\\
%%0 & \text{otherwise}
%%\end{array}
%%\right.
%%\end{align}
%%
%%\begin{figure}
%%\includegraphics[scale=0.6]{Figures/Signal65.pdf}
%%\end{figure}
%%
%%}
%%
%%\frame{
%%\frametitle{Rectangular pulse}
%%
%%It can be defined in terms of the unit step signal $u(t)$:
%%\begin{align}\nn
%%\Pi(t)&=u(t+\frac{1}{2})-u(t-\frac{1}{2})\\\nn
%%\Pi(\frac{t-a}{b})&=u(t-(a-\frac{b}{2}))-u(t-(a+\frac{b}{2}))
%%\end{align}
%%
%%
%%}
%
%\frame{
%\frametitle{Continuous-time impulse (Dirac Delta function)}
%
%The continuous-time impulse function $\delta(t)$ is related to the unit step by the equation
%\begin{align*}
%u(t)=\int_{-\infty}^{t}\delta(\tau)d\tau
%\end{align*}
%and this suggests that
%\begin{align}\nn
%\delta(t)=\frac{\partial u(t)}{\partial t}=\left\{
%\begin{array}{cc}
%\infty & t=0\\
%0 & t\neq0
%\end{array}
%\right.
%\end{align}
%
%\begin{figure}
%\includegraphics[scale=0.6]{Figures/Signal66.pdf}
%\end{figure}
%
%}
%
%\frame{
%\frametitle{Continuous-time impulse (Dirac Delta function)}
%
%\begin{block}{Continuous approximation}
%Let
%\begin{align}
%\nn
%\delta_L(t)=\frac{\partial u_L(t)}{\partial t}\left\{
%\begin{array}{cc}
%L^{-1} & 0<t<L\\
%0 & \text{ otherwise }
%\end{array}
%\right.
%\end{align}
%then
%\begin{align}\nn
%\delta(t)=\lim_{L\rightarrow 0}\delta_L(t)
%\end{align}
%\end{block}
%
%\begin{figure}
%\includegraphics[scale=0.5]{Figures/Signal67.pdf}
%\end{figure}
%
%}
%
%\frame{
%For any $L$ value,
%\begin{align}\nn
%&\int_{-\infty}^{\infty}\delta_L(t) dt=L\frac{1}{L}=1 \Rightarrow  \int_{-\infty}^{\infty} \delta(t)=1.
%\end{align}
%
%\begin{exampleblock}{}
%The signal $\delta(t)$ has unit area.
%\end{exampleblock}
%
%\begin{block}{}
%\begin{align}\nn
%\int_{-\infty}^{\infty}\delta(t-t_0)dt=1
%\end{align}
%\end{block}
%
%}
%
%\frame{
%\frametitle{Continuous-time Impulse. Properties.}
%
%\begin{block}{Multiplication by a constant $\rightarrow$ Area multiplication}
%\begin{align}\nn
%\int_{-\infty}^{\infty}k\delta(t)dt=k\int_{-\infty}^{\infty}\delta(t)dt=k
%\end{align}
%\end{block}
%
%\begin{exampleblock}{$x(t)\delta(t-t_0)$}
%\begin{align}\nn
%x(t)\delta(t-t_0)=x(t_0)\delta(t-t_0)
%\end{align}
%\end{exampleblock}
%
%\begin{figure}
%\includegraphics[scale=0.5]{Figures/Signal68.pdf}
%\end{figure}
%
%}
%
%\frame{
%\frametitle{Continuous-time Impulse. Properties (II).}
%
%Any signal $x(t)$ can be decomposed as a linear combination of an infinite number of impulses:
%\begin{align}\nn
%x(t)=\int_{-\infty}^{\infty}x(\tau)\delta(t-\tau) d\tau
%\end{align}
%
%\begin{exampleblock}{Unit step signal}
%\begin{align}\nn
%u(t)=\int_{-\infty}^{\infty}u(\tau)\delta(t-\tau) d\tau=\int_{0}^{\infty}\delta(t-\tau) d\tau
%\end{align}
%\end{exampleblock}
%
%}
%
%%\frame{
%%\frametitle{Relationship with the rectangular pulse}
%%
%%\begin{figure}
%%\includegraphics[scale=0.5]{Figures/Signal69.pdf}
%%\end{figure}
%%
%%}

\end{document}


\documentclass[12pt]{article}

\include{preamble}

\title{Math 390.4 / 650.3 Spring 2018 \\ Midterm Examination Two}
\author{Professor Adam Kapelner}

\date{Monday, April 16, 2018}

\begin{document}
\maketitle

\noindent Full Name \line(1,0){410}

\thispagestyle{empty}

\section*{Code of Academic Integrity}

\footnotesize
Since the college is an academic community, its fundamental purpose is the pursuit of knowledge. Essential to the success of this educational mission is a commitment to the principles of academic integrity. Every member of the college community is responsible for upholding the highest standards of honesty at all times. Students, as members of the community, are also responsible for adhering to the principles and spirit of the following Code of Academic Integrity.

Activities that have the effect or intention of interfering with education, pursuit of knowledge, or fair evaluation of a student's performance are prohibited. Examples of such activities include but are not limited to the following definitions:

\paragraph{Cheating} Using or attempting to use unauthorized assistance, material, or study aids in examinations or other academic work or preventing, or attempting to prevent, another from using authorized assistance, material, or study aids. Example: using an unauthorized cheat sheet in a quiz or exam, altering a graded exam and resubmitting it for a better grade, etc.
\\

\noindent I acknowledge and agree to uphold this Code of Academic Integrity. \\

\begin{center}
\line(1,0){250} ~~~ \line(1,0){100}\\
~~~~~~~~~~~~~~~~~~~~~signature~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ date
\end{center}

\normalsize

\section*{Instructions}

This exam is 110 minutes and closed-book. You are allowed \textbf{one} page (front and back) of a \qu{cheat sheet.} You may use a graphing calculator of your choice. Please read the questions carefully. If the question reads \qu{compute,} this means the solution will be a number otherwise you can leave the answer in \textit{any} widely accepted mathematical notation which could be resolved to an exact or approximate number with the use of a computer. I advise you to skip problems marked \qu{[Extra Credit]} until you have finished the other questions on the exam, then loop back and plug in all the holes. I also advise you to use pencil. The exam is 100 points total plus extra credit. Partial credit will be granted for incomplete answers on most of the questions. \fbox{Box} in your final answers. Good luck!

\pagebreak

\problem This question is about concepts of OLS.

\benum

\subquestionwithpoints{4} Solve for $\c^\star$ where $B \in \reals^{n \times m}$ where $n > m$ and $B$ is full rank:

\beqn
\c^\star = \argmin_{\c \in \reals^{m}}\braces{\c^\top B^\top B \c}
\eeqn~\spc{5}

\subquestionwithpoints{3} Assume $\X \in \reals^{n \times (p+1)}$ where $n >> p + 1$ and $\X$ is full rank and its first column is $\onevec_n$. In terms of $\X, n, p$, (1) give an expression for the matrix $\H$ which represents the orthogonal projection matrix onto the column space of $X$, (2) indicate the dimension of the matrix $\H$ and (3) indicate the rank of the matrix $\H$.

\beqn
\H &=& \hspace{400px}\\
&& \\
\dim\bracks{\H} &=& \\
&& \\
\rank{\H} &=&
\eeqn

\subquestionwithpoints{8} Assume $\b$ is the least squares solution, $\yhat$ is the projection of $\y$ onto the column space of $\X$ defined in (b) via projection matrix $\H$ and $\e$ is the difference between the original vector and this projection. Simplify the following \textit{as best as possible} or indicate an \textit{illegal operation}.

\beqn
\yhat \cdot \e &=& \hspace{400px}\\
&& \\
\yhat + \e &=& \\
&& \\
\yhat \cdot \y &=& \hspace{400px}\\
&& \\
\y \cdot \b &=& \hspace{400px}\\
&& \\
\H \Ht \yhat &=& \hspace{400px}\\
&& \\
(\I - \H)^\top \yhat &=& \hspace{400px}\\
&& \\
\normsq{\y} - \normsq{\X \b} - \normsq{\y - \yhat} &=& \hspace{400px}\\
&& \\
\H \threevec{\ybar}{\vdots}{\ybar} &=& \hspace{400px}\\
&& \\
\H \bracks{\onevec_n~|~\x_{\cdot 4}~|~\x_{\cdot 9}} &=& \hspace{400px} \\
\eeqn

\subquestionwithpoints{6} Assume all notation from (b) and (c). Let $\X = \Q\R$, the Q-R decomposition. Prove that $\b$ in the following expression is the standard least squares solution. Show all steps explicitly for full credit.

\beqn
\R \b = \Q^\top \y \hspace{400px}
\eeqn~\spc{10}

\subquestionwithpoints{9} Assume all notation means the same as in the previous questions. Now, let $\X_{\text{aug}} := \bracks{\X ~|~\x_{\text{junk}}}$ where $\x_{\text{junk}}$ is a $n \times 1$ vector whose entries are all $\iid \stdnormnot$. Let the subscript \qu{aug} refer to all quantities of the OLS solution using $\X_{\text{aug}}$ instead of $\X$. Circle the following statement(s) that are \textit{always} true.

\begin{enumerate}[i)]
\item $\normsq{\e} < \normsq{\e_{\text{aug}}}$
\item $\normsq{\e} > \normsq{\e_{\text{aug}}}$
\item $\normsq{\yhat} < \normsq{\yhat_{\text{aug}}}$
\item $\normsq{\yhat} > \normsq{\yhat_{\text{aug}}}$
\item $\normsq{\y} < \normsq{\y_{\text{aug}}}$
\item $\normsq{\y} > \normsq{\y_{\text{aug}}}$
\item $\normsq{\b} < \normsq{\b_{\text{aug}}}$
\item $\normsq{\b} > \normsq{\b_{\text{aug}}}$
\item $b_{\text{junk}} \approx 0$
\item $R^2 < R^2_{\text{aug}}$
\item $R^2 > R^2_{\text{aug}}$
\item $\normsq{\y} < \normsq{\y_{\text{aug}}}$
\item $\normsq{\y} > \normsq{\y_{\text{aug}}}$
\item $\rank{\H} > \rank{\H_{\text{aug}}}$
\item $\rank{\H} < \rank{\H_{\text{aug}}}$
\item $x_{\text{junk}} \in \colsp{\X_{\text{aug}}}$
\item $\yhat \in \colsp{\X_{\text{aug}}}$
\item $\yhat_{\text{aug}} \in \colsp{\X_{\text{aug}}}$
\end{enumerate}

\subquestionwithpoints{4} Assume $\b$ is now the least absolute cube solution (not the least squares solution). Simplify the following \textit{as best as possible} or indicate an \textit{illegal operation}.

\beqn
\yhat \cdot \e &=& \hspace{400px}\\~\\
&& \\
\yhat + \e &=& \\~\\
\eeqn

\eenum
\pagebreak

\problem This question is about the concept of model validation and the strategy we discussed in class.

\benum

\subquestionwithpoints{6} Let's say we divide scramble the rows of $\mathbb{D}$ then create a partition

\beqn
\mathbb{D} = \threevec{\mathbb{D}_{\text{train}}}{\text{------}}{\mathbb{D}_{\text{test}}}
\eeqn

\noindent in a 4:1 ratio train : test (in number of rows). We then fit $g_1 = \mathcal{A}(\mathcal{H}, \mathbb{D}_{\text{train}})$, $g_2 = \mathcal{A}(\mathcal{H}, \mathbb{D}_{\text{test}})$ and $g_{\text{final}} = \mathcal{A}(\mathcal{H}, \mathbb{D})$. Which of the following statement(s) can be employed as a means of \textit{honest} model validation?

\begin{enumerate}[i)]
\item Comparing $g_1(\X_{\text{train}})$ to $\y_{\text{train}}$
\item Comparing $g_1(\X_{\text{train}})$ to $\y_{\text{test}}$
\item Comparing $g_1(\X_{\text{test}})$ to $\y_{\text{train}}$
\item Comparing $g_1(\X_{\text{test}})$ to $\y_{\text{test}}$
\item Comparing $g_2(\X_{\text{train}})$ to $\y_{\text{train}}$
\item Comparing $g_2(\X_{\text{train}})$ to $\y_{\text{test}}$
\item Comparing $g_2(\X_{\text{test}})$ to $\y_{\text{train}}$
\item Comparing $g_2(\X_{\text{test}})$ to $\y_{\text{test}}$
\item Comparing $g_{\text{final}}(\X_{\text{train}})$ to $\y_{\text{train}}$
\item Comparing $g_{\text{final}}(\X_{\text{train}})$ to $\y_{\text{test}}$
\item Comparing $g_{\text{final}}(\X_{\text{test}})$ to $\y_{\text{train}}$
\item Comparing $g_{\text{final}}(\X_{\text{test}})$ to $\y_{\text{test}}$
\end{enumerate}

\eenum

\pagebreak

\problem This question is about \qu{non-linear} linear modeling. Consider the following data:

\begin{figure}[htp]
\centering
\includegraphics[width=5.5in]{nonlinear}
\end{figure}

\noindent Imagine if $\mathbb{D}$ consisted of the subset of the data pictured above where $\mathcal{X} = \braces{x : x \geq 0}$ i.e. no triangle points are part of the historical data. Consider $\mathcal{A} = $ OLS and the following model candidate sets:

\beqn
\mathcal{H}_1 &=& \braces{w_0 + w_1 x} \\
\mathcal{H}_2 &=& \braces{w_0 + w_1 x^2} \\
\eeqn

\benum

\subquestionwithpoints{3} Which model candidate set would be better for building a model $g$ using $\mathbb{D}$ whose goal is to predict in $\mathcal{X} = \braces{0, 3}$?

\begin{enumerate}[i)]
\item $\mathcal{H}_1$
\item $\mathcal{H}_2$
\item not enough information to tell
\end{enumerate}

\subquestionwithpoints{3} Which model candidate set would be better for building a model $g$ using $\mathbb{D}$ whose goal is to predict in $\mathcal{X} = \braces{-3, 3}$?

\begin{enumerate}[i)]
\item $\mathcal{H}_1$
\item $\mathcal{H}_2$
\item not enough information to tell
\end{enumerate}
\pagebreak

\subquestionwithpoints{3} Which model candidate set would be better for building a model $g$ using $\mathbb{D}$ whose goal is to predict in $\mathcal{X} = \reals$?

\begin{enumerate}[i)]
\item $\mathcal{H}_1$
\item $\mathcal{H}_2$
\item not enough information to tell
\end{enumerate}

\eenum

\problem We continue with \qu{non-linear} linear modeling. We will consider a similar-looking dataset as in the previous problem but the situation will be totally different. Below the response $y$ is plotted by predictor $x$. However there is a second dummy predictor $z$ which is pictured below as well. If $z=1$, the illustration displays a circle and if $z=0$, the illustration displays a triangle. The entire $\mathbb{D}$ is plotted below.

\begin{figure}[htp]
\centering
\includegraphics[width=5.3in]{nonlinear}
\end{figure}

Consider $\mathcal{A} = $ OLS and the following model candidate sets:

\beqn
\mathcal{H}_1 &=& \braces{w_0 + w_1 x} \\
\mathcal{H}_2 &=& \braces{w_0 + w_1 z} \\
\mathcal{H}_3 &=& \braces{w_0 + w_1 x^2} \\
\mathcal{H}_4 &=& \braces{w_0 + w_1 x + w_2 z + w_3 xz} \\
\eeqn

\benum

\subquestionwithpoints{3} Which model candidate set would be better for building a model $g$?

\begin{enumerate}[i)]
\item $\mathcal{H}_1$
\item $\mathcal{H}_2$
\item $\mathcal{H}_3$
\item $\mathcal{H}_4$
\item not enough information to tell
\end{enumerate}

\subquestionwithpoints{6} Regardless of your answer in (a), assume $\mathcal{H}_4$ was employed. Estimate $\b$ as best as you can.\spc{9}

\eenum

\problem This question is about general concepts of modeling including under/overfitting.

\benum

\subquestionwithpoints{6} Assume a general $\mathbb{D}$, $\mathcal{A}$ and $\mathcal{H}$ and $\mathcal{Y} \subset \reals$.  In the graph below, (1) draw the relationship between in-sample error and model complexity, (2) draw the relationship between out-of-sample error and model complexity, then (3) indicate the region of underfitting and (4) indicate the region of overfitting.  \spc{-0.5}

\begin{figure}[htp]
\centering
\includegraphics[width=6.5in]{complexity}
\end{figure}

\pagebreak

\subquestionwithpoints{6} Assume a general phenomenon where you're given $\mathbb{D}$ and $\mathcal{Y} \subset \reals$ and $\mathcal{A}$ and corresponds to a least squares minimization for and a simple model space $\mathcal{H}$ with 10 parameters. Assume $\epsilon$ is non-zero. Now, (1) draw the relationship between in-sample error and $n$, the number of data points in $\mathbb{D}$, (2) draw the relationship between out-of-sample error and $n$.  \spc{-0.5}

\begin{figure}[htp]
\centering
\includegraphics[width=5.35in]{n_increasing}
\end{figure}

\subquestionwithpoints{3} [Extra credit] Assume the same setup as in (b) but now the model space $\mathcal{H}$ is complex with 100 parameters. Now, (1) draw the relationship between in-sample error and $n$, the number of data points in $\mathbb{D}$, (2) draw the relationship between out-of-sample error and $n$. Make sure to indicate clearly how the relationships differ here from the relationships you drew in (b).  \spc{-0.5}

\begin{figure}[htp]
\centering
\includegraphics[width=5.35in]{n_increasing}
\end{figure}

\subquestionwithpoints{6} Consider the plot below. \spc{-0.5}

\begin{figure}[htp]
\centering
\includegraphics[width=5.5in]{sine}
\end{figure}

Which one(s) of the following statement(s) are most likely true?

\begin{enumerate}[i)]
\item the predictor $x$ and the response $y$ are correlated
\item the predictor $x$ and the response $y$ are associated
\item $s_{xy}$ will be approximately zero
\item $s_{xy}$ will be exactly zero
\item $r$ will be approximately zero
\item $r$ will be exactly zero
\item $\delta = 0$
\item $f(x) = 0$
\item the random variable $X$ (that generated the realizations of $x$ above) and the random variable $Y$ (that generated the $\iid$ realizations of $y$) are dependent
\item the random variable $X$ (that generated the realizations of $x$ above) and the random variable $Y$ (that generated the $\iid$ realizations of $y$) are independent
\item this data is only of theoretical interest and can never be found in the real world
\item a linear model with polynomial terms will take many degrees of freedom to fit well
\item a model with a intelligently selected $\mathcal{H}$ can be fit with very few degrees of freedom
\item this data can \textit{only} be fit if one uses three splits of $\mathbb{D}$ --- one for training, one for selection and one for testing
\end{enumerate}

\eenum
\pagebreak

\problem Below are some questions on the practice topics we studied. We first load the diamonds data and we remind ourselves of the response (\texttt{price}) and the 9 features:

\begin{lstlisting}
> pacman::p_load(ggplot2)
> data(diamonds)
> diamonds$cut = factor(as.character(diamonds$cut))
> diamonds$color = factor(as.character(diamonds$color))
> diamonds$clarity = factor(as.character(diamonds$clarity))
> summary(diamonds)
    carat               cut        color        clarity
 Min.   :0.2000   Fair     : 1610   D: 6775   SI1    :13065
 1st Qu.:0.4000   Good     : 4906   E: 9797   VS2    :12258
 Median :0.7000   Ideal    :21551   F: 9542   SI2    : 9194
 Mean   :0.7979   Premium  :13791   G:11292   VS1    : 8171
 3rd Qu.:1.0400   Very Good:12082   H: 8304   VVS2   : 5066
 Max.   :5.0100                     I: 5422   VVS1   : 3655
                                    J: 2808   (Other): 2531
     depth           table           price             x
 Min.   :43.00   Min.   :43.00   Min.   :  326   Min.   : 0.000
 1st Qu.:61.00   1st Qu.:56.00   1st Qu.:  950   1st Qu.: 4.710
 Median :61.80   Median :57.00   Median : 2401   Median : 5.700
 Mean   :61.75   Mean   :57.46   Mean   : 3933   Mean   : 5.731
 3rd Qu.:62.50   3rd Qu.:59.00   3rd Qu.: 5324   3rd Qu.: 6.540
 Max.   :79.00   Max.   :95.00   Max.   :18823   Max.   :10.740

       y                z
 Min.   : 0.000   Min.   : 0.000
 1st Qu.: 4.720   1st Qu.: 2.910
 Median : 5.710   Median : 3.530
 Mean   : 5.735   Mean   : 3.539
 3rd Qu.: 6.540   3rd Qu.: 4.040
 Max.   :58.900   Max.   :31.800
\end{lstlisting}
\vspace{-1cm}

\benum

\subquestionwithpoints{4} As best as you can, illustrate the output of the following code. Make sure you label axes and provide some tick marks.

\begin{lstlisting}
> ggplot(diamonds) +
     geom_density(aes(carat))
\end{lstlisting}~\spc{6}

\subquestionwithpoints{4} We now run an anova model as follows:

\begin{lstlisting}
> anova_mod = lm(price ~ cut, diamonds)
\end{lstlisting}
\vspace{-0.8cm}

and below are the $\b$ and RMSE:

\begin{lstlisting}
> coef(anova_mod)
 (Intercept)      cutGood     cutIdeal   cutPremium cutVery Good
   4358.7578    -429.8933    -901.2158     225.4999    -376.9979
> summary(anova_mod)$sigma
[1] 3963.847
\end{lstlisting}
\vspace{-0.8cm}

The first six entries of the variable \texttt{cut} are:

\begin{lstlisting}
> head(diamonds$cut)
[1] Ideal     Premium   Good      Premium   Good      Very Good
Levels: Fair Good Ideal Premium Very Good
\end{lstlisting}
\vspace{-0.8cm}

Provide below the first six rows of the model matrix $\X$ for the model \texttt{price $\sim$ cut}.\spc{5}

\subquestionwithpoints{3} [Extra credit] Given the model and the results in (b), illustrate as best as you can the result of the following code. Credit will only be given to near perfect renditions.

\begin{lstlisting}
> ggplot(diamonds) +
     geom_boxplot(aes(x = cut, y = price))
\end{lstlisting}~\spc{6}

\subquestionwithpoints{6} The first six entries of carat are

\begin{lstlisting}
> head(diamonds$carat)
[1] 0.23 0.21 0.23 0.29 0.31 0.24
\end{lstlisting}
\vspace{-0.8cm}

Illustrate the result of the following code:

\begin{lstlisting}
> head(model.matrix(price ~ carat * cut, diamonds))
\end{lstlisting}~\spc{5}

\subquestionwithpoints{6} Consider $\mathcal{A} = $ OLS and the following models explaining diamond \texttt{price}:

\begin{enumerate}[1.]
\item a 4-degree polynomial of carat
\item all raw features
\item all features interacted with carat
\item all interactions
\end{enumerate}

Write code below to fit these four models and save them as \texttt{mod\_1}, \texttt{mod\_2}, \texttt{mod\_3}, \texttt{mod\_4}. \spc{6}

\subquestionwithpoints{4} If $R^2$ was employed to select the \qu{best} model of the four in (d), what would be the result? That is, which model would it declare the winner?\spc{0.5}

\subquestionwithpoints{5} [Extra credit] Write code below that will select the \qu{best} model of the four in (d) as measured by future predictive performance.

\eenum

\end{document}


\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{url}
\author{Micky Faas}
\begin{document}
\title{Verkade: LU-Factorisation on Sparse Matrices}
\maketitle
\section{Introduction}
\emph{Verkade} is an implementation of LU-factorisation on sparse matrices using the simple Gaussian elimination method with partial pivotting. Partial pivotting lends itself very well for sparse matrices as only row or column permutations are required but not both. Therefore the matrix data can be stored either by row or by column. Verkade stores matrices by row in \emph{compressed row storage} (CRS)\cite{crs}.

To load matrix data, the \emph{matrix market} format\cite{mm} is used. The various test matrices described in this document are obtained from Suite Sparse\cite{suitesparse}.

\section{Implementation}

LU-factorisation is performed in situ on the CRS input data. Both the L and the U result matrix are stored at the same location: for a given row $i$ all columns $0\dots{j-1}$ belong to the L matrix while all columns $j\dots{n-1}$ belong to the U matrix.

\subsection{Fill-ins}

When transforming a sparse matrix using Gaussian elimination, it often happens that the density of the matrix increases. When pivot row $i$ is subtracted from row $k$, $A(i,j)$ may be non-zero while $A(k,j)$ is zero such that the resulting operation $A(k,j)=A(k,j)-rA(i,h)$ is also non-zero. This means an extra non-zero value has to be added into row $k$, which expands the entire values-array in the CRS. In Table \ref{fillin} we see that the factor in which the rows expand can be quite dramatic. To accommodate for these variations in length, rows $i$ and $k$ are often converted into dense representation first (scatter-gather). However, our experiments showed that this increased computation time by a factor of 10 compared to generating CRS immediate without scatter-gather. To this end we implement some simple form of memory management that supports heap-style allocation.

\begin{table}
\begin{tabular}{|l|rr|rr|r|}
\hline
Matrix & Elements & Density & Elements after & Density after & Fill-in ratio\\
\hline
mcfe & 24382 & .042  & 87396 & .15 & 3.58  \\
c-21 &  32157 & .0026  & 4915965 & .4 & 152.87  \\
flowmeter5 & 67391 & .0007 & 1182851 & .013 & 17.56 \\
epb1 & 95053  & .00044  & 3079993 & .014 & 32.40 \\
meg4 & 46842 & .0014 & 746284 & .022 & 15.93 \\
cell1 & 34855  & .0007  & 474506  & .0095 & 13.61 \\
nopoly &  70842 & .00061  & 15417152 & .13 & 217.63 \\
mhd4800b & 27520  &  .0012 & 33490  & .0015 & 1.22\\
ex10 & 54840 &  .0094 & 183234 & .032 & 3.41\\
aft01 & 125567  & .0019  & 1713317 & .025 & 13.64\\
\hline
\end{tabular}
\label{fillin}
\caption{Ratio for fill-in after LUP transformation.}
\end{table}

\subsection{Memory Management}

Verkade implements a simple memory management that supports allocating and freeing memory regions just like in C. It does this by maintaining a meta array of region descriptors separately from the CRS data. In the simplest form this meta array only contains free regions: when a row is expanded it leaves a `hole' in the array and the new data is moved to the back of the occupied space. A list of these free regions is later used to assign memory to other expanding rows.

A problem with this approach is the inherent fragmentation of the memory space. To counter fragmentation, we also need to store the occupied regions in the CRS array. This makes bookkeeping the meta array much more complex, but it enables us to move the row data around later to clear space when it is needed. In practice, however, the amount of data lost by fragmentation was so small that it did not outweigh the overhead caused by the more complex memory management. Table \ref{mem} shows the loss due to fragmentation while Table \ref{times} shows the performance of the algorithm for both memory managers. These times were obtained by running LUP and the substitution to five different result vectors on a Core-i7 machine.

\begin{table}
\begin{tabular}{|l|rrr|}
\hline
Matrix & Original size (KiB) & Size after LUP (KiB) & Bytes lost (KiB)\\
\hline
mcfe & 190  & 684  & 27  \\
c-21 & 251  & 38405  & 3582  \\
flowmeter5 & 526  & 9241  & 1010  \\
epb1 & 742  & 24062  & 3188  \\
meg4 & 365  & 5830  & 204  \\
cell1 & 272  & 3707  & 18  \\
nopoly & 553  & 120446  & 4666  \\
mhd4800b & 215  & 261  & 5  \\
ex10 & 428  & 1421  & 27  \\
aft01 & 980  & 13385  & 726  \\
\hline
\end{tabular}
\label{mem}
\caption{Memory footprint and loss due to fragmentation.}
\end{table}

\subsection{Numerical stability}

Compared to complete pivotting, the method of partial pivotting can lead to much more numerical instability. In this case there is a trade-off to make because partial pivotting is much more suited for use with the simple CRS format for sparse matrices. In order to measure the effect of numerical instability on the test matrices, the Euclidian norm was used: $\frac{||\tilde{x}-x||}{x}$ was computed for each solution vector. Here $x$ is the pre-computed vector and $\tilde{||x||}$ is the vector computed by the algorithm. $||$ is simply the square-root of the sum of squared elements of the vectors.

For almost all vectors the variance was exactly zero. This means no instability occurred. Only for the \texttt{nopoly} matrix any variance was measured (1, 0.656, 0.021, 0.012, 0.008 for vectors $x_1$ to $x_5$ respectively). The \texttt{nopoly} matrix was also a very hard matrix to factorise in terms of time and memory, which probably suggest it is not suitable to compute it with partial pivotting (it is not invertible).

\begin{table}
\begin{tabular}{|l|rr|}
\hline
Matrix & Only free regions (s) & Full memory + defragmentation (s) \\
\hline
mcfe & 0.054 & 0.12 \\
c-21 & 19.16 & 43.91  \\
flowmeter5 & 7.04 & 19.89 \\
epb1 & 20.71 &  60.28   \\
meg4 & 2.30 &  5.30   \\
cell1 & 1.64 & 4.66  \\
nopoly & 131.21 & 376.22 \\
mhd4800b & 0.17 & 0.26  \\
ex10 & 0.32 & 0.70 \\
aft01 & 6.58 & 22.13 \\
\hline
\end{tabular}
\label{times}
\caption{Timings for LUP and substitutions for both memory models.}
\end{table}

\begin{thebibliography}{XX}

\bibitem{crs}
Compressed Row Storage. \url{http://www.netlib.org/linalg/html_templates/node91.html}

\bibitem{mm}
The Matrix Market fileformat. \url{https://math.nist.gov/MatrixMarket/formats.html}

\bibitem{suitesparse}
SuiteSparse, Tim Davis et al. \url{https://sparse.tamu.edu/}

\end{thebibliography}

\end{document}


\documentclass[handout, navsym]{tum-presentation}

\graphicspath{{figs/}}
\usepackage{fancybox}
\usepackage{listings}
\usepackage{xcolor}

\setbeamercovered{invisible}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{section in toc}[sections numbered]
\setbeamertemplate{subsection in toc}[subsections numbered]
\setbeamertemplate{subsubsection in toc}[subsubsections numbered]
\numberwithin{equation}{section}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{
	basicstyle=\footnotesize\ttfamily,% 基本风格
         numbers=left,    % 行号
         numberstyle=\tiny,
         numbersep=10pt,  % 行号间隔
         tabsize=2,       % 缩进
         extendedchars=true, % 扩展符号？
         breaklines=true, % 自动换行
         language=C++,
         frame=shadowbox,  % 框架左边竖线
         xleftmargin=19pt,% 竖线左边间距
         showspaces=false,% 空格字符加下划线
         showstringspaces=false,% 字符串中的空格加下划线
         showtabs=false,  % 字符串中的tab加下划线
       xleftmargin=2em,xrightmargin=2em,aboveskip=1em
}

\title{Praktikum: Grundlagen der Programmierung}
\author[Wenjie Hou]{Wenjie Hou}
\date{2. Tutorübung}
\institute{\theuniversity\par Fakultät für Informatik}
\footline{\insertshortauthor~|~\insertshorttitle~|~2. Tutorübung}

\begin{document}

\begin{frame}[noframenumbering]
  \titlepage
\end{frame}

\begin{frame}[t]
  \frametitle{Overview}
 \tableofcontents[section=show,subsectionstyle=show]
\end{frame}

\section{Lecture Review}

\begin{frame}
  \frametitle{Lecture Review}

  \begin{alertblock}{Control Statements in Java}
   \begin{enumerate}
  \item Decision Making
  	\begin{itemize}
	\item if...then
	\item if...then...else
	\item if...then...else if...then...
	\item Switch
	\item Ternary operation A ? B : C
	\end{itemize}
  \item Looping Statements
  	\begin{itemize}
	\item While Loop
	\item Do-While Loop
	\item For Loop
	\item Foreach Loop
	\end{itemize}
  \item Branching Statements
  \begin{itemize}
	\item Break
	\item Countinue
	\item Return
	\end{itemize}
  \end{enumerate}
  \end{alertblock}
\end{frame}

\section{P01: Summieren}
\begin{frame}[fragile]
  \frametitle{P01: Summieren}
  \vspace*{\fill}
\large  In this task, a program is to be created which calculates the sum of several integers entered by the user. Ask the user to enter a number with "$\color{blue} Bitte$ $\color{blue}Zahl$ $\color{blue} eingeben:$" \textbf{until 0 is entered}. \par
~\\
As soon as the number 0 is entered, print "$\color{blue} Summe:$", print the sum of the numbers entered by the user in another line  and \textbf{terminated} the program.\par
\bigskip
\textbf{\large Example Output:}
\center
\begin{lstlisting}
<Bitte Zahl eingeben:
>-3
<Bitte Zahl eingeben:
>31
<Bitte Zahl eingeben:
>0
<Summe:
<28
\end{lstlisting}

\vspace*{\fill}
\end{frame}

\subsection{Flow Diagram}
\begin{frame}{Flow Diagram}
\begin{figure}[htbp]
\centering
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[height=8cm]{p1-1.png}
\caption{v1}
\end{minipage}
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[height=8cm]{p1-2.png}
\caption{v2}
\end{minipage}
\end{figure}
\end{frame}

\subsection{Code - 1}
\begin{frame}{Code -1}
\center \includegraphics[height=9cm]{p1-code.png}
\end{frame}

\subsection{Code - 2}
\begin{frame}{Code -2}
\center \includegraphics[height=9cm]{p1-2-code.png}
\end{frame}

\section{P02: Integer factorization}
\begin{frame}[fragile]
\frametitle{P02: Integer factorization}
\vspace*{\fill} \large
Any natural number $n > 1$ is either a prime itself or can be represented as a product of prime numbers. To calculate the prime factorization of a number $n$, divide it by all natural numbers starting from 2. If a divisor t is found, then output t. If the quotient $\frac{n}{t} > 1$, then it is also decomposed into its prime factors.\par
~\\
Write a MiniJava program that says\textsl{ \color{blue}"Bitte Zahl eingeben:"} and reads a natural number $n > 1$ from the user and breaks it up into prime terms. Your program should output all prime factors of the number $n$ separated by spaces on the screen. If the input number entered is $n \leq 1$, then print \textsl{\color{blue}"Fehler: $n >1$ erwartet!"}.\par
~\\
Tip: You can use the $\color{blue}writeConsole ()$ method to print something on the console without extra line break. By using method $\color{blue}writeLineConsole()$ you can print a line with the line feed.\par
\bigskip
\textbf{\large Example Output:}
\begin{lstlisting}
Bitte Zahl eingeben:
>12321342
2 3 3 3 11 20743
\end{lstlisting}
\vspace*{\fill}

\end{frame}

\subsection{Flow Diagram}
\begin{frame}[fragile]
\frametitle{Flow Diagram}

\center \includegraphics[height=9cm]{p2.png}

\end{frame}

\subsection{Code}
\begin{frame}[fragile]
\frametitle{Code}

\center \includegraphics[height=9cm]{p2-code.png}

\end{frame}

\section{P03: Population of Rabbit}
\begin{frame}[fragile]
\frametitle{P03: Population of Rabbit}
\vspace*{\fill} \large

We put a pair of mature rabbits on a desert island to find out how many rabbits will born within a year. It is assumed that every mature couple will give birth to a new pair of rabbits each month. Each rabbit pair is sexually mature for the first month of life and each rabbit has \textbf{a lifetime of $3$ months}.\par
~\\
Write a MiniJava program that reads in the number $n$, which is the $n^{th}$ month. Your program should print out the sum of the rabbit pairs, which are mature in the $n^{th}$ month. You can assume that $n \geq 1$. \par
\bigskip
\textbf{\large Example Output:}
\begin{lstlisting}
<Bitte Zahl eingeben:
>3
<4
\end{lstlisting}
\vspace*{\fill}
\end{frame}

\subsection{Code}
\begin{frame}[fragile]
\frametitle{Code}

\vspace{-2cm}
\center \includegraphics[height=11cm]{p3-code.png}

\end{frame}

\section{P04: 3 and 7}
\begin{frame}[fragile]
\frametitle{P04: 3 and 7}
\vspace*{\fill} \large

Write a program that prints \textsl{ \color{blue}"Bitte Zahl eingeben:"}" and then read in a number $n$. Then it calculate the sum of all positive numbers less than or equal to n, and are divisible by 3 or 7. Then print the result to console. If the user enters a negative number,\textsl{\color{blue}"Fehler: $n >1$ erwartet!"} and exit the program.\par
~\\
If the user types e.g. If the number is $25$, so we add $3, 6, 7, 9, 12, 14, 15, 18, 21, and 24$ and it gives us $129$.\par
\bigskip
\textbf{\large Example Output:}
\begin{lstlisting}
Bitte Zahl eingeben:
>91
1822

Bitte Zahl eingeben:
>16
1822
\end{lstlisting}

\vspace*{\fill}
\end{frame}

\subsection{Code}
\begin{frame}[fragile]
\frametitle{Code}

\center \includegraphics[height=9cm]{p4-code.png}

\end{frame}

\begin{frame}[fragile]
\vspace*{\fill}
\begin{center}
 \Huge Thank You!
\end{center}
\vspace*{\fill}
\end{frame}

\end{document}


\documentclass{article}

\usepackage[margin=1in]{geometry}

\title{Mathematical Symbols}
\author{Toni Farley}
\date{}

\begin{document}
\maketitle

\section{Introduction}

This document will include some math.

\subsection{Math Formulas}

Mathematical equations can be created inline as $5*4=20$, and can include a number of different math symbols, such as $7 \leq 10$ is true.

You can also put your equation on a separate line as \[5^2 = 25\] to call out the formula.

\subsection{Float: Equations}

My first result is shown in Equation~\ref{eq:minutes}, which shows the number of minutes in a day.

\begin{equation}
24*60 = 1,440
\label{eq:minutes}
\end{equation}

There are a lot of interesting math symbols that I can learn, as shown in Equation~\ref{eq:symbols}.

\begin{equation}
7^4+6*17 \geq 13 \cup X \alpha 13 \exists \rightarrow nonsense
\label{eq:symbols}
\end{equation}

\section{Conclusion}

And this was a brief primer on math in \LaTeX.

\end{document}


\documentclass[a4paper,11pt]{article}
\usepackage{geometry}
 \geometry{
 a4paper,
 total={170mm,257mm},
 left=20mm,
 top=20mm,
 }

 \usepackage{amsmath}
 \usepackage{siunitx}
 \usepackage{multirow}
\usepackage{colortbl}
 \usepackage{hhline}

 \usepackage{lipsum}  %%% Lorem ipsum

\setlength{\headheight}{30.0pt}
\setlength{\footskip}{20pt}

\usepackage{hyperref}
\hypersetup{
    colorlinks=True,
    linkcolor={blue!20!black},
    filecolor=magenta,
    urlcolor=cyan,
}

 \usepackage[export]{adjustbox}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{multicol}

\pagestyle{fancy}
\fancyhf{}
\rhead{\textit{Pul074BEX004}}
\lhead{\textit{Amrit Prasad Phuyal}}
\rfoot{\thepage}

\usepackage{mathpazo} % Palatino font
\usepackage{graphicx}
\usepackage{float}

\input{./CoverPage.tex} %%% cover page
\include{./Matlab.tex} %%% Matlab code

%%%%%%%%%%%%%%%%%%%%%% for matlab observation #1 fig name #2 Caption
\newcommand{\mobs}[2]{
    \begin{figure}[H]
        \centering
        \includegraphics[width=0.9\linewidth]{./FIG/#1.eps}
        \caption{#2}
    \end{figure}

}

\begin{document}

%%%%  COver page
\CP{Communication System II}{Lab \#2}{Sampling, TDM \& Demodulation}
{Suman Sharma}
%%%%%%%%%%%%%%%%%%%%

\pagenumbering{gobble}
\renewcommand{\contentsname}{Table of Contents}
\tableofcontents

\pagebreak
%\listoffigures
% \pagebreak
% \listoftables
% \vspace{5em}
\lstlistoflistings
\vspace{10em}
% \pagebreak
\listoffigures
\pagebreak
\pagenumbering{arabic}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Title} {\large Sampling, TDM \& Demodulation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Objective}
\begin{itemize}
    \item To observe Signal Reconstruction using Samples
    \item To observe Time Division Multiplexing of two signals
    \item To observe Delta Modulation and its bits sequence
\end{itemize}
%%%%%%%%%%%%%%%%%%%%%

%Theory
\section{Theory}
\subsection{Sampling and Signal Reconstruction}
Sampling is the process of taking a continuous signal and converting it into discrete signal. In other words, sampling is measuring the instantaneous value of continuous time signal.If $s(t)$ is a continuous time signal, then, the sampled discrete time signal having Sampling period $T_s$, denoted by $s[n]$,
is given by:
\begin{equation*}
    s[n] = s( nT_s )
\end{equation*}

Interplotation technique is used to interpolate the sampled signal in order to recover the continuous time signal.

\subsection{Time Division Multiplexing (TDM)}
Time Division Multiplexing is a technique of multiplexing two signals in a single signal. Here each signal is allocated a definite amount of time such that the transmission appear to be parallel.

\subsection{Delta Modulation}
Delta Modulation is a technique of encoding a signal using a single bit. The signal is encoded using a single bit, which is either a 1 or a 0. The encoding is done by adding a delta to the original signal. The delta $\Delta$ is a small amount of the original signal. The delta is added to the original signal and the resulting signal is the encoded signal. It create stair-case approximation of output waveform. Delta modulation is deployed when transmission of voice is needed and quality is not the primary concern.

\pagebreak
%Problems
\section{Problems}

\subsection{Signal Reconstruction using Sampling}

\MAT{./CODES/Sampling.m}{MATLAB code Signal Reconstruction using Sampling}
\mobs{Sampling1}{Orginal signal and its sampling}
\mobs{Sampling2}{Sampled Signal and its Reconstruction Step at n=10}
\mobs{Sampling3}{Sampled Signal and final  Reconstructed Signal}

\subsection{Time Division Multiplexing (TDM)}

\MAT{./CODES/TDM.m}{Time Division Multiplexing (TDM)}
\mobs{TDM1}{Orginal signals and their sampled form}
\mobs{TDM2}{Multiplexed Signal}
\mobs{TDM3}{Demultiplexed Signals}

\subsection{Delta Modulation}

\MAT{./CODES/Delta.m}{Delta Modulation and its bits sequence}
\mobs{Delta}{ Delta Modulation and its bits sequence}

%%Discussion and Conclusion
\section{Discussion and Conclusion}
In this Lab we performed the Sampling of original signal and recover the measure signal from its sampled version. We also performed Time Division Multiplexing of two signals and Demultiplex the signals to recover the originals. We also performed Delta Modulation of a signal and its bits sequence. We used MATLAB, its modules and functions to perform the above tasks.

\end{document}

Communication System II/LAB 2/Comm sys II LAB 2 Amrit Prasad Phuyal.tex


\documentclass[12pt,a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[charter]{mathdesign}
\usepackage{amsmath,amsthm,enumitem,graphicx,titlesec,xcolor}
\usepackage{microtype}
\usepackage[a4paper,margin=25mm]{geometry}
\usepackage[unicode]{hyperref}

\hypersetup{
    hidelinks,
    pdftitle={Distributed Algorithms},
    pdfauthor={Juho Hirvonen and Jukka Suomela},
}

\definecolor{titlecolor}{HTML}{0088cc}
\definecolor{hlcolor}{HTML}{f26924}

\newcommand{\q}[2]{\paragraph{\mbox{Question #1: }#2.}}
\newcommand{\sep}{{\centering \raisebox{-3mm}[0mm][0mm]{$*\quad*\quad*$}\par}}
\newcommand{\hl}[1]{\textbf{\emph{#1}}}
\newcommand{\cemph}[1]{\textcolor{hlcolor}{\emph{#1}}}
\DeclareMathOperator{\re}{re}

\setitemize{noitemsep,leftmargin=3ex}

\titleformat{\paragraph}[runin] {\normalfont\normalsize\bfseries\color{titlecolor}}{\theparagraph}{1em}{}

\begin{document}

\noindent
\emph{CS-E4510 Distributed Algorithms / Juho Hirvonen, Jukka Suomela\\
second exam, 10 December 2020}

\paragraph{Instructions.}

There are five questions, and you must answer \hl{at least four questions} in order to pass the exam.

You are free to look at any source material (this includes lecture notes, textbooks, and anything you can find with Google), but you are not allowed to collaborate with anyone else or ask for anyone's help (this includes collaboration with other students and asking for help in online forums).

You are free to use any results from the lecture notes directly (including the results from the regular exercises). You are free to use computers and computer programs to find solutions.

If you cannot solve a problem entirely, please try to at least explain what you tried and what went wrong.

\sep

\q{1}{Maximal matching}

Consider the following graph $G_1$ with 16 nodes:
\begin{center}
\includegraphics[page=1,scale=0.5]{figs.pdf}
\end{center}
Design a deterministic PN-algorithm $A$ that finds a \hl{maximal matching} in graph $G_1$. That is, if you run $A$ in any simple port-numbered network $N$ that has graph $G_1$ as the underlying graph, algorithm $A$ will stop and output a maximal matching.

The local inputs of the nodes are empty. Any running time is fine. A brief, informal description of the algorithm is sufficient. The algorithm does not need to do anything meaningful if you run it in any other graph.

\q{2}{Edge coloring}

Let graph $G_1$ be as defined in question~1. Prove that there is no deterministic PN-algorithm that solves the following problem: finding a \hl{proper edge coloring} (with any number of colors) in graph $G_1$.

\bigskip\noindent
\emph{Hint:} You are expected to use an argument based on covering maps.

\vspace{\stretch{1}}
\noindent\emph{There is more, please see the other page\ldots}

\newpage

\q{3}{Two colors}

Design a deterministic PN-algorithm that solves the following problem in $O(1)$ rounds:
\begin{itemize}
    \item Graph family: bipartite graphs.
    \item Local inputs: proper vertex coloring with $2$ colors.
    \item Local outputs: label the edges with labels R, G, and B such that for any node $v$ of degree at least $10$, the edges incident to $v$ use \hl{at least two different labels}.
\end{itemize}
A brief, informal description of the algorithm is sufficient.

\q{4}{Three colors}

Prove that there is no deterministic PN-algorithm that solves the following problem in $O(1)$ rounds:
\begin{itemize}
    \item Graph family: bipartite graphs.
    \item Local inputs: proper vertex coloring with $2$ colors.
    \item Local outputs: label the edges with labels R, G, and B such that for any node $v$ of degree at least $10$, the edges incident to $v$ use \hl{all three labels}.
\end{itemize}
\emph{Hints:} Consider $(10,10)$-biregular trees. Compare with the sinkless orientation problem.

\q{5}{One red, one green}

Consider the following problem in $(10,10)$-biregular trees: label the edges with labels R, G, and B such that for any node $v$ of degree $10$, the edges incident to $v$ use label R \hl{exactly once} and label G \hl{exactly once}.
\begin{enumerate}[label=(\alph*)]
\item Formalize this as a \emph{bipartite locally verifiable problem} $\Pi$ (Section 9.1.1 in the lecture notes).
\item Show that $\Pi$ is not solvable in $0$ rounds.
\item Show that $\Pi$ is a periodic point in round elimination, i.e., if you apply $\re$ sufficiently many times, you will arrive at a problem equivalent to $\Pi$.
\item How long is the period, i.e., how many applications of $\re$ are needed to arrive at the original problem $\Pi$?
\end{enumerate}

\end{document}