\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[]{Unit Step, Impulse}
\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{Discrete Unit step and Impulse}

\frame{
\begin{exampleblock}{Today}
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}

}

\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}

}

\section{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{
\textbf{{\color {darkblue} We approximate} $x(t)$} by a lineal combination of delayed and scaled versions of  $\delta_{L}(t)$

\begin{figure}
\centering\includegraphics[scale=0.4]{Figures/Signal322.pdf}
\end{figure}
}

\frame{
\frametitle{Continuous-time Impulse. Properties (II).}
\[
x(t) \approx x_{L}(t) = \sum_{k=-\infty}^{\infty}{x(kL){\color{darkblue}\delta_{L}(t-kL)}L}
\]

If we take the limit $L \rightarrow 0$:
\begin{itemize}
\item $kL \rightarrow \tau$
\item $\sum \rightarrow \int$
\item $L \rightarrow d\tau$
\end{itemize}

\begin{align}\nn
x(t)=\int_{-\infty}^{\infty}x(\tau)\delta(t-\tau) d\tau
\end{align}

}

\frame{
\frametitle{Relationship with the rectangular pulse}

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

}

\end{document}

Slides Systems_Circuits/M_3 Unit Step, Impulse/Unit_Impulse.tex


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx}
\usepackage{listings}
\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ (\hmwkClassInstructor\ \hmwkClassTime): \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

% \lstset{
%  columns=fixed,
%  numbers=left,                                        % 在左侧显示行号
%  numberstyle=\small\color{gray},                       % 设定行号格式
%  frame=none,                                          % 不显示背景边框
%  backgroundcolor=\color[RGB]{245,245,244},            % 设定背景颜色
%  keywordstyle=\color[RGB]{40,40,255},                 % 设定关键字颜色
%  numberstyle=\footnotesize\color{darkgray},
%  commentstyle=\it\color[RGB]{0,96,96},                % 设置代码注释的格式
%  stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},   % 设置字符串格式
%  showstringspaces=false,                              % 不显示字符串中的空格
%  language=c++,                                        % 设置语言
% }

% \usepackage{listings}
\usepackage{color}

\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}

\lstset{
  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument
  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
  breaklines=true,                 % sets automatic line breaking
  captionpos=b,                    % sets the caption-position to bottom
  commentstyle=\color{mygreen},    % comment style
  deletekeywords={...},            % if you want to delete keywords from the given language
  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
  frame=single,	                   % adds a frame around the code
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
  keywordstyle=\color{blue},       % keyword style
  language=Octave,                 % the language of the code
  morekeywords={*,...},            % if you want to add more keywords to the set
  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)
  numbersep=5pt,                   % how far the line-numbers are from the code
  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
  showstringspaces=false,          % underline spaces within strings only
  showtabs=false,                  % show tabs within strings adding particular underscores
  stepnumber=2,                    % the step between two line-numbers. If it's 1, each line will be numbered
  stringstyle=\color{mymauve},     % string literal style
  tabsize=2,	                   % sets default tabsize to 2 spaces
  title=\lstname                   % show the filename of files included with \lstinputlisting; also try caption instead of title
}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Homework\ \#1}
\newcommand{\hmwkDueDate}{Jan. 24, 2019}
\newcommand{\hmwkClass}{CPSC8400}
\newcommand{\hmwkClassTime}{}
\newcommand{\hmwkClassInstructor}{Professor Dr.Brian Dean}
\newcommand{\hmwkAuthorName}{\textbf{Guoze Tang}}

%
% Title Page
%

\title{
    \vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{Due\ on\ \hmwkDueDate\ at 12:25pm}\\
    \vspace{0.1in}\large{\textit{\hmwkClassInstructor\ \hmwkClassTime}}
    \vspace{3in}
}

\author{\hmwkAuthorName}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

\pagebreak

\begin{homeworkProblem}
% \textbf{Virtual Initialization}. One problem with arrays is that they must typically be initialized prior to use. On most computing environments, when we allocate an array of O(n) words of memory they start out filled with “garbage” values (whatever data last occupied that block of memory), and we must spend O(n) time setting the words in the block to some initial value. In this problem, we wish to design a data structure that behaves like an array (i.e., allowing us to retrieve the ith value and modify the ith value both in O(1) time), but which allows for initialization to a specified value v in O(1) time as well. That is, if we ask for the value of an element we have not modified since the last initialization, the result should be v. The data structure should occupy O(n) space in memory (note that this could be twice or three times as large as the actual space we need to store the elements of the array), and the data structure should function properly regardless of whatever garbage is initially present in this memory. As a hint, try to combine the best features of an array and a linked list.
    % Give an appropriate positive constant \(c\) such that \(f(n) \leq c \cdot
    % g(n)\) for all \(n > 1\).

    % \begin{enumerate}
    %     \item \(f(n) = n^2 + n + 1\), \(g(n) = 2n^3\)
    %     \item \(f(n) = n\sqrt{n} + n^2\), \(g(n) = n^2\)
    %     \item \(f(n) = n^2 - n + 1\), \(g(n) = n^2 / 2\)
    % \end{enumerate}
\textbf{Requirements}
    \begin{enumerate}
        \item Retrieve the ith valuse and modify the ith value both in O(1) time
        \item Initialization to a specified value v in O(1) time
        \item Space: O(n), can twice or three times as large as the actual space we need.
        \item The data structure should function properly regardless of whatever garbage is initially present in the memory.
    \end{enumerate}
    \textbf{Solution}

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
% \textbf{Enumerating Subsets by Incrementing a Binary Counter}. This is a somewhat classical amortized analysis problem. Suppose we store the digits of an n-bit binary number B in an array A of length n. We wish to increment B from 0 to $2^n - 1$ while continually modifying the contents of A to reflect the digits in B. For example, if n = 3, then we will start with $A = (0, 0, 0)$, then we toggle the last entry to obtain A = (0, 0, 1). The next increment operation changes A to A = (0, 1, 0), and so on, until we finally reach A = (1, 1, 1). Please describe how to implement the operation increment that takes an array A and modifies it by incrementing its associated binary number. Although your operation will require $\theta(n)$ time in the worst case, please show that its amortized running time is only $O(1)$ (assuming the entries in A all start out at zero). Please show how to use the accounting method as well as a potential function to perform this amortized analysis.

\textbf{Requirements}
    \begin{enumerate}
        \item Describe how to implement the operation increment
        \item Show the amortized running time in only $O(1)$ (Assum the entries in A all start out at zero)
        \item Show how to use the accounting metheod as well as a potential function to perforem this amortized analysis.
    \end{enumerate}

\textbf{Analyze}

We store the digits of an n-bit binary number B to count the incrementing and store this number to an array A of length n. And this increment counter is initially 0. The only operation is $increment(A)$. The worst case running time occurs when all k bits are flipped to 1, so $increment(A)$ has running time $O(k)$. a sequence of n increment operations, few increments will cause that many bits to flip. Suppose we do $m$ increments, we choose $m = 9$ as an example.

\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|} %l(left)居左显示 r(right)居右显示 c居中显示
\hline
Incrementing(op\#) & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & ...\\
\hline
A & (0) & (1) &(1,0) & (1,1) & (1,0,0) & (1,0,1) & (1,1,0) & (1,1,1) &(1,0,0,0) & ...\\
Flipped Number & 0 & 1 & 2 & 1 & 3 & 1 & 2 & 1 & 4 & ... \\
Cumulative & 0 & 1 & 3 & 4 & 7 & 8 & 10 & 11 & 15 & ...\\
Total(Amortized) & 2 & 2 & 2 & 2 & 2 & 2 & 2 & 2 & 2 & ... \\
New Cumulative  & 2 & 4 & 6 & 8 & 10 & 12 & 14 & 16 & 18 & ...\\

\hline
\end{tabular}
\end{center}

In this case, the total costs is about 2m which average is 2 units per increment. Then the amortized cost per operation is O(1).

\textbf{Aggregate Method for k-increments:} K-increment for each bits:
    \begin{enumerate}
        \item bit 0 flips with every increment
        \item bit 1 flips with every $2^{nd}$ increments
        \item bit 2 flips with every $4^{th}$ increments
        \item So, the bit k flips with every $(2^k)^th$ increments
    \end{enumerate}
So the total number of bit flips in k increment operations is:

$Total\  op = k + k/2 + k/4 ...+ k/2^k = k*(1 + 1/2 + 1/4 + ... + 1/2^k) = 2k$

As a result, the total cost of the sequence is O(n), then the amortized cost per operation is $O(n) / n = O(1)$$.

\textbf{Accounting Method for k-bit:} The actual cost for an increment operation is the number of bits
flipped. We can assign an amortized cost of 2 for each increment operation. The main idea is to use 1 to flip the bit from 0 to 1 and store 1 credit to flip it back to 0 later. All changes from 1 to 0 are paid for with previously stored credit. The amortized time per operation is O(1).

\textbf{Potential Method:} Potential Function $C_i = number$ of 1s in counter after $i^{th}$ increment. We suppose $i^{th}$ operation resets $t_i$ bits to 0.

Actual cost: $c_i = t_i + 1$

Notice That: $C_i \leq C_{i-1} - t_i + 1$.
\begin{enumerate}
    \item If $C_i = 0, then \  C_{i-1} = t_i = k$.
    \item If $C_i > 0, then \ C_i = C_{i-1} - t_i + 1$.
\end{enumerate}

Difference in Potentials:

$C_i - C_{i-1} \leq (C_{i-1} - t_i + 1) - C_{i-1} = -t_i + 1$

As a result, add the actual cost, the amortized cost: $c_i + C_i - C_{i-1} \leq (t_i + 1) - t_i + 1 = 2$

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
% \textbf{Enumerating Permutations.} Consider a length-n array A = (1, 2, 3, . . . , n). We would like to step through all $n!$ permutations of A, updating the array as we go to represent each subsequent permutation. Permutations should be generated in lexicographic order; for example, with n = 3 we start with A = (1, 2, 3), then move to A = (1, 3, 2), A = (2, 1, 3), A = (2, 3, 1), A = (3, 1, 2), and finally A = (3, 2, 1). Please describe how to implement an operation next-perm with $O(1)$ amortized running time that modifies A to produce the next permutation in lexicographic order.Use a potential function in your analysis.
    % Write part of \alg{Quick-Sort($list, start, end$)}

\textbf{Requirements}
    \begin{enumerate}
        \item Describe how to implement an operation $next-perm$ with O(1) amortized running time that modifies A to produce the next permutation in lexicographic order.
        \item Use a potential function in the analysis.
    \end{enumerate}

\textbf{Analyze}

In order to find the next-perm base on the current number, we deal with this number from right to left. We difine the index i and j (i < j), for each index i, we want to find the first j which have $A[j] > A[i]$, swap A[i] with A[j] and reverse the A[i+1, ... n]. This operation will takes n - i + 1 times.

\begin{lstlisting}[language=C++]
vector<int>& nextPermutation(vector<int>& A) {
  unsigned len = A.size() - 1;
  // Find an element from the right to left.
  for (int i = len - 1; i >= 0; --i) {
    if (A[i + 1] > A[i]) {
      for (int j = len; j > i; --j) {
        if (A[j] > A[i]) {
          swap(A[j], A[i]);
          reverse(A.begin() + i + 1, A.end());
          return A;
        }
      }
    }
  }
  // If there are increate order from left to right.
  reverse(A.begin(), A.end());
  return A;
}
\end{lstlisting}

As the above code, there are a few steps to find the next permutation in lexicographic order.
\begin{enumerate}
    \item Find the largest index $i$ such that $A[i] < A[i+1]$. If no such index exists, this is the last permutation, then reverse the array A to the first permutation.
    \item Find the largest index $j$ in the $[i+1, len]$ such that $A[j] > A[i]$
    \item Swap $A[i] \  with \  A[j]$
    \item Reverse the sequence from $A[i+1]$ up to and including the final element $A[len]$
\end{enumerate}

\textbf{Potential Method:} Define the potential to be three times the length of the longest contiguously decreasing subsequence at the end of the sequence.

\begin{enumerate}
    \item The first step costs $n-k$ (unless we have the last permutation, in which case it costs n, but that can be handled separately, since it can occur at most once in a sequence of permutations.) and does not alter the potentaial.
    \item The seconde step costs $n-l \leq n-k$ (because k + 1 is a possible choice for l) and again does not affect the potential.
    \item  The fourth step costs n - k - 1 and replaces what was a decreasing sequence of length n - k by an ascending sequence of length n - k -but beware the fact that, with n-k = 1, the suffix has length 1 and thus can be viewed either as descending or as ascending. The potntial decreases from 3(n-k) down to 3, a decrease of 3(n-k-1). So fase, our total cost is at most 3(n-k)-1 and our decreasee in potential is 3(n-k-1), so the sum at most 2, a constant.
\end{enumerate}

The third step is the difficult one to analyze. It costs one unit of time (assuming the permutation is stored in an array), but its effect on the potential is difficult to assess. In almost all
cases, it has no effect at all. The definition of k is such that the numbers from k + 1 to n must
form a decreasing sequence; the exchange replaces the lth element, part of the decreasing suffix
sequence, with the smaller kth element, so that the new value in position l is still smaller than
the current (unchanged) (l −1)st element, but we also know that the kth element was larger than
the element at position l + 1, since that is part of the definition of l. However, in the case of
k = n− 1 and k + 1 = l = n, then the swap creates a 2-digit decreasing suffix (and the reversal
affects only the single last element and thus has no effect); that suffix could form the tail end of
a much longer (arbitrarily longer) decreasing sequence, so this step might cause an arbitrarily
large potential increase. Fortunately, each increase is matched by an equal decrease within one
step, since the potential equals 3 every other step. Thus the amortization works, but it is clearly
not any simpler than the direct analysis.

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
% \textbf{In-Place Matrix Transposition.} Suppose we store an $m*n$ matrix in row-major form as an array of length $N = m*n$ in which we list the elements of the matrix one row at a time from left to right. By taking the transpose of such a matrix, we convert it into column-major form - an array of length N listing the columns of the matrix one at a time, each one from top to bottom. Suppose the matrix is sufficiently large that we would like to permute its memory representation from row-major to column-major order in place (using only $O(1)$ extra storage beyond the memory that holds the matrix). Please describe and analyze an $O(N log N )$ algorithm for solving this problem. As a hint, try to design an approach modeled on the “domination radius” algorithm from lecture, noting that for each element in the matrix, you can easily determine the location to which it needs to move, as well as the location of the element that will replace it.

\textbf{Requirements}
    \begin{enumerate}
        \item Suppose the matrix is sufficiently large that we would like to permute its memory representation from row-major to column-major order in place(Space Complexity: $O(1)$).
        \item Use an $O(NlogN)$ algorithm for solving this problem.
        \item Try to design an approach modeled on the "domination radius" algorithm.
    \end{enumerate}

\textbf{Analyze}

We store an m*n matrix in row-major form as an array of length N=m*n. And transposite this matrix. There are some requirements for this question.
\begin{enumerate}
    \item Using only O(1) extra storage beyond the memory that hold the matrix.
    \item The algorithm time complexity: $O(Nlog N)$
\end{enumerate}

We use an matrix A as an example.  \\
\begin{figure}[h]
\centering
\includegraphics[scale=0.5]{images/1.png}
\end{figure}

In the above graph, small number at the right of the letter represent the index for the letter in the arrow. We can find the movement for this transposition.
\begin{lstlisting}
Index movement:
0 -> 0
1 -> 4 -> 2 -> 1
2 -> 1 -> 4 -> 2(Repetition)
3 -> 5 -> 6 -> 3
4 -> 2 -> 1 -> 4(Repetition)
5 -> 6 -> 3 -> 5(Repetition)
6 -> 3 -> 5 -> 6(Repetition)
7 -> 7
\end{lstlisting}
These index movement are 4 cycle. $0->0$,  $1 -> 4 -> 2 -> 1$, $3 -> 5 -> 6 -> 4$ and $7 -> 7$. After that, we need to think about how to find the cycle is repetition and how to calculate the precursor and successor element for the current element. \\

\textbf{Solution}

\textbf{How to know the cycle is not repetitive?}

It is easily to find whether this cycle is a repetitive cycle because we traverse this array for index 0 to N. So the first index for a new cycle which is not a repetitive one should be the lowest index in this cycle. As a result, the cycle is a repetitive cycle if there is a successor index is bigger than the first index in the cycle.
\begin{lstlisting}[language=C++]
void transpose(int *mtx, int m, int n) {
  for (int i = 0; i < m * n; ++i) {
    int next = getNext(i, m, n);
    while (next > i)  // Detect the repetitive cycle
      next = getNext(next, m, n);
    if (next == i)  // Deal with the new cycle
      movedata(mtx, i, m, n);
  }
}
\end{lstlisting}

\textbf{How to get the precursor ans successor index?}

If the index for a element in the array is $i$ before the transposition, then the row and colume is $[i/n, i\%n]$ in the matrix. After the transposition, it change to $[i\%n,i/n]$. So the new index in the array is $(i\%n)*m + i/n$. This is the successor index for the index $i$. \\

If the index for a element in the array is $j$ after the transposition, then the row and colume is $(i/m, i\%m)$ in the matrix. Before the transposition, it is to $[i\%m,i/m]$. So the precurrsor index in the array is $(i\%m)*n + i/m$. This is the precurrsor index for the index $i$.

\begin{lstlisting}[language=C++]
int getNext(int i, int m, int n) { return (i % n) * m + i / n; }
int getPre(int i, int m, int n) { return (i % m) * n + i / m; }
\end{lstlisting}

\textbf{How to move the elements in a new cycle?}

\begin{lstlisting}[language=C++]
void movedata(int *mtx, int i, int m, int n) {
  int temp = mtx[i];
  int cur = i;
  int pre = getPre(cur, m, n);
  while (pre != i) {
    mtx[cur] = mtx[pre];
    cur = pre;
    pre = getPre(cur, m, n);
  }
  mtx[cur] = temp;
}
\end{lstlisting}

This algorithm has time complexity: $O(n^2)$ and space complexity: $O(1)$. We can think about use the domination radius method to detect the cycle both left and right at the same time. Then we can reduce the time complexity to $O(n log n)$.

\begin{lstlisting}[language=C++]
void transpose(int *mtx, int m, int n) {
  for (int i = 0; i < m * n; ++i) {
    int pre = getPre(cur, m, n),  next = getNext(i, m, n);
    while(pre > i && next > i && pre!= next && getPre(m, n, pre) != next) {
      pre = getPre(m,n,pre);
      next = getNext(m,n,next);
    }
    if(pre < i || next < i) continue;
    movedata(mtx, i, m, n);
  }
}
\end{lstlisting}

\end{homeworkProblem}

\end{document}


\documentclass[11pt,a4paper,fleqn]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[colorlinks=true, citecolor=blue, linkcolor=blue, filecolor=blue,urlcolor=blue]{hyperref}
\hypersetup{
     colorlinks   = true,
     citecolor    = gray
}
\usepackage{wrapfig}

\usepackage{caption}
\captionsetup{format=plain, indent=5pt, font=footnotesize, labelfont=bf}

\setkomafont{disposition}{\scshape\bfseries}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{bbm}
\usepackage{mathtools}
% \usepackage{epsfig}
% \usepackage{grffile}
%\usepackage{times}
%\usepackage{babel}
\usepackage{tikz}
\usepackage{paralist}
\usepackage{color}
\usepackage[top=3cm, bottom=2.5cm, left=2.5cm, right=3cm]{geometry}
%\setlength{\mathindent}{1ex}

% PGF
\usepackage{pgfplots}
\usepackage{pgf}
\usepackage{siunitx}
\usepackage{xfrac}
\usepackage{calculator}
\usepackage{calculus}
\usepackage{eurosym}
%\sisetup{per-mode=fraction,%
%	fraction-function=\sfrac}

%\newcommand{\eur}[1]{\EUR{#1}\si{\per\kilo\meter}}
\pgfplotsset{
  compat=newest,
  every axis/.append style={small, minor tick num=3}
}

%\usepackage[backend=biber,style=alphabetic,url=false,doi=false]{biblatex}
%\addbibresource{sheet01_biber.bib}
% \addbibresource{/home/coroa/papers/refs.bib}

\newcommand{\id}{\mathbbm{1}}
\newcommand{\NN}{{\mathbbm{N}}}
\newcommand{\ZZ}{{\mathbbm{Z}}}
\newcommand{\RR}{{\mathbbm{R}}}
\newcommand{\CC}{{\mathbbm{C}}}
\renewcommand{\vec}[1]{{\boldsymbol{#1}}}

\renewcommand{\i}{\mathrm{i}}

\newcommand{\expect}[1]{\langle\,#1\,\rangle}
\newcommand{\e}[1]{\ensuremath{\,\mathrm{#1}}}

\renewcommand{\O}{\mc{O}}
\newcommand{\veps}{\varepsilon}
\newcommand{\ud}[1]{\textup{d}#1\,}

\newcommand{\unclear}[1]{\color{green}#1}
\newcommand{\problem}[1]{\color{red}#1}
\newcommand{\rd}[1]{\num[round-mode=places,round-precision=1]{#1}}

%\DeclareSIUnit{\euro}{\EUR}
\DeclareSIUnit{\dollar}{\$}
\newcommand{\eur}{\text{\EUR{}}}

\usepackage{palatino}
\usepackage{mathpazo}
\setlength\parindent{0pt}
\usepackage{xcolor}
\usepackage{framed}
\definecolor{shadecolor}{rgb}{.9,.9,.9}

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

\begin{flushright}
 \textbf{Energy System Modelling }\\
 {\small Karlsruhe Institute of Technology}\\
 {\small Institute for Automation and Applied Informatics}\\
 {\small Summer Term 2020}\\
\end{flushright}

 \vspace{-0.5em}
 \hrulefill
 \vspace{0.3em}

\begin{center}
 \textbf{\textsc{\Large Solutions III: Storage Optimisation}}\\
 \small Will be worked on in the exercise session on Thursday, 19 June 2020.\\[1.5em]
\end{center}

\vspace{-0.5em}
\hrulefill
\vspace{0.8em}

%=============== ======================================================
\paragraph{Problem III.1 (analytical) -- storage optimisation without losses}~\\
%=====================================================================

\begin{wrapfigure}[11]{r}{0pt}
 \begin{tikzpicture}
  \begin{axis}[
    domain=0:14, no markers, samples=200
    % xlabel = $x$, ylabel = $f(x)$
   ]
   \addplot+[dashed] {0.3 * (1 + 0.9 * sin(deg(2*pi*x/7)))}; \label{figref:w}
   \addplot+[densely dotted] {0.12*(1 + sin(deg(2*pi*x))}; \label{figref:s}
   \addplot+[solid] {1}; \label{figref:l}
  \end{axis}
 \end{tikzpicture}
 \caption{daily and multi-week variations of wind and solar power generation
	\(g^{N}_{w}(t)\)
	\autoref{figref:w} and \(g^{S}_{s}(t)\)
	\autoref{figref:s}, and a constant load (all in per-unit) \(L(t)\)
	\autoref{figref:l}.}
\label{fig:variations}
\end{wrapfigure}

Imagine a two-node Germany. The South can install solar panels with a capacity factor $c_s$ to cover its load $L^S$, while the North uses wind turbines that have a capacity factor $c_w$
to feed their load $L^N$. Figure \ref{fig:variations} shows approximations to the daily and multi-week variations of per-unit wind and solar power generation \(G^{N}_{w}(t)\) and \(G^{S}_{s}(t)\) and a constant load \(L^{N/S}(t)\):

\begin{align*}
 g_{w}^N(t) & = c_w(1+A_w \sin \omega_w t), \\
 g_{s}^S(t) & = c_s(1+A_s \sin \omega_s t), \\
L^{N/S}(t) & = A_{l}^{N/S}.
\end{align*}

The capacity factors and constants are
\begin{align*}
A_{l}^{N} & = 20 \si{\giga\watt}, & A_{l}^{S} & = 30 \si{\giga\watt},                                         \\
 c_w    & = 0.3,                & A_w     & = 0.9,                & \omega_w & = \frac{2\pi}{7 \text{d}}, \\
 c_s    & = 0.12,               & A_s     & = 1.0,                & \omega_s & = \frac{2\pi}{1 \text{d}}.
\end{align*}
\vspace{-0.3em}
For now, assume no power exchange between the regions and that the stores are lossless.

\begin{enumerate}[(a)]
 % (a)
 \begin{shaded}\item How much wind capacity $G^{N}_{w}$ must be installed in the North and solar capacity $G_s^S$ in the South so that on average generation matches demand?\end{shaded}

 In the North:

 $$\expect{L^N} = \expect{G^N_w \cdot g^N_w(t)}$$

 $$\Rightarrow \quad A^N_l = G^N_w\cdot c_w $$

 \DIVIDE{20}{0.3}\res

 $$\Rightarrow \quad G^N_w = \frac{A^N_l}{c_w} = \frac{20\si{\giga\watt}}{0.3} = \rd{\res}\si{\giga\watt}$$

 In the South:

 $$\expect{L^S} = \expect{G^S_s \cdot g^S_s(t)}$$

 $$\Rightarrow \quad A^S_l = G^S_s\cdot c_s $$

 \DIVIDE{30}{0.12}\res

 $$\Rightarrow \quad G^S_s = \frac{A^S_l}{c_s} = \frac{30\si{\giga\watt}}{0.12} = \rd{\res}\si{\giga\watt}$$

 % (b)
 \begin{shaded}\item For a system to work, generation must match demand not on average but at each location and each point in time. Storages are one way of ensuring this constraint with variable renewable generation. What is the amount of store and dispatch power capacity $G_{st,store}=\max(-\Delta(t))$ and $G_{st,dispatch} = \max \Delta(t)$ the storage units must have in the North and in the South to account for the mismatch $\Delta(t)=L(t)-G\cdot g(t)$?\end{shaded}

 In the North:

 \begin{align*}
  G_{s,storage,dispatch}^N & = \max ( \pm \Delta^N(t))                                                              \\
                           & = \max (\pm [L^N(t) - G^N_w \cdot g^N_w(t)])                                    \\
                           & = \max (\pm [L^N(t) - \frac{A^N_l}{c_w}\cdot c_w\cdot (1+A_w \sin \omega_w t)]) \\
                           & = \max (\pm [L^N(t) - A^N_l - A^N_l A_w \sin \omega_w t)])                      \\
                           & = \max (\pm [-A^N_l A_w \sin \omega_w t)])                                         \\
                           & = A^N_l A_w = 0.9 \cdot 20 \si{\giga\watt} = 18 \si{\giga\watt}
 \end{align*}

 In the South:

 \begin{align*}
  G_{s,storage,dispatch}^S & = \max ( \pm \Delta^S(t))                                                              \\
                           & = \max (\pm [L^S(t) - G^S_s \cdot g^S_s(t)])                             \\
                           & = \max (\pm [L^S(t) - \frac{A^S_l}{c_s}\cdot c_s\cdot (1+A_s \sin \omega_s t)]) \\
                           & = \max (\pm [L^S(t) - A^S_l + A^S_l A_s \sin \omega_s t)])                      \\
                           & = \max (\pm [A^S_l A_s \sin \omega_s t)])                                         \\
                           & = A^S_l A_s = 1.0 \cdot 30 \si{\giga\watt} = 30 \si{\giga\watt}
 \end{align*}

 % (c)
 \begin{shaded}\item What is the amount of energy capacity $E_{st}$ one needs for either storage in the North and in the South? The energy capacity is given by

 	\begin{equation*}
 	E_{st} = \max_t e_{st}(t) = \max_t \int_{0}^{t} -\Delta(t') \;\mathrm{d}t'
 	\end{equation*}

 \end{shaded}

 In the North:

 \begin{align*}
  e_{st}^N(t) & = \int_{0}^{t} -\Delta^N(t') \;\mathrm{d}t' = \int_{0}^{t} A^N_l A_w \sin \omega_w t' \;\mathrm{d}t'           \\
           & = A^N_l A_w \frac{-\cos(\omega_w t')}{\omega_w}\Big|_0^t = A^N_l A_w \frac{1-\cos(\omega_w t')}{\omega_w}
 \end{align*}

 \begin{equation*}
  E_{st}^N = \max_t e_{st}(t) = \frac{2A^N_lA_w}{\omega_w} = \frac{2\cdot 20 \si{\giga\watt}\cdot 0.9}{2\pi} \cdot 7\cdot 24 \si{\hour} = 1 \si{\tera\watt\hour}
 \end{equation*}

 In the South:

 \begin{align*}
  e_{st}^S(t) & = \int_{0}^{t} -\Delta^S(t') \;\mathrm{d}t' = \int_{0}^{t} A^S_l A_s \sin \omega_s t' \;\mathrm{d}t'           \\
           & = A^S_l A_s \frac{-\cos(\omega_s t')}{\omega_s}\Big|_0^t = A^S_l A_s \frac{1-\cos(\omega_s t')}{\omega_s}
 \end{align*}

 \begin{equation*}
  E_{st}^S = \max_t e_{st}(t) = \frac{2A^S_lA_s}{\omega_s} = \frac{2\cdot 30 \si{\giga\watt}\cdot 1}{2\pi} \cdot 24 \si{\hour} = 230 \si{\giga\watt\hour}
 \end{equation*}

 % (d)
 \begin{shaded}\item Should they choose hydrogen or battery storages? And how much would it cost them? Is the South or the North paying more for their energy? Disregard losses!\end{shaded}

 \textbf{In the North:}

 The cost of renewable generation in the North is

 $$P_w^N=G^N_w \cdot 1200 \text{\EUR{}}\si{\per\kilo\watt}=80\cdot10^9\text{\EUR{}} $$

 The minimal (lossless) corresponding cost to supply constant demand by using hydrogen as storage technology are

 \begin{align*}
  P_h^N & = 750 \text{\EUR{}}\si{\per\kilo\watt} \cdot G_{storage,dispatch}^N + 10 \text{\EUR{}}/\text{kWh} \cdot E_{st}^N \\
        & = 13.5 \cdot 10^9 \eur + 10 \cdot 10^9 \eur                                                                                \\
        & = 23.5 \cdot 10^9 \eur
 \end{align*}

 The minimal (lossless) corresponding cost to supply constant demand by using batteries as storage technology are:

 \begin{align*}
  P_b^N & = 300 \text{\EUR{}}\si{\per\kilo\watt} \cdot G_{storage,dispatch}^N + 200 \text{\EUR{}/kWh} \cdot E_{st}^N \\
        & = 5.4 \cdot 10^9 \eur + 200 \cdot 10^9 \eur                                                                                \\
        & = 205.4 \cdot 10^9 \eur
 \end{align*}

 The minimal (lossless) total system cost using hydrogen storages accumulates to

 $$P_{w+h}^N = P_w^N + P_h^N = 104 \cdot 10^9\eur$$

 whereas the system cost using batteries are

 $$P_{w+b}^N = P_w^N + P_b^N = 285 \cdot 10^9\eur$$

 Thus, the North should choose hydrogen storages.\\~\\

 \textbf{In the South:}

 The cost of renewable generation in the South is

 $$P_s^S=G^S_s \cdot 600 \text{\EUR{}}\si{\per\kilo\watt}=150\cdot10^9\text{\EUR{}} $$

 The minimal (lossless) corresponding cost to supply constant demand by using hydrogen as storage technology are

 \begin{align*}
  P_h^S & = 750 \text{\EUR{}}\si{\per\kilo\watt} \cdot G_{storage,dispatch}^S + 10 \text{\EUR{}/kWh} \cdot E_{st}^S \\
        & = 22.5 \cdot 10^9 \eur + 2.3 \cdot 10^9 \eur                                                                                \\
        & = 24.8 \cdot 10^9 \eur
 \end{align*}

 The minimal (lossless) corresponding cost to supply constant demand by using batteries as storage technology are:

 \begin{align*}
  P_b^S & = 300 \text{\EUR{}}\si{\per\kilo\watt} \cdot G_{storage,dispatch}^S + 200 \text{\EUR{}/kWh} \cdot E_{st}^S \\
        & = 9 \cdot 10^9 \eur + 46 \cdot 10^9 \eur                                                                                \\
        & = 54 \cdot 10^9 \eur
 \end{align*}

 The minimal (lossless) total system cost using hydrogen storages accumulates to

 $$P_{s+h}^S = P_s^S + P_h^S = 175 \cdot 10^9\eur$$

 whereas the system cost using batteries are

 $$P_{s+b}^S = P_s^S + P_b^S = 204 \cdot 10^9\eur$$

 Thus, the South should also choose hydrogen storages.\\~\\

 \textbf{Cost comparison between North and South:}

 Without taking losses into account, both regions should choose hydrogen storages. Overall, the North can provide electricity at a lower rate than the South:

 $$P^N = \frac{104 \cdot 10^9 \eur}{20 \si{\giga\watt}} = 5 \cdot 10^9 \eur \si{\per\giga\watt}$$

 $$P^S = \frac{175 \cdot 10^9 \eur}{30 \si{\giga\watt}} = 6 \cdot 10^9 \eur \si{\per\giga\watt}$$

 Note that we can consider energy as $\si{\giga\watt}$ as we have a constant load! Otherwise, we would have to pay more attention!

 % (e)
\begin{shaded}\item Now we lift the restriction against transmission and allow the two regions to bridge their 500 km separation with a transmission line. Estimate the cost-optimal technology mix by assuming wind energy in the North is only stored in the North and solar energy in the South is likewise only stored in the South! What would happen if you dropped that assumption?\end{shaded}

Because $P_{w+h}^N < P_{w+h}^S$ there will be energy exports from North to South:

$$E^N > E^S \quad \text{and} \quad E^N + E^S = 50 \si{\giga\watt}$$

Note that we can consider energy as $\si{\giga\watt}$ as we have a constant load! Otherwise, we would have to pay more attention!

The total price of electricity is given by

\begin{align*}
P_{tot} & =\frac{ E^N \cdot P_{w+h}^N + E^S \cdot P_{s+h}^S + (E^N - E^S)\cdot 200 \eur\si{\per\kilo\watt}}{E^N + E^S}                                           \\
& = \frac{E^N \cdot P_{w+h}^N + (50\si{\giga\watt} - E^N) \cdot P_{s+h}^S + (2E^N - 50\si{\giga\watt})\cdot 200 \eur\si{\per\kilo\watt}}{E^N + E^S}      \\
& = \frac{E^N (P_{w+h}^N - P_{s+h}^S + 400 \eur \si{\per\kilo\watt}) + 50 \si{\giga\watt} (P_{s+h}^S - 200 \eur \si{\per\kilo\watt})}{E^N + E^S} \\
\end{align*}

Now, minimising the term for a choice of $E^N$ and filling in the costs calculated in the preceding tasks will yield

\begin{align*}
E^N & = 50 \si{\giga\watt}
\end{align*}

such that all power would be produced from wind in the North. This is because the term $(P_{w+h}^N - P_{s+h}^S + 400 \eur \si{\per\kilo\watt})$ is negative. The resulting total system cost is

\begin{align*}
\min P_{tot} & = \frac{-0.6 \cdot 50 \cdot 10^9 \eur + 5.8 \cdot 50 \cdot 10^9 \eur}{50 \si{\giga\watt}}  \\
& = \frac{260 \cdot 10^9 \eur}{50 \si{\giga\watt}} = 5.2 \cdot 10^9 \eur \si{\per\giga\watt}
\end{align*}

Compared to the weighted electricity cost of North and South without transmission

\begin{align*}
\min P_{tot} & = \frac{20\si{\giga\watt}\cdot 5 \cdot 10^9 \eur \si{\per\giga\watt} + 30\si{\giga\watt}\cdot 6 \cdot 10^9 \eur \si{\per\giga\watt}}{50 \si{\giga\watt}} \\
& = \frac{280 \cdot 10^9 \eur}{50 \si{\giga\watt}} = 5.6 \cdot 10^9 \eur \si{\per\giga\watt}
\end{align*}

the system cost could be reduced by approx.\ 7 \%.

 % (f)
  \begin{shaded}
 	\item What do you imagine would change if you considered the storage losses given in Table 1 in your results (a)-(d)?
 \end{shaded}

 To compensate for the energy losses wind and solar capacity $G_{w/s}$, store and dispatch power capacities $G_{storage,dispatch}$ and storage energy capacities $E_{st}$ have to increase. Since hydrogen storage has lower efficiencies than batteries, the optimal choice (particularly in the South) might change. You can prove that by taking into account the losses in your preceding calculations. The calculations including losses are uploaded in a seperate file.

\end{enumerate}

\end{document}


\documentclass[10pt]{report}

\usepackage{listings} % for code
\lstset
{
	language=Matlab,
	frame=single,
	basicstyle=\footnotesize,
	numbers=left,
	stepnumber=1,
	showstringspaces=false,
	tabsize=1,
	breaklines=true,
	breakatwhitespace=false,
}

\usepackage{siunitx} % for scientific notation
% for `e' in scientific notation
\sisetup{output-exponent-marker=\ensuremath{\mathrm{e}}}

\usepackage{float} % for figure [H]
\usepackage{booktabs} % for tabular
\usepackage{caption} % for \caption*
\usepackage[export]{adjustbox} % for valign=t
\usepackage{array} % for column type m
\usepackage{verbatim}
\usepackage{graphicx}
\graphicspath{ {imgs/} }
\usepackage{fancyhdr}
\usepackage{amssymb}
\usepackage{amsmath}

%%%%%% Pagination
\setlength{\topmargin}{-.3 in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\textheight}{9.in}
\setlength{\textwidth}{6.5in}

%Title page
\newcommand{\hwTitle}{Homework \#1}
\newcommand{\hwCourse}{Introduction to Computational Mathematics}
\newcommand{\hmwkClassInstructor}{Professor Shuwang Li}

\title{
	\vspace{2in}
	\textmd{\textbf{\hwCourse\\\hwTitle}}\\
	\vspace{0.3in}\large{\textit{\hmwkClassInstructor}}
	\vspace{3in}
}

%\title{Homework 1}
\author{\textbf{Zhihao Ai}}
\date{}

%Header setting.
\pagestyle{fancy}
\fancyhead[L]{Zhihao Ai}
\fancyhead[C]{Math 350: Introduction to Computational Mathematics}
\fancyhead[R]{Homework 1}
%%%%%%

%\displaystyle apply to all
\everymath{\displaystyle}

%Custom commands.
\newcommand{\ds}{\displaystyle}
\newcommand{\eva}[2] {\left. #1 \right|_{#2}}
\newcommand{\dintt}[4] {\int_{#1}^{#2} #3 d#4}

\newcolumntype{C}{ >{\centering\arraybackslash} m{3em} }
\newcolumntype{D}{ >{\centering\arraybackslash} m{4em} }

\newcommand{\abs}[1] {\left| #1 \right|}

\begin{document}

\maketitle

\section*{Part 1. Reading Assignment}
\textbf{Read http://ta.twi.tudelft.nl/users/vuik/wi211/disasters.html. Write a short essay on your understanding of numerical errors, as a future scientist.}
%\newline
\\
There were many disasters caused by a variety of reasons in the human history, but many of them were easy to be detected due to their obviousness, thus easy to be resolved. However, numerical errors are often emerging in a subtle way that is difficult for us to notice, and after many calculations, the loss of accuracy grows into huge problems which cost us not only money, but priceless human lives.

Typically, numerical errors occur because of the way how computers represent numbers, especially floating point numbers. For example, the registers of the Patriot computer were only 24 bits long, then any conversion beyond the finite real numbers the computer can represent would cause a loss of precision, leading to inaccuracy of the following calculations, which finally caused an American Army barracks being struck and 28 soldiers being killed. Similar problem with accuracy of conversion happened with the Ariane 5 and the Sleipner, which caused the explosion of the rocket and the sinking of the offshore platform respectively.

In the meantime, other common forms of numerical errors, like truncation error and rounding error, also had many negative impacts on the human activities. The conversion errors, reconversion errors and totalizing errors in the Euro’s case and the truncation errors in the Vancouver Stock Exchange’s case clearly demonstrate such financial influences. In addition, the rounding errors that changed a German Parliament makeup also showed an interesting political effect they could have.

In conclusion, the numerical errors appear because of inaccuracy of computation, both by computers and human beings. Even though they are quite small to be detected, we as the future scientists, should be fully aware of them, and trying our best to solve them in order to benefit the world.

\section*{Part 2. Fundamental concepts/ideas}
\begin{enumerate}
	\item
	Compute the absolute error and relative error in approximation of $x$ by $x^*$.
	\begin{enumerate}
		\item
		\(
		x=\pi, x^*=3.1416
		\)
		\\
		\(
		e_{abs}
		= \abs{x - x^*}
		= \abs{\pi - 3.1416}
		\approx 7.3464\times 10^{-6}
		\\
		e_{rel}
		= \abs{\frac{x - x^*}{x}}
		= \abs{\frac{\pi - 3.1416}{\pi}}
		\approx 2.3384\times 10^{-6}
		\)

		\item
		\(
		x=\pi, x^*=22/7
		\)
		\\
		\(
		e_{abs}
		= \abs{x - x^*}
		= \abs{\pi - 22/7}
		\approx 1.2645\times 10^{-3}
		\\
		e_{rel}
		= \abs{\frac{x - x^*}{x}}
		= \abs{\frac{\pi - 22/7}{\pi}}
		\approx 4.025\times 10^{-4}
		\)
	\end{enumerate}
	\textit{Things learned:} Absolute error measures the difference between an exact value and the approximation of it. Relative error measures the proportion of absolute error to the exact value. Both errors are nonnegative. Using $3.1416$ to approximate $\pi$ results in both absolute error and relative error of which the order of magnitude is $-6$. But using $22/7$ to approximate $\pi$ results in an absolute error of which the order of magnitude is $-3$ and a relative error of which the order of magnitude is $-4$. It's better to use $3.1416$ than $22/7$ as an approximation for $\pi$.

	\item
	The Maclaurin series for the arctangent function converges for $-1 < x \le 1$ and is given by
	\[
	\arctan{x}
	= \lim\limits_{n\to \infty} P_n(x)
	= \lim\limits_{n\to \infty} \sum_{i=1}^{n} (-1)^{i+1} \frac{x^{2i-1}}{2i-1}
	\]
	\begin{enumerate}
		\item
		Use the fact that $\tan{\pi / 4} = 1$ to determine the number of $n$ terms of the series that need to be summed to ensure that $\abs{4P_n(1)-\pi}<10^{-3}$.
		\\
		Since $P_n(x)$ consists of an alternating series whose term is decreasing in magnitude,
		\[
		\abs{\lim\limits_{n\to \infty} P_n(x) - P_n(x)} \le \abs{a_{n+1}}
		\]
		where $a_n$ is the $n$-th term of the series. Also because $\tan{\frac{\pi}{4}} = 1$,
		\[
		\lim\limits_{n\to \infty} P_n(1) = \arctan{1} = \frac{\pi}{4}
		\]
		Therefore,
		\[
		\abs{4P_n(1) - \pi}
		\le 4\abs{a_{n+1}}
		= 4\abs{(-1)^{n+1} \frac{1^{2n+1}}{2n+1}}
		= \frac{4}{2n+1}
		< 10^{-3}
		\]
		can be satisfied if $n > 1999.5$. So, at least 2000 terms of the series are needed to be summed to ensure that $\abs{4P_n(1) - \pi} < 10^{-3}$.

		\item
		Suppose Matlab require the value of $\pi$ to be within $10^{-10}$, how many terms of the series would we need to sum to obtain this degree of accuracy?
		\\
		\[
		\abs{4P_n(1) - \pi}
		\le 4\abs{a_{n+1}}
		= 4\abs{(-1)^{n+1} \frac{1^{2n+1}}{2n+1}}
		= \frac{4}{2n+1}
		< 10^{-10}
		\]
		Therefore, $n = 2\times 10^{10}$ is the minimum number of terms needed.

		\item
		This is not an efficient way to evaluate the value of $\pi$. The method can be improved significantly by observing that $ \pi /4 = \arctan 1/2 + \arctan 1/3$ and evaluating the series for the arctangent at $1/2$ and $1/3$. Determine the number of terms that must be summed to ensure an approximation to $\pi$ to within $10^{-3}$.
		\\
		Since $\pi/4 = \arctan 1/2 + \arctan 1/3$, denoting $a_n$ and $b_n$ as the $n$-th term of the series of $P_n\left(\frac{1}{2}\right)$ and $P_n\left(\frac{1}{3}\right)$ respectively and we have
		\begin{equation*}
		\begin{split}
		\abs{4\left[P_n\left(\frac{1}{2}\right) + P_n\left(\frac{1}{3}\right)\right] - \pi}
		\le 4\abs{a_{n+1} + b_{n+1}}
		&= 4\abs{(-1)^{n+1} \frac{(\frac{1}{2})^{2n+1}}{2n+1} + (-1)^{n+1} \frac{(\frac{1}{3})^{2n+1}}{2n+1}} \\
		&= 4\cdot \frac{(\frac{1}{2})^{2n+1} + (\frac{1}{3})^{2n+1}}{2n+1}
		< 10^{-3}
		\end{split}
		\end{equation*}
		Therefore, $n = 4$ terms must be summed.
	\end{enumerate}
	\textit{Things learned:} If $\abs{a_n}$ is approaching 0 monotonically, the difference between infinite sum and partial sum is bounded by a single term. The fact that $\tan{\pi/4}=1$ can be used combined with property of alternating series to approximate $\pi$. Even for error within $10^{-3}$, thousands of terms are needed to be calculated. To approximate $\pi$ using the first series requires a huge number of calculations. The Taylor series of $\arctan{1}$ converges much slower than the that of $\arctan{1/2}$ and $\arctan{1/3}$. By applying $\pi/4=\arctan{1/2}+\arctan{1/3}$, number of calculations can be dramatically decreased.

	\item
	Consider integral $I_n = \dintt{0}{1}{\frac{x^n}{x+5}}{x}, n=0,1,2,\dots,20$.
	\begin{enumerate}
		\item
		Establish the recursive relation between $I_n$ and $I_{n-1}$ with $I_0 = \ln 6 - \ln 5$.
		\\
		\[
		I_n+5I_{n-1}
		= \dintt{0}{1}{\frac{x^n}{x+5}}{x} + 5\dintt{0}{1}{\frac{x^{n-1}}{x+5}}{x}
		= \dintt{0}{1}{\frac{x^n+5x^{n-1}}{x+5}}{x}
		= \dintt{0}{1}{x^{n-1}}{x}
		= \frac{1}{n}
		\]
		Therefore,
		\[
		I_n = \begin{cases}
		\ln{6} - \ln{5}, &n=0\\
		\frac{1}{n} - 5I_{n-1}, &n=1,2,\dots,20
		\end{cases}
		\]

		\item
		Establish the recursive relation between $e_n$ and $e_{n-1}$. Suppose an error $e_0$ is introduced initially in the computation of $I_0$.
		\\
		Since $e_0$ is introduced initially in the computation of $I_0$,
		\[
		I_0^* = I_0 + e_0
		\]
		Then for the $n$-th term,
		\[
		e_n^*
		= I_n^* - I_n
		= \frac{1}{n} - 5I_{n-1}^* - \frac{1}{n} + 5I_{n-1}
		= 5(I_{n-1} - I_{n-1}^*)
		= -5e_{n-1}
		\]
		Therefore,
		\[
		e_n = \begin{cases}
		e_0, &n=0\\
		-5e_{n-1}, &n=1,2,\dots,20
		\end{cases}
		\]

		\item
		How is $e_0$ amplified at the $n$-th step? Is this algorithm numerically stable?
		\\
		According to the recursive relation in part (b), $e_n = (-5)^n\cdot e_0$. If $n$ is large enough, the error $e_n$ would also be large; hence the algorithm is unstable.
	\end{enumerate}
	\textit{Things learned:} A little manipulation of $I_n$ can lead to $I_n+5I_{n-1}=1/n$. The error introduced, even small at first, grows exponentially in this case. A small error can make an algorithm numerically unstable.
\end{enumerate}

\section*{Part 3. Computer assignments}
\begin{enumerate}
	\item
	Problem 1.39 @Page 49
	\begin{enumerate}
		\item
		What causes the while loop to terminate?
		\\
		When the result of \texttt{s+t} cannot be rounded to a number different from \texttt{s} that can be represented in Matlab, \texttt{s+t\~{}=s} returns false and terminates the loop. For example, for a positive \texttt{t}, if the rounded result of \texttt{s+t} is less than \texttt{s+eps(s)}, then \texttt{s+t} would actually yields \texttt{s}, not \texttt{s+t}; for a negative \texttt{t}, if the rounded result of \texttt{s+t} is less than the adjacent smaller number to \texttt{s}, \texttt{s+t} would also yields \texttt{s}.

		\item
		Answer the following questions for $x = \pi/2, 11\pi/2, 21\pi/2$, and $31\pi/2$.
		\\
		The code provided in the problem is revised as follows to output more information:
		\lstinputlisting{powersin_aug.m}

		Then a function for different values of $x$:
		\lstinputlisting{hw1p1.m}

		Running \lstinline|x=[pi/2, 11*pi/2, 21*pi/2, 31*pi/2]; hw1p1(x);|  produces the results below:
		\begin{table}[H]
			\centering
			\begin{tabular}{cccccc} \toprule
				$x$ & $\sin x$&Computed Result & Number of Terms & Largest Term & Error\\ \midrule
				$\pi/2$ & $1$ & $1.0000$ & $21$ & $1.5708$ & \num{2.2204e-16} \\
				$11\pi/2$ & $-1$ & $-1.0000$ & $73$ & \num{3.0665e+06} & \num{2.1287e-10} \\
				$21\pi/2$ & $1$ & $0.9999$ & $119$ & \num{1.4673e+13} & \num{1.3324e-04} \\
				$31\pi/2$ & $-1$ & \num{-5.8220e+03} & $155$ & \num{7.9890e+19} & \num{5.8210e+03} \\
				\bottomrule
			\end{tabular}
		\end{table}

		\begin{enumerate}
			\item
			How accurate is the computed result?
			\\
			The computed results are relatively accurate for $\pi/2$ and $11\pi/2$. But the error increases as $x$ increases and for $x = 31\pi/2$ the error is unacceptable.

			\item
			How many terms are required?
			\\
			If the zero terms are counted as well, the number of terms required is 21, 73, 119 and 155 for $x = \pi/2, 11\pi/2, 21\pi/2$, and $31\pi/2$ respectively.

			\item
			What is the largest term in the series?
			\\
			The largest term is 1.5708, \num{3.0665e6}, \num{1.4673e13} and \num{7.9890e19} for $x = \pi/2, 11\pi/2, 21\pi/2$, and $31\pi/2$ respectively.
		\end{enumerate}

		\item
		What do you conclude about the use of floating-point arithmetic and power series to evaluate functions?
		\\
		It's probably a bad idea to do that if the power series converge slowly enough for the errors introduced due to floating-point arithmetic to grow into a notable inaccuracy.
	\end{enumerate}
	\textit{Things learned:} Numbers a computer can represent is finite. \texttt{eps(x)} can be used to get the distance of \texttt{x} to the closest number larger than \texttt{x}. When an operant is small enough, a calculation may turn out not as expected. The result of a calculation is rounded to the nearest representable number. Using power series to approximate $\sin$ is not quite preferable due to floating-point arithmetic. The power series of $\sin$ may consists of really large number which affects the precision.

	\item
	Consider a recurrence formula: $a_{k+2} = 10a_{k+1} - 9a_k$ with
	\begin{enumerate}
		\item [1.]
		$a_2 = a_1 = 3.75$
		\item [2.]
		$a_2 = a_1 = 3.775$
	\end{enumerate}
	For us, the solution is always $a_k = a_1$ for any positive integer $k$. However, for a computer (a machine with finite precision), things may change due to round-off error.
	\begin{enumerate}
		\item
		Write a short Matlab script and calculate $a_k$ up to 20 iterations, i.e., k =1,2,\dots,19, for the two cases.
		\lstinputlisting{recurrence.m}

		\item
		Demonstrate the catastrophic round-off error using a table showing the digit loss.

		\begin{table}[H]
			\centering
			\begin{tabular}{ccc} \toprule
				Index $i$ & $a_i$ with $a_1=3.75$ & $a_i$ with $a_1=3.775$ \\ \midrule
				1  & 3.750000 & 3.775000 \\
				2  & 3.750000 & 3.775000 \\
				3  & 3.750000 & 3.775000 \\
				4  & 3.750000 & 3.775000 \\
				5  & 3.750000 & 3.775000 \\
				6  & 3.750000 & 3.775000 \\
				7  & 3.750000 & 3.775000 \\
				8  & 3.750000 & 3.775000 \\
				9  & 3.750000 & 3.775000 \\
				10 & 3.750000 & 3.775000 \\
				11 & 3.750000 & 3.775000 \\
				12 & 3.750000 & 3.774999 \\
				13 & 3.750000 & 3.774994 \\
				14 & 3.750000 & 3.774944 \\
				15 & 3.750000 & 3.774498 \\
				16 & 3.750000 & 3.770485 \\
				17 & 3.750000 & 3.734363 \\
				18 & 3.750000 & 3.409264 \\
				19 & 3.750000 & 0.483375 \\
				\bottomrule
			\end{tabular}
		\end{table}

		\item
		Explain why case 1 and 2 behave differently.
		\\
		Since $3.75_{10} = 11.11_{2}$, there is no round-off error introduced in the algorithm. But $3.775_{10} = 11.110\overline{0011}_{2}$ can only be stored by rounding to the nearest number Matlab can represent, thus introducing a round-off error. After certain times of calculations, the error accumulates and causes the issue above.
	\end{enumerate}

	\item
	Write a Matlab routine using Horner's algorithm to evaluate the value of polynomial
	\[
	p(x) = 6x^5 + 5x^4 +4x^3 + 3x^2 +2x+1 \quad \text{at} \quad x=5
	\]
	\lstinputlisting{horner.m}
	outputs \lstinline|ans = 22461|.
\end{enumerate}

\end{document}


\documentclass[main.tex]{subfiles}
\begin{document}

\subsection{Neutral current interactions}

\marginpar{Tuesday\\ 2020-4-28, \\ compiled \\ \today}

We have introduced a term in our model which yields an important and testable prediction: the existence of a weak \emph{neutral} current in addition to the charged ones.
Let us make some simple examples for the three types of currents we have: the charged current with the \(W^{\pm}\) bosons mediates interactions like
%
\begin{align}
\nu_{L} + d_L \to e^{-}_{L} + u_L
\,,
\end{align}
%
the electromagnetic current \(A_{\mu }\) and the neutral current \(Z^{0}_{\mu }\) mediate interactions like
%
\begin{align}
e^{-}_{L} + u_L \to e^{-}_{L} + u_L
\,,
\end{align}
%
however there is a distinction to be made: the electromagnetic current can only be coupled to charged particles, so a process like
%
\begin{align}
\nu_{L} + u_L \to \nu_{L} + u_L
\,
\end{align}
%
can only be mediated by the \(Z^{0}\) boson, since the neutrino is neutral!
This kind of interaction has been experimentally observed!

\todo[inline]{So, there are certain processes which can be mediated by both the \(Z^{0}\) boson and the photon. Does this mean that people needed to revise their estimate of the electromagnetic coupling, since electromagnetism was not the only contributor to those scatterings?}

\section{The Standard Model of particle physics}

The Lagrangian reads:
%
\boxalign{
\begin{align}
\mathscr{L} = - \frac{1}{4} F_{\mu \nu } F^{\mu \nu }
+ i \overline{\psi} \slashed{\DD} \psi
+ \psi_{i} y_{ij} \psi_{j} \phi
+ \text{h.\ c.}
+\abs{\DD_{\mu } \phi }^2 - V(\phi )
\,.
\end{align}}

Let us unpack the terms:
\begin{enumerate}
    \item \(F_{\mu \nu } F^{\mu \nu }\) encompasses the kinetic and self-interaction terms of all the interaction bosons (photon, \(W^{\pm}\), \(Z^{0}\), gluons);
    \item \(i \overline{\psi} \slashed{\DD} \psi \) encompasses all the kinetic terms of the fermions (\(\overline{\psi} \gamma^{\mu } \partial_{\mu } \psi  \)) and the interaction terms between the fermions and the gauge bosons: \(g \overline{\psi} \gamma^{\mu }A_{\mu } \psi \);
    \item \(\psi_{i} y_{ij} \psi_{j} \phi \) is the interaction between the Higgs field and the fermions, which gives mass to the fermions and which we will discuss in the next section;
    \item \(\abs{\DD_{\mu } \phi }^2\) is the kinetic term of the scalar (Higgs) field \(\phi \), also including the interactions between it and the vector bosons;
    \item \(V(\phi )\) is the potential for the scalar field, it must be at least quartic.
\end{enumerate}

``h.\ c.'' means Hermitian Conjugate, it is needed in order to ensure that everything is self-adjoint.

The symmetry which determines this theory is
%
\begin{align}
\text{Lorentz} \otimes
SU(3)_{c}  \otimes
SU(2)_{L} \otimes
U(1)_{Y}
\,.
\end{align}

Starting from the symmetry, the only other prescription needed are the quantum numbers of the various particles: we can make a table.
As we have seen, the fermions are divided into left-handed isospin doublets and right-handed singlets.

\begin{figure}[H]
\centering
\begin{tabular}{rcccc}
& Name & \(T_3\) (SU(2)) & \(Y\) & \(Q\) \\
\cline{2-5}
\ldelim\{{4}{*}[Leptons (no \(SU(3)\) charge)] &
\(\nu_{L}\) & \(+ 1 / 2\) & \(- 1/ 2\) & 0  \\
& \(e^{-}\) & \(- 1/ 2\) & \(- 1/ 2\) & \(-1\)  \\
& \(\cancelto{}{\nu_{R}}\) & 0 & 0 & 0 \\
& \(e^{-}_{R}\) & 0 & \(-1\) & \(-1\) \\
 \\
\ldelim\{{2}{*}[Higgs scalar] &
\(\phi^{+}\) & \(+1 / 2\) & \(+ 1/2\) &  \(+1\) \\
&\(\phi^{0}\) & \(-1 / 2\) & \(+1 /2 \) & \(0\) \\
 \\
\ldelim\{{4}{*}[Quarks (\(SU(3)_c\) triplets)] &
\(u_L\) & \(+ 1/ 2\) & \(1 / 6\) & \( 2 / 3\) \\
& \(d_L\)& \(- 1/ 2\) & \(1 / 6\) & \(- 1/ 3\) \\
& \(u_R\)& \(0\) & \(2/3\) & \(2/ 3\) \\
& \(d_R\)& \(0\) & \(- 1/3\) & \(- 1/ 3\)
\end{tabular}
\label{tab:particles}
\caption{Particles}
\end{figure}

Here we write only one of the generations for both leptons and quarks.
The quantum numbers for the other generations are the same.
An unanswered question is \emph{why} exactly there are three families.

We are always computing the electric charge as \(Q = T_3 + Y\), where \(T_3\) is the generator of \(SU(2)_L\) rotations around the \(\hat{3}\) axis.
Sometimes we write ``1'' for the right-handed quarks under \(T_3 \), this is not the eigenvalue but it is used to mean ``singlet''.

For the \(SU(3)\) we have 8 generators (corresponding to the gluons), for \(SU(2)\) we have three generators, for \(U(1)\) we only have 1 generator: these four, after SSB, are three massive bosons and the photon.

The assignment of the charges cannot come from the symmetry, it must be determined experimentally.

The right-handed neutrino does not appear here: it should be invariant under any gauge transformation. This would then be the \emph{sterile} neutrino: it would not interact with matter by any of the forces of the Standard Model.

It makes sense not to include it \emph{a priori} then, however we can keep it in mind: it is a DM candidate.

Can we say anything about its possible mass? There are schemes in which the RH neutrino enters, and in which it can be assigned a mass. However, in general this is a free parameter: in some contexts we can give it a specific value, but we cannot say anything about its mass from basic Standard Model theory.

There are experiments at Fermilab which could point indirectly at their existence.

The rule is always:
\begin{quote}
    \emph{Write all the terms in your Lagrangian which are invariant under your symmetry and which have dimension \( 4\).}
\end{quote}

Should we not include also some prescription for the couplings?
No, this is included in the symmetry: if we have the coupling constants \(g_S\), \(g\) (weak) and \(g'\) (hypercharge) we can determine everything else.

The issue is that, before including the Higgs boson, everything is massless.

Gluons and quarks have the same ``destiny'': there is confinement when \(g_S\) becomes large.

% The \(SU(2)_L \times U(1)_{Y}\) symmetry is spontaneously broken to \(U(1)_{\text{em}}\). If we had 4 massless DoF before, they must still be there but they have become massive.

% These three particles would have become Goldstone bosons, but instead they become the longitudinal component of the three vector bosons.

The charged Higgs component \(\phi^{+}\) gives mass to the \(W^{\pm}\) vector bosons of the electroweak interaction, the \(\phi^{0}\) gives mass to the \(Z^{0}\) vector boson.

% So, we know how to write the kinetic terms \(F^{\mu \nu } F_{\mu \nu }\), and the mass terms \(\overline{\psi} \slashed{D} \psi \).

\subsection{Fermions' mass terms}

We have the massless \(G^{a}\) and \(A^{\mu }\), and the massive \(W^{\pm}\) and \(Z^{0}\). These are the terms we've written so far: where do the \(\overline{\psi} m  \psi \) terms come from?

The kinetic term has dimension \(2^2\), which is fine, the wavefunction has dimension \(3/2\) while the derivative has dimension \(1\).
So, also a term \(\overline{\psi} m \psi \) would be fine dimensionally. Is it symmetric?
Let us consider the issue with the left- and right-handed components. If we were to write something like \(\overline{\psi}_L \psi_L \) or \(\overline{\psi}_{R} \psi_{R}\) we would get
%
\begin{align}
\overline{\psi}_{L/R} \psi_{L/R} = \overline{\psi}
\qty(\frac{1 \mp \gamma_5 }{2})
\qty(\frac{1 \pm \gamma_5 }{2})
\psi
= 0
\,,
\end{align}
%
since we are computing the product of two orthogonal projectors.

So, the only terms which do not vanish look like \(\overline{\psi}_{L} \psi_{R} = \overline{\psi}_{R} \psi_{L} = \overline{\psi} \psi \).

\todo[inline]{So he writes, but it does not work! We have two different components, \(\overline{\psi} \psi \) and \(\overline{\psi} \gamma^{5} \psi \)!}

Let us consider electrons for example: an object like \(m \overline{e}_{L} e_R\) is a Lorentz invariant, but is it also gauge invariant?

The spinor \(e_L\) is in an \(SU(2)\) doublet, while the \(e_R\) is an \(SU(2)\) singlet.
So, the object is not a singlet: it is not invariant under \(SU(2)_{L}\), but each term in the Lagrangian must be a scalar with respect to the symmetry group (that is, it must be \emph{symmetric}).
In fact, this term is only \(U(1) _{\text{em}}\) invariant, neither its isospin nor its hypercharge are zero.

So, we cannot include this term.
Does this mean that fermions are massless?
Before introducing \(\phi \), in the pure Yang-Mills theory, they indeed are.

There is only one kind of field which is invariant under spacetime transformations: a scalar. So, we could introduce a term like
%
\begin{align}
\overline{\psi}_{L}^{i} \phi_{i} \psi_{R}
\,,
\end{align}
%
where \(i\) is an index going from 1 to 2, an \(SU(2)\) index: \(\phi \), the Higgs field, is an \(SU(2)_L\) doublet!
This is not a mass term, but an interaction term between the Higgs field and the electron-left and electron-right.

Then, the way the mechanism works is by the fact that the VEV of \(\phi \) is \(v \neq 0\), so at low energies we will see an effective mass term.
The term we put in the Lagrangian will look like
%
\begin{align}
y^{ij} \overline{\psi}^{i}_{L} \phi \psi_{R}^{j}
\,,
\end{align}
%
where now the indices \(i\) and \(j\) run over the possible fermions.
We will then have
%
\begin{align}
M_\ell = y_{\ell} v
\,,
\end{align}
%
and the matrix will be \(y^{ij} = \delta^{ij} y^{j}\).

Similarly we will have mass terms for the leptons, up and down quarks.
These are free parameters of the theory, and they must be different.
The VEV of the Higgs field is fixed by the masses of the \(W\) and \(Z\) bosons: it is of the order \SI{100}{GeV}.

But the mass of the electron is \(m_e \sim \SI{511}{keV}\): so, we must have \(y_e \sim \num{e-5}\).

The price we pay for this is the fact that the number of free parameters increases. This is a ``dirty part'' of the theory.

Why are these parameters so different? This is the \emph{flavour problem}.

\todo[inline]{Stuff is not super clear here.}

Let us write the most general set of Yukawa couplings \cite[eq.\ 18.24]{peskinConceptsElementaryParticle2019}:
%
\begin{align}
\mathscr{L} _{\text{coupling}}
= - y^{ij}_{e} L ^{\dag, i}_{a} \phi_{a} e^{j}_{R}
+ y^{ij}_{d} Q ^{\dag, i}_{a} \phi_{a} d^{j}_{R}
- y^{ij}_{u} Q ^{\dag, i}_{a} \epsilon_{ab} \phi_{b}^{*} u^{j}_{R}
+ \text{h.\ c.}
\end{align}

The matrices \(y^{ij}_{f}\) are called the Yukawa matrices. The indices \(i \) and \(j\) label fermion generations (1, 2, 3 for electron-lik, muon-like and tau-like).
They are not Hermitian in general, however we can construct
%
\begin{align}
y_f y_f ^\dag = U_L^{(f)} Y_f U_L^{(f), \dag}
\qquad \text{and} \qquad
y_f ^\dag y_f = U_R^{(f)} Y_f U_R^{(f), \dag}
\,,
\end{align}
%
and if the matrix \(\sqrt{Y_f}\) is block-diagonal in generation space then we can write
%
\begin{align}
y_f = U_L^{(f)} \sqrt{Y_f} U_R^{(f)\dag}
\,.
\end{align}

So, if we change variables as
%
\begin{align}
e^{i}_{R} \to U^{(e)}_{R, ij} e^{j}_{R}
\qquad \text{and} \qquad
L^{i} \to U^{(e)}_{L, ij} L^{j}
\,,
\end{align}
%
the matrices \(U_{L, R}\) disappear from the couplings.

This works well for the leptons; for the quarks there is an issue, in their coupling to the \(W\) boson we are left with a term
%
\begin{align}
u ^\dag_{L} (i \overline{\sigma}^{\mu }) d_L &= u ^\dag _L U_L^{(u)\dag} (i \sigma^{\mu }) U_L^{(d)} d_L  \\
&= u ^\dag_L (i \overline{\sigma}^{\mu }) \underbrace{U_L^{(u)\dag}U_L^{(d)}}_{V_{CKM}} d_L
\,.
\end{align}

\todo[inline]{But why does this happen? what is it about the quarks that makes those matrices not cancel?}

\todo[inline]{This all has to do with the fact that mass eigenstates and flavour eigenstates are different, methinks.}

% We could have a term which looks like
% %
% \begin{align}
% \overline{u}_{L} \gamma^{\mu } d_{L} W_{\mu }
% \,.
% \end{align}

% Thi is not the most general thing: we could write
% %
% \begin{align}
% \overline{u}_{L} U_{L} ^{\dag, (u)} \gamma^{\mu } U_{L}^{(d)} d_{L} W_{\mu }
% \,.
% \end{align}
% %
% The product \(U ^\dag U\) is called \(V_{CKM}\), the Cabibbo matrix, which gives us \(CP\) violation in the Standard model.

% It does seem, though, that the amount of CP violation in the Standard Model is too small to satisfy the Sacharov conditions.

% There are many parameters: the couplings, the mass terms inside \(y^{ij}\), the terms \(\mu \) and \(\lambda \) inside of \(V(\phi )\).

In the \(V_{CKM}\) matrix we have the freedom to choose three (Euler) angles (it is a rotation matrix basically) and a phase.

\end{document}


% Created 2015-11-24 Tue 11:56
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{khpreamble}
\newcommand{\tustin}{\frac{2}{h}\frac{z-1}{z+1}}
\providecommand{\alert}[1]{\textbf{#1}}

\title{Computerized control - partial exam 3 (dummy)}
\author{Kjartan Halvorsen}
\date{2015-11-17}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs Org-mode version 7.9.3f}}

\begin{document}

\maketitle

In the last lecture we looked at a state-space model of the harmonic oscillator with state variables corresponding to the position and velocity of the oscillating mass. If the frequency of the oscillations is $\omega=1$ and we sample the system with zero-order-hold  with a sampling period $h$ such that $\omega h = 0.4$ we obtain the sampled system
\begin{equation}
\begin{split}
x(k+1) &= \bbm 0.92 & 0.39\\ -0.39 & 0.92 \ebm x(k) + \bbm 0.079\\0.39 \ebm u(k)\\
y(k)  &= \bbm 1 & 0 \ebm x(k)
\end{split}
\label{eq:ss}
\end{equation}

\section*{Problem 1}
\label{sec-1}

Verify that the pulse-transfer function is
\begin{equation}
H(z) = \frac{0.079(z+1)}{z^2 - 1.84z + 1.0} = \frac{0.079(z+1)}{(z-0.92)^2 + 0.15}.
\end{equation}
Plot the zeros and poles of the discrete-time system \textbf{and} of the continuous-time system in the complex plane in figure \ref{fig:complex-plane}.
\begin{figure}[h]
\begin{center}
\includegraphics[]{complex-plane}
\caption{Problem 1: Plot the poles and zeros of the system (both discrete-time and continuous-time).}
\label{fig:complex-plane}
\end{center}
\end{figure}
\section*{Problem 2}
\label{sec-2}

A PD-regulator for the continuous-time harmonic oscillator has been designed. It is sampled using Tustin's formula to give the discrete-time controller
\begin{equation}
F(z) = \frac{5z-3.4}{z+0.6}.
\end{equation}
The system is controlled by error-feedback, according to figure \ref{fig:error-feedback}. Calculate the pulse-transfer function for the closed-loop system from $u_c$ to $y$.
\begin{figure}[h]
\begin{center}
\includegraphics[]{error-feedback}
\caption{Problem 2: Error feedback with PD-control.}
\label{fig:error-feedback}
\end{center}
\end{figure}
\section*{Problem 3}
\label{sec-3}

Figure \ref{fig:bode-open} shows the Bode-diagram of the open-loop pulse transfer function $H_o(z) = H(z)F(z)$. Determine the crossover frequency $\omega_c$ and the phase margin $\varphi_m$ from the Bode-diagram.
\begin{figure}[h]
\begin{center}
\includegraphics[]{bode-open}
\caption{Problem 3: Determine the crossover frequency and the phase margin.}
\label{fig:bode-open}
\end{center}
\end{figure}
\section*{Problem 4}
\label{sec-4}

Assume that the requirements on the properties of the discrete-time closed-loop system is that it should have two complex-conjugated poles at
\begin{equation}
0.3 \pm 0.3i
\end{equation}
In addition, there should be an observer pole in the origin (deadbeat observer). Hence, the desired closed-loop characteristic polynomial is
\begin{equation}
A_{cl} = A_cA_o = (z-0.3-0.3i)(z-0.3+0.3i)z = z^3 - 0.6z^2 + 0.18z,
\end{equation}
with observer polynomial $A_o=z$.
Design a RST-controller (see figure \ref{fig:rst}) that gives the desired closed-loop characteristic polynomial, and such that the pulse-transfer function from $u_c$ to $y$ has static gain equal to one ($G_c(1) = 1)$.
\begin{figure}[h]
\begin{center}
\includegraphics[]{rst}
\caption{Problem 4: RST-controller.}
\label{fig:rst}
\end{center}
\end{figure}
It is sufficient to set up the linear system of equations to solve for $s_0$, $s_1$ and $r_1$.

\section*{Problem 5}
\label{sec-5}

Assume that both the position and the velocity of the moving mass are measured. We thus have a measurement of the state $x(k)$ available, and we can use these two measurements to implement state feedback control according to the control law
\begin{equation}
u(k) = l_1x_1(k) + l_2x_2(k) = Lx(k).
\end{equation}
Determine the state feedback gain $L$ such that the closed-loop system has characteristic polynomial
\begin{equation}
z^2 - 0.6z + 0.18.
\end{equation}
It is sufficient to set up the linear system of equations to solve for $l_1$ and $l_2$.

\section*{Solutions}
\label{sec-6}
\subsection*{Problem 1}
\label{sec-6-1}

The pulse-transfer function is given by
\begin{equation*}
\begin{split}
H(z) &= C\left(zI - \Phi\right)\inv \Gamma\\
     &= \bbm 1 & 0 \ebm \bbm z-0.92 & -0.39\\0.39 & z-0.92 \ebm\inv \bbm 0.079\\0.39 \ebm\\
     &= \frac{1}{(z-0.92)^2 + 0.39^2}\bbm 1 & 0 \ebm \bbm z-0.92 & 0.39\\-0.39 & z-0.92 \ebm \bbm 0.079\\0.39\ebm \\
     &= \frac{0.079(z+1)}{(z-0.92)^2 + 0.15}.
\end{split}
\end{equation*}
\begin{center}
\includegraphics[]{complex-plane-sol}
\end{center}
\subsection*{Problem 2}
\label{sec-6-2}

Write the pulse-transfer function of the controller as
\[ F(z) = \frac{B_f(z)}{A_f(z)}, \] and the plant as
\[ H(z) = \frac{B(z)}{A(z)}. \]
The pulse transfer function of the closed-loop system is given by
\begin{equation*}
\begin{split}
H_c(z) &= \frac{H(z)F(z)}{1 + H(z)F(z)} = \frac{\frac{B(z)}{A(z)}\frac{B_f(z)}{A_f(z)}}{1 + \frac{B(z)}{A(z)}\frac{B_f(z)}{A_f(z)}}\\
       &= \frac{B(z)B_f(z)}{A(z)A_f(z) + B(z)B_f(z)} = \frac{0.079(z+1)(5z-3.4)}{(z^2 -1.84z + 1)(z+0.6) +  0.079(z+1)(5z-3.4)}\\
       &= \frac{0.395(z+1)(z-0.68)}{z^3 -1.24z^2 -0.104z + 0.6 + 0.395(z^2 + 0.32z-0.68)}\\
       &= \frac{0.395(z+1)(z-0.68)}{z^3 -0.845z^2 + 0.0224z + 0.3314}
\end{split}
\end{equation*}
\subsection*{Problem 3}
\label{sec-6-3}

\begin{center}
\includegraphics[]{bode-open-sol}
\end{center}
\subsection*{Problem 4}
\label{sec-6-4}

With a first order controller
\[ \frac{S(z)}{R(z)} = \frac{s_0z + s_1}{z + r_z}, \]
the diophantine equation $AR + BS = A_{cl}$ becomes
\begin{equation*}
\begin{split}
(z^2 - 1.84z + 1)(z + r_1) + 0.079(z+1)(s_0z+s_1) &= z^3 - 0.6z^2 + 1.18z\\
z^3 + (-1.84 + r_1 + 0.079s_0)z^2 + (1 - 1.84r_1 + 0.079(s_0 + s_1))z + r_1 + 0.079s_1 &= z^3 - 0.6z^2 + 1.18z
\end{split}
\end{equation*}
which leads to the following linear equation in the controller parameters $s_0$, $s_1$ and $r_1$:
\begin{equation*}
\bbm 0.079 & 0 & 1\\ 0.079 & 0.079 & -1.84\\ 0 & 0.079 & 1\ebm \bbm s_0\\s_1\\r_1\ebm =
\bbm -0.6+1.84\\0.18-1\\0\ebm
\end{equation*}
with solution
\[ \bbm s_0\\s_1\\r_1\ebm = \bbm  8.90\\-6.80\\0.54\ebm. \]
\subsection*{Problem 5}
\label{sec-6-5}

The desired closed-loop characteristic equation is
\[ z^2 - 0.6z + 0.18. \]
With the state feedback
\[ u(k) = -Lx(k) = - \bbm l_1 & l_2 \ebm x(k) \]
the closed-loop characteristic equation becomes
\[ \det \left( zI - \Phi + \Gamma L \right), \]
where
\[ \Gamma L = \bbm 0.079\\0.39 \ebm \bbm l_1 & l_2 \ebm = \bbm 0.079l_1 & 0.079l_2\\ 0.39l_1 & 0.39l_2 \ebm. \]
We get
\begin{equation*}
\begin{split}
\det  \left( zI - \Phi + \Gamma L \right) &= \det \left( \bbm z & 0\\ 0 & z \ebm - \bbm 0.92 & 0.39\\ -0.39 & 0.92 \ebm  +\bbm 0.079l_1 & 0.079l_2\\ 0.39l_1 & 0.39l_2 \ebm \right)\\
&= \det \bbm z-0.92 + 0.079l_1 & -0.39+0.079l_2\\0.39+0.39l_1 & z -0.92 + 0.39l_2 \ebm \\
&= ( z-0.92 + 0.079l_1 ) (z -0.92 + 0.39l_2) - ( -0.39+0.079l_2)(0.39+0.39l_1)\\
& = z^2 + (-1.84+0.079l_1 + 0.39l_2)z + 1-0.39l_2 + 0.079l_2.
\end{split}
\end{equation*}
Comparing this to the desired characteristic polynomial gives the system of equations
\begin{equation*}
\bbm 0.079 & 0.39\\0.079 &- 0.39\ebm \bbm l_1\\l_2 \ebm = \bbm -0.6 + 1.84\\ 0.18-1 \ebm
\end{equation*}
with solution
\[ \bbm l_1\\l_2 \ebm = \bbm 2.65\\2.64\ebm. \]

\end{document}


\documentclass[t]{beamer}
\usetheme{Copenhagen}
\setbeamertemplate{headline}{} % remove toc from headers
\beamertemplatenavigationsymbolsempty

\usepackage{amsmath, bm, xcolor, tcolorbox}

\title{Complex Fractions}
\author{}
\date{}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Objectives}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}
\maketitle
\end{frame}

\section{Simplify Complex Fractions}

\begin{frame}{Complex Fractions}
\begin{tcolorbox}[colframe=red!35!blue, colback=white!30!green, title=\textbf{Complex Fraction.}]
A \textbf{complex fraction} is a rational expression which contains other rational expressions in the numerator and/or denominator.
\end{tcolorbox}
\vspace{12pt}	\pause
Some examples of complex fractions are given below:
\[
\frac{\frac{2}{x} - 3}{\frac{5}{x} + \frac{7}{x}}
\qquad \text{and} \qquad
\frac{\frac{x}{x+1} + \frac{7}{x}}{\frac{3}{2x} + \frac{8}{x-4}}
\]
\end{frame}

\begin{frame}{Simplifying Complex Fractions}
Simplifying a complex fraction involves working with the expression until there is \emph{at most} only one fraction bar in the entire expression.   \newline\\	\pause

Recall that when we add or subtract fractions with unlike denominators, we need to find a common denominator first.    \newline\\	\pause

Rather than take this approach with complex fractions (which we could, by the way), we are going to clear out our ``tiny" fractions by multiplying every term by the {\color{blue}\textbf{least common tiny denominator}}, or {\color{blue}\textbf{LCTD}}.
\end{frame}

\begin{frame}{Least Common Tiny Denominator}
We find the least common tiny denominator by finding the least common denominator of all of the ``tiny" fractions in the expression. We can then simplify, if possible.  	\newline\\	\pause

\begin{itemize}
\item To find the LCTD of numbers, find the least common multiple of those numbers.   \newline\\ \pause
\item To find the LCTD of variable terms, select the highest power of each term.
\end{itemize}
\end{frame}

\begin{frame}{Example 1}
Simplify each of the following as much as possible.	\newline\\
(a) \quad $\dfrac{\left(3+\dfrac{1}{x}\right)}{\left(\dfrac{2}{x}+4\right)}$
\onslide<2->{\quad LCTD is $x$}
\begin{align*}
\onslide<3->{\dfrac{\left(3+\dfrac{1}{x}\right)}{\left(\dfrac{2}{x}+4\right)} &\left(\dfrac{x}{x}\right)}
\onslide<4->{\quad \longrightarrow \quad \frac{3x+1}{2+4x}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(b) \quad $\dfrac{\left(1-\dfrac{5}{x^2}\right)}{\left(\dfrac{2}{x^2}-7\right)} $
\onslide<2->{\quad LCTD is $x^2$}
\begin{align*}
\onslide<3->{\dfrac{\left(1-\dfrac{5}{x^2}\right)}{\left(\dfrac{2}{x^2}-7\right)} &\left(\dfrac{x^2}{x^2}\right)}
\onslide<4->{\quad \longrightarrow \quad \frac{x^2-5}{2-7x^2}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(c)	\quad	$\dfrac{\left(\dfrac{1}{x}+\dfrac{y}{x^2}\right)}{\left(\dfrac{1}{y}+\dfrac{x}{y^2}\right)}$
\onslide<2->{\quad LCTD is $x^2y^2$}
\begin{align*}
\onslide<3->{\dfrac{\left(\dfrac{1}{x}+\dfrac{y}{x^2}\right)}{\left(\dfrac{1}{y}+\dfrac{x}{y^2}\right)} \left(\dfrac{x^2y^2}{x^2y^2}\right)}
\onslide<4->{\quad \longrightarrow \quad \dfrac{xy^2+y^3}{x^2y+x^3}}
\end{align*}
\end{frame}

\begin{frame}{Example 1c}
\begin{align*}
&\dfrac{xy^2+y^3}{x^2y+x^3}	\\[12pt]
\onslide<2->{&=\dfrac{y^2(x+y)}{x^2(y+x)}} \\[12pt]
\onslide<3->{&=\dfrac{y^2}{x^2}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(d)	\quad $\dfrac{\left(\dfrac{x}{y}-1\right)}{\left(\dfrac{x^2}{y^2}-1\right)}$
\onslide<2->{LCTD is $y^2$}
\begin{align*}
\onslide<2->{\dfrac{\left(\dfrac{x}{y}-1\right)}{\left(\dfrac{x^2}{y^2}-1\right)}\left(\dfrac{y^2}{y^2}\right)}
\onslide<3->{\quad \longrightarrow \quad \dfrac{xy-y^2}{x^2-y^2}}
\end{align*}
\end{frame}

\begin{frame}{Example 1d}
\begin{align*}
&\dfrac{xy-y^2}{x^2-y^2}	\\[12pt]
\onslide<2->{&= \dfrac{y(x-y)}{(x+y)(x-y)}}	\\[12pt]
\onslide<3->{&= \dfrac{y}{x+y}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(e)	\quad $\dfrac{\left(\dfrac{1}{x+7}-\dfrac{1}{x}\right)}{7}$
\onslide<2->{\quad LCTD is $x(x+7)$}	\newline\\
\begin{align*}
\onslide<3->{&\dfrac{\left(\dfrac{1}{x+7}-\dfrac{1}{x}\right)}{7} \left(\dfrac{x(x+7)}{x(x+7)}\right)} \\[10pt]
\onslide<4->{&= \dfrac{x-(x+7)}{7x(x+7)}}		\\[10pt]
\onslide<5->{&= \dfrac{x-x-7}{7x(x+7)}}
\end{align*}
\end{frame}

\begin{frame}{Example 1e}
\begin{align*}
&\dfrac{x-x-7}{7x(x+7)}		\\[12pt]
\onslide<2->{&= \dfrac{-7}{7x(x+7)}}	\\[12pt]
\onslide<3->{&= \dfrac{-1}{x(x+7)}}
\end{align*}
\end{frame}

\begin{frame}{Example 1}
(f) \quad $\dfrac{\left(\dfrac{x+1}{x} + \dfrac{x+1}{x-1} \right)}{\left( \dfrac{x+2}{x} - \dfrac{2}{x-1}\right)}$
\onslide<2->{\quad LCTD is $x(x-1)$}	\newline\\
\begin{align*}
\onslide<3->{
\dfrac{\left(\dfrac{x+1}{x} + \dfrac{x+1}{x-1} \right)}{\left( \dfrac{x+2}{x} - \dfrac{2}{x-1}\right)} \left(\dfrac{x(x-1)}{x(x-1)} \right)
}	\\[12pt]
\onslide<4->{
\dfrac{(x+1)(x-1) + x(x+1)}{(x+2)(x-1)-2x}
}
\end{align*}
\end{frame}

\begin{frame}{Example 1f}
\begin{align*}
& \dfrac{(x+1)(x-1) + x(x+1)}{(x+2)(x-1)-2x} \\[14pt]
\onslide<2->{
&=\dfrac{\onslide<3->{x^2-1}\onslide<4->{+x^2+x}}{\onslide<5->{x^2+x-2}\onslide<6->{-2x}}
}	\\[12pt]
\onslide<7->{&=
\dfrac{2x^2+x-1}{x^2-x-2}
}	\\[12pt]
\onslide<8->{&=
\dfrac{(2x-1)(x+1)}{(x-2)(x+1)}
}
\onslide<9->{\quad \longrightarrow \quad = \dfrac{2x-1}{x-2}}
\end{align*}
\end{frame}

\end{document}