\documentclass{article}
\usepackage[utf8]{inputenc}

\title{MAT257 Notes}
\author{Jad Elkhaleq Ghalayini}
\date{January 18 2019}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{cancel}

\usepackage[margin=1in]{geometry}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{definition}{Definition}
\newtheorem*{corollary}{Corollary}
\newtheorem{exercise}{Exercise}
\newtheorem{claim}{Claim}

\DeclareMathOperator{\Int}{Int}
\DeclareMathOperator{\grad}{grad}
\DeclareMathOperator{\Ker}{Ker}
\DeclareMathOperator{\Ima}{Im}

\newcommand{\reals}[0]{\mathbb{R}}
\newcommand{\nats}[0]{\mathbb{N}}
\newcommand{\ints}[0]{\mathbb{Z}}
\newcommand{\rationals}[0]{\mathbb{Q}}
\newcommand{\brac}[1]{\left(#1\right)}
\newcommand{\sbrac}[1]{\left[#1\right]}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\eval}[3]{\left.#3\right|_{#1}^{#2}}
\newcommand{\ip}[2]{\left\langle#1,#2\right\rangle}
\newcommand{\prt}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\mb}[1]{\mathbf{#1}}
\newcommand{\hlfspc}[0]{\mathbb{H}}
\newcommand{\loint}[0]{\operatorname{L}\int}
\newcommand{\hiint}[0]{\operatorname{U}\int}
\newcommand{\indic}[1]{\chi_{#1}}

\begin{document}

\maketitle

\section{Change of Variable Theorem}

\begin{theorem}
  Let \(A \subset \reals^n\) be open, \(g: A \to \reals^n\) be one to one, continuously differentiable and let, for all \(x \in A\), \(g'(x) \neq 0\). Then
  \begin{equation}
    f : g(A) \to \reals
  \end{equation}
  is integrable if and only if
  \begin{equation}
    f \circ g|\det g'|
  \end{equation}
  is integrable on \(A\). In this case,
  \begin{equation}
    \int_{g(A)}f = \int_Af \circ g|\det g'|
  \end{equation}
  \label{covtheorem}
\end{theorem}
Let's look at some examples, starting with polar coordinates: we use coordinates \(r \in \reals^+_0, \theta \in [0, 2\pi]\) and write
\begin{equation}
  x = r\cos\theta, y = r\sin\theta
\end{equation}
We have
\begin{equation}
  D = \prt{(x, y)}{(r, \theta)} = \begin{pmatrix}
    \cos\theta & -r\sin\theta \\
    \sin\theta & r\cos\theta
  \end{pmatrix} \implies \det D = r
\end{equation}
So we can write
\begin{equation}
  \iint_Af(x, y)dxdy = \iint_Af(r\cos\theta, r\sin\theta)rdrd\theta
\end{equation}
We now examine a corollary of Theorem \ref{covtheorem}.

\begin{corollary}
  Let \(A \subset C \subset \reals^n\) where \(A\) is open, \(C\) is compact and Jordan-measurable and \(C \setminus A\) has measure zero. If \(g\) is a continuously differentiable function from a neighborhood of \(C\) to \(\reals^n\) wich satisfies the conditions of theorem \ref{covtheorem} on \(A\), then
  \begin{equation}
    f: g(C) \to \reals
  \end{equation}
  is integrable if and only if
  \begin{equation}
    f \circ g|\det g'|
  \end{equation}
  is iintegrable on \(C\), and in this case
  \begin{equation}
    \int_{g(C)}f = \int_Cf \circ g|\det g'|
  \end{equation}
  \label{corcov}
\end{corollary}
\begin{lemma}
  Assume \(A \subset \reals^n\) is open and \(g: A \to \reals^n\) is continuously differentiable. If \(B \subset A\) has measure zero, then \(g(B)\) has measure zero.
\end{lemma}
\begin{proof}
  Enough to prove that \(g(B \cap C)\) has measure zero for any \(C \subset A\) compact, since \(A\) has an exhaustion by countably many compact sets \(C_1 \subset C_2 \subset ...\)

  To do so, remember that a countable intersection of measure 0 sets is measure 0. Using \(\mc{C}_1\), which is more than uniformly continuous, we have that
  \begin{equation}
    \forall x \in C, \forall y \in U, |g(x) - g(y)| \leq c|x - y|
  \end{equation}
  where \(U\) is some neighborhood of \(C\). So \(g\) maps a ball of radius \(\epsilon\) to a ball of radius \(c\epsilon\).
\end{proof}
We now proceed to prove Corollary \ref{corcov}
\begin{proof}
  \(g(C) \setminus g(A) \subseteq g(C \setminus A)\), and so it is of measure zero. We hence have that
  \begin{equation}
    \int_{g(A)}f = \int_{g(C)}f
  \end{equation}
  \begin{equation}
    \int_A(f \circ g)|\det g'| = \int_{C}(f \circ g)|\det g'|
  \end{equation}
  giving the desired equality by Theorem \ref{covtheorem}
\end{proof}
Let's move on to another example: what are called spherical coordinates. We use coordinates \(r \in \reals^+_0, \phi \in [0, 2\pi], \theta \in [0, \pi]\) where
\begin{equation}
  x = r\cos\phi\sin\theta, y = r\sin\phi\sin\theta, z = r\cos]theta
\end{equation}
We have... this is going to hurt...
\begin{equation}
  D = \prt{(x, y, z)}{(r, \theta, \phi)} = \begin{pmatrix}
    \cos\phi\sin\theta & r\cos\phi\cos\theta & -r\sin\phi\sin\theta \\
    \sin\phi\sin\theta & r\sin\phi\cos\theta & r\cos\phi\sin\theta \\
    \cos\theta & -r\sin\theta & 0
  \end{pmatrix} \implies \det D = r^2\sin\theta
\end{equation}

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% OPENMODELICA INTERFACE  %%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{OpenModelica Interface}
OpenModelica (\url{http://www.openmodelica.org}) is an open source implementation of the Modelica simulation language.  Modelica is "a non-proprietary,
object-oriented, equation based language to conveniently model complex physical systems containing, e.g., mechanical, electrical, electronic, hydraulic,
thermal, control, electric power or process-oriented subcomponents."\footnote{\url{http://www.modelica.org}}.  Modelica models are specified in text files
with a file extension of .mo.  A standard Modelica example called BouncingBall which simulates the trajectory of an object falling in one dimension from a
height is shown as an example:
\begin{lstlisting}
model BouncingBall
  parameter Real e=0.7 "coefficient of restitution";
  parameter Real g=9.81 "gravity acceleration";
  Real h(start=1) "height of ball";
  Real v "velocity of ball";
  Boolean flying(start=true) "true, if ball is flying";
  Boolean impact;
  Real v_new;
  Integer foo;

equation
  impact = h <= 0.0;
  foo = if impact then 1 else 2;
  der(v) = if flying then -g else 0;
  der(h) = v;

  when {h <= 0.0 and v <= 0.0,impact} then
    v_new = if edge(impact) then -e*pre(v) else 0;
    flying = v_new > 0;
    reinit(v, v_new);
  end when;

end BouncingBall;
\end{lstlisting}

\subsubsection{Files}
An OpenModelica installation specific to the operating system is used to create a stand-alone executable program that performs the model calculations.
A separate XML file containing model parameters and initial conditions is also generated as part of the build process.  The RAVEN OpenModelica interface
modifies input parameters by changing copies of this file.  Both the executable and XML parameter file names must be provided to RAVEN.  In the case of
the BouncingBall model previously mentioned on the Windows operating system, the \textless Files\textgreater  specification would look like:
\begin{lstlisting}[style=XML]
<Files>
  <Input name='BouncingBall_init.xml' type=''>BouncingBall_init.xml</Input>
  <Input name='BouncingBall.exe' type=''>BouncingBall.exe</Input>
</Files>
\end{lstlisting}
\subsubsection{Models}
OpenModelica models may provide simulation output in a number of formats.  The particular format used is specified during the model generation
process.  RAVEN works best with Comma-Separated Value (CSV) files, which is one of the possible output format options.  Models are generated
using the OpenModelica Shell (OMS) command-line interface, which is part of the OpenModelica installation.  To generate an executable that provides
CSV-formatted output, use OMSl commands as follows:
\lstset{
    frame=single,
    breaklines=true,
    postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}}
}
 \begin{enumerate}
\item Change to the directory containing the .mo file to generate an executable for:
\begin{lstlisting}
>> cd("C:/MinGW/msys/1.0/home/bobk/projects/raven/framework/CodeInterfaces/OpenModelica")
"C:/MinGW/msys/1.0/home/bobk/projects/raven/framework/CodeInterfaces/OpenModelica"
\end{lstlisting}
\item Load the model file into memory:
\begin{lstlisting}
>> loadFile("BouncingBall.mo")
true
\end{lstlisting}
\item Create the model executable, specifying CSV output format:
\begin{lstlisting}
>> buildModel(BouncingBall, outputFormat="csv")
{"C:/MinGW/msys/1.0/home/bobk/projects/raven/framework/CodeInterfaces/OpenModelica/BouncingBall","BouncingBall_init.xml"}
Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
\end{lstlisting}
At this point the model executable and XML initialization file should have been created in the same directory as the original model file.
\end{enumerate}
The model executable is specified to RAVEN using the \textless Models\textgreater  section of the input file as follows:
\begin{lstlisting}[style=XML]
<Simulation>
    ...
  <Models>
    <Code name="BouncingBall" subType = "OpenModelica">
      <executable>BouncingBall.exe</executable>
    </Code>
  </Models>
    ...
</Simulation>
\end{lstlisting}
\subsubsection{CSV Output}
The CSV files produced by OpenModelica model executables require adjustment before it may be read by RAVEN.
The first few lines of original CSV output from the
BouncingBall example is shown below:
\begin{lstlisting}
"time","h","v","der(h)","der(v)","v_new","foo","flying","impact",
0,1,0,0,-9.810000000000001,0,2,1,0,
  ...
\end{lstlisting}
RAVEN will not properly read this file as-generated for two reasons:
\begin{itemize}
  \item The variable names in the first line are each enclosed in double-quotes.
  \item Each line has a trailing comma.
\end{itemize}
 The OpenModelica inteface will automatically remove the double-quotes and trailing commas through its implementation of the
finalizeCodeOutput function.


\documentclass{homework}
\course{Math 5522H}
\author{Jim Fowler}
\input{preamble}

\begin{document}
\maketitle

\begin{inspiration}
Nature laughs at the difficulties of integration.
\byline{Pierre-Simon Laplace} % what's the original source for this quotation?
\end{inspiration}

\section{Terminology}

\begin{problem}
  What does it mean to say that $\Omega \subset \C$ is connected?  Is path-connected?
\end{problem}

\begin{problem}
  What is a piecewise-smooth \textbf{curve}?  When are two curves ``the same''?
\end{problem}

\begin{problem}
    Define $\int_\gamma f(z) \, dz$ and define $\int_\gamma f(z) \, dx$ and define $\int_\gamma f(z) \, dy$.
\end{problem}

\begin{problem}
  Define $\int_\gamma f(z) \, d\conj{z}$.
\end{problem}

\begin{problem}
  Define $\int_\gamma f(z) \, \abs{dz}$.
\end{problem}

\begin{problem}
  What does it mean to say that a $1$-form is \textbf{exact}?
\end{problem}

\begin{problem}
  What are the \textbf{poles} and \textbf{zeros} of a rational
  function $p(z)/q(z)$?
\end{problem}

\section{Numericals}

\begin{problem}Consider a piecewise smooth curve $\gamma$ tracing the boundary of the square
  $$S = \{ z = x+iy\in \C : \abs{x} \mbox{ and } \abs{y} \leq 1 \}.$$
  Compute $\displaystyle\int_\gamma \frac{1}{z} \, dz$ by hand.
\end{problem}

\begin{problem}\label{integral-powers-of-z}Consider the curve $\gamma : [0,2\pi] \to \C$ given by $\gamma(\theta) = e^{i\theta}$.  For an integer $n \in \Z$, compute $\displaystyle\int_\gamma z^n \, dz$ and $\displaystyle\int_\gamma \conj{z}^n \, dz$.
\end{problem}

\begin{problem}\label{one-over-z-around-circle}Let $\gamma$ be a (positively oriented) parametrization of a circle
  in the plane, and suppose the image of $\gamma$ does not include the
  origin.  Compute $\displaystyle\int_\gamma \frac{1}{z} \, dz$.
\end{problem}

\begin{problem}\label{lacunary-series}What is radius $R$ of convergence of
  $\displaystyle\sum_{n=1} x^{(n!)}$?  (This is a \textbf{lacunary
    series} with large gaps between nonzero terms.)
\end{problem}

% primitives

\section{Exploration}

\begin{problem}For the series in \ref{lacunary-series}, find a dense
  subset of the circle $\{ z \in \C : \abs{z} = R \}$ where the series
  diverges.
\end{problem}

\begin{problem}
  For which $z \in \C$ with $|z|=1$ does the series
  $\displaystyle\sum_{n=0}^{\infty} \frac{z^n}{n}$ converge?  Diverge?
\end{problem}

\begin{problem}Suppose $f : \C \to \C$ is a rational function which
  sends the unit circle to the real line, i.e., for $z \in \C$ with
  $|z| = 1$ we have $f(z) \in \R$.  Inspired
  by \ref{schwarz-reflection-principle}, compute
  $\overline{f(1/\conj{z})}$ and then discuss the relationship between
  the poles and zeros of $f$.
\end{problem}

\begin{problem}In lecture, we briefly saw an example (the
  \textbf{topologist's sine curve}) of a subset of $\mathbb{C}$ which
  is connected but not path-connected.  For open subsets of
  $\mathbb{C}$, what is the relationship between connectedness and
  path-connectedness?
\end{problem}

\begin{problem}\label{argument-principle-numerical}Consider $\gamma : [0,2\pi] \to \C$ given by $\gamma(\theta) = e^{i\theta}$.  For an integer $n \in \Z$ and $f(z) = z^n$, compute
  \[
    \frac{1}{2\pi i} \displaystyle\int_\gamma \frac{f'(z)}{f(z)} \, dz
  \]
  in two different ways.  First, evaluate $f'(z)/f(z)$ and invoke
  \ref{integral-powers-of-z}.  Second, describe a curve $\gamma_n$ and
  interpret $\int_\gamma \frac{f'(z)}{f(z)} \, dz$ as
  $\int_{\gamma_n} dz/z$ for that different curve $\gamma_n$.  (This
  is our first glimpse of the \textbf{argument principle}.)
\end{problem}

\begin{problem}
  Consider the curve $\gamma : [0,2\pi] \to \C$ given by $\gamma(\theta) = e^{i\theta}$.  For $w \in \C$ with $|w| \neq 1$, compute
  \[
    \frac{1}{2\pi i} \displaystyle\int_\gamma \frac{1}{z-w} \, dz
  \]
  perhaps by invoking \ref{one-over-z-around-circle}.
\end{problem}

\begin{problem}
  Yet again consider the curve $\gamma : [0,2\pi] \to \C$ given by $\gamma(\theta) = e^{i\theta}$.  For distinct $w_1, w_2 \in \C$ with $\abs{w_1} \neq 1$ and $\abs{w_2} \neq 1$, let $f(z) = (z - w_1) (z - w_2)$ and compute
  \[
    \frac{1}{2\pi i} \displaystyle\int_\gamma \frac{f'(z)}{f(z)} \, dz.
  \]
\end{problem}

\section{Prove or Disprove and Salvage if Possible}

\begin{problem}
  If $e^z = e^w$, then $z = w$.
\end{problem}

\begin{problem}
  If $f \, dz$ is exact, then $\displaystyle\int_\gamma f \, dz = 0$.
\end{problem}

\begin{problem}% orientation issues
  Suppose $\gamma : [0,1] \to \C$ is a smooth curve, and $p : [0,1] \to [0,1]$ is a smooth bijection.
  Then
  \[
    \int_\gamma f(z) \, dz = \int_{\gamma \circ p} f(z) \, dz.
  \]
\end{problem}

  \begin{problem}\label{identity-theorem}If $f \in \C[z]$ is a polynomial with infinitely many zeros, then
    $f \equiv 0$.
  \end{problem}

\end{document}


\input{../common/common.tex}

\title{Math notes - Paying a dollar}
\author{Uwe Hoffmann}
\hypersetup{colorlinks, pdftitle={Math notes - Paying a dollar}}

\begin{document}

\setcounter{chapter}{1}
\section*{Paying a dollar}

\vspace{10 mm}
\begin{problem}
In how many combinations of half-dollars, quarters, dimes, nickels and pennies  can you pay out one dollar ? You can assume you have enough coins for any combination and any coins of one denomination are indistinguishable.
\end{problem}

We will look at tuples $(h, q, d, n, p)$ where $h$ is the number of half-dollars, $q$ the number of quarters, $d$ the number of dimes, $n$ the number of nickels and $p$ the number of pennies. We want to consider all tuples $(h, q, d, n, p)$ such that:

\begin{equation*}
50 h + 25 q + 10 d + 5 n + p = 100
\end{equation*}

We want to determine how many such tuples exist. Let's establish what the possible values for $h$, $q$, $d$, $n$ and $p$ can be:

\begin{center}
  \begin{tabular}{cll}
       Denomination & Possible Values & Values range size\\[5pt]
       h & 0, 1, 2 & 3\\
       q & 0, 1, 2, 3, 4 & 5\\
       d & 0, \ldots, 10 & 11\\
       n & 0, \ldots, 20 & 21\\
       p & 0, \ldots, 100 & 101
    \end{tabular}
\end{center}

Clearly $h$, $q$, $d$, $n$ and $p$ cannot take values outside of the ones listed because it would violate the requirement: $50 h + 25 q + 10 d + 5 n + p = 100$.

The multiplicity principle tells us there are $3 * 5 * 11 * 21 * 101 =  349965$ distinct tuples from the possible values.

But not all of them fulfill $50 h + 25 q + 10 d + 5 n + p = 100$. To figure out how many of them do let's introduce the following notation:

\begin{equation*}
\#(h, q, d, n, p)_x = | \{(h, q, d, n, p) : 50 h + 25 q + 10 d + 5 n + p = x\} |
\end{equation*}

so $\#(h, q, d, n, p)_x$ is the number of tuples of half-dollars, quarters, dimes, nickels and pennies that add up to $x$. We are looking for $\#(h, q, d, n, p)_{100}$.

We also use $\#(q, d, n, p)_x$ for tuples of quarters, dimes, nickels and pennies that add up to $x$, $\#(d, n, p)_x$ for dimes, nickels and pennies that add up to $x$ etc.

The half-dollar denomination has the smallest values range size so it's probably in our favor to start with it and break down the problem into smaller problems from there. It is clear that

\begin{equation*}
\#(h, q, d, n, p)_{100} = \#(q, d, n, p)_{100} + \#(q, d, n, p)_{50} + \#(q, d, n, p)_0
\end{equation*}

because $\#(q, d, n, p)_{100}$ comes from $h$ taking value $0$, $\#(q, d, n, p)_{50}$ from $h$ taking value $1$ and $ \#(q, d, n, p)_0$ from $h$ taking value $2$. Continuing down this path and breaking down the $q$ cases:

\begin{equation*}
    \begin{split}
      \#(q, d, n, p)_{100} & = \#(d, n, p)_{100} + \#(d, n, p)_{75} +\\
      &  \#(d, n, p)_{50} + \#(d, n, p)_{25} + \#(d, n, p)_0\\
      \#(q, d, n, p)_{50} & = \#(d, n, p)_{50} + \#(d, n, p)_{25} + \#(d, n, p)_0\\
      \#(q, d, n, p)_{0} & = \#(d, n, p)_0
    \end{split}
\end{equation*}

This is getting tedious though. Maybe we can find a closed-form formula for $\#(d, n, p)_{x}$. Let's try to find one for $\#(n, p)_{x}$ first.

\begin{lem}\label{np}
If $x = 5y$ then
\begin{equation*}
\#(n, p)_{x} = y + 1
\end{equation*}
\end{lem}

\begin{proof}
 $n$ can take values in range $0, \ldots, y$ and for each value of $n$ there is only one possible value of $p = x - 5n$.
\end{proof}

\begin{lem}\label{dnp}
If $x$ is a multiple of $5$ then
\begin{equation*}
\#(d, n, p)_{x} =
   \begin{cases}
       (y + 1)^2 & \text{if $x = 10 y$}\\
       (y + 1)(y + 2) & \text{if $x = 10y + 5$}
    \end{cases}
\end{equation*}
\end{lem}

\begin{proof}

Let's deal with the case $x = 10y$ first.

\begin{equation*}
    \begin{split}
      \#(d, n, p)_{x} & = \sum_{k = 0}^{y} \#(n, p)_{x - 10k}\\
                               & =  \sum_{k = 0}^{y} \#(n, p)_{10 (y - k)} \\
                               & =  \sum_{k = 0}^{y} \#(n, p)_{10 k} \\
                               & =  \sum_{k = 0}^{y} (2 k + 1) \\
                               & = (y + 1)^2
    \end{split}
\end{equation*}

The case $x = 10y + 5$ is established in a similar fashion.
\end{proof}

We can now use the two lemmas to compute the number of combinations:

\begin{equation*}
    \begin{split}
     \#(h, q, d, n, p)_{100} & =\#(d, n, p)_{100} +  \#(d, n, p)_{75} +\\
            & 2 \#(d, n, p)_{50} + 2 \#(d, n, p)_{25} + 3 \#(d, n, p)_0\\
                               & =  11^2 +  8 * 9 + 2 * 6^2 + 2 * 3 * 4 + 3\\
                               & = 292
    \end{split}
\end{equation*}

\end{document}