\section{Curve Sketching}\label{sec:CurveSketching}

In this section, we discuss how we can tell what the graph of a function
looks like by performing simple tests on its derivatives.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Subsections to include
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{5-applications-of-derivatives/5-6-1-inc-dec-first-derivative-test}
\input{5-applications-of-derivatives/5-6-2-second-derivative-test}
\input{5-applications-of-derivatives/5-6-3-concavity-inflection-pts}
\input{5-applications-of-derivatives/5-6-4-asymptotes-other}
\input{5-applications-of-derivatives/5-6-5-summary}

% Exercises are included at the end of each subsection, except the 'asymptotes-other' subsection which does not have its own exercises
% The following are exercises for the entire section on Curve Sketching

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:CurveSketching}}

\begin{enumialphparenastyle}

Sketch the curves. Identify clearly any interesting features, including
local maximum and minimum points, inflection points, asymptotes, and
intercepts.

%%%%%%%%%%
\begin{ex}
	$\ds y=x^5-5x^4+5x^3$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=x^3-3x^2-9x+5$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=(x-1)^2(x+3)^{2/3}$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds x^2+x^2y^2=a^2y^2$, $a>0$.
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=xe^x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=(e^x+e^{-x})/2$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=e^{-x}\cos x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=e^x-\sin x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=e^x/x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y = 4x+\sqrt{1-x}$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y = (x+1)/\sqrt{5x^2 + 35}$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y= x^5 - x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y = 6x + \sin 3x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y = x+ 1/x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y = x^2+ 1/x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y = (x+5)^{1/4}$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y = \tan^2 x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y =\cos^2 x - \sin^2 x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y = \sin^3 x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=x(x^2+1)$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=x^3+6x^2 + 9x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=x/(x^2-9)$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=x^2/(x^2+9)$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=2\sqrt{x} - x$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=3\sin(x) - \sin^3(x)$, for $x\in[0,2\pi]$
\end{ex}

%%%%%%%%%%
\begin{ex}
	$\ds y=(x-1)/(x^2)$
\end{ex}

\end{enumialphparenastyle}


\subsection{Metrics for Entity Typing}
The evaluation of an ET approach relies on some variants of the metrics used in classical classification problems. The explanation of each metric will be supported by numerical values obtained from the example in Table~\ref{tab:metrics_example}.

\begin{table}[H]
\centering
\caption{Example of predictions over a type set $T=\{T1, T2, T3\}$ and a dataset $X=\{X1, X2, X3\}$}
\label{tab:metrics_example}
\begin{tabular}{c|ccc|ccc|}
\cline{2-7}
                                       & \multicolumn{3}{c|}{\textbf{Prediction}}                                          & \multicolumn{3}{c|}{\textbf{Target}}                                              \\ \hline
\multicolumn{1}{|c|}{\textbf{Example}} & \multicolumn{1}{c|}{\textbf{T1}} & \multicolumn{1}{c|}{\textbf{T2}} & \textbf{T3} & \multicolumn{1}{c|}{\textbf{T1}} & \multicolumn{1}{c|}{\textbf{T2}} & \textbf{T3} \\ \hline
\multicolumn{1}{|c|}{X$_{1}$}          & x                                &                                  & x           & x                                & x                                &             \\ \hline
\multicolumn{1}{|c|}{X$_{2}$}          &                                  & x                                &             & x                                &                                  & x           \\ \hline
\multicolumn{1}{|c|}{X$_{3}$}          & x                                &                                  & x           & x                                &                                  & x           \\ \hline
\end{tabular}
\end{table}

In the definition of the metrics we will use terminology that needs a preliminary explanation:
\begin{itemize}
    \item True Positive (\textbf{TP}): number of correct positive predictions. In the example in Table~\ref{tab:metrics_example} we have TP=3 .
    \item False Positive (\textbf{FP}): number of wrong positive predictions. In the example in Table~\ref{tab:metrics_example} we have FP=2 .
    \item True Negative (\textbf{TN}): number of correct negative predictions. In the example in Table~\ref{tab:metrics_example} we have TN=1 .
    \item False Negative (\textbf{FN}): number of wrong negative predictions. In the example in Table~\ref{tab:metrics_example} we have FN=3 .
\end{itemize}

Once fixed these preliminary notions, the evaluated metrics are defined as follows:

\begin{itemize}
    \item \textbf{Accuracy:} percentage of correct predictions; defined as
    \begin{gather*}
        \frac{count(Prediction == Target)}{|X|} = \frac{1}{3}
    \end{gather*}

    \item \textbf{Micro precision:} percentage of correct positive predictions with respect to all the positive predictions; defined as
    \begin{gather*}
        \frac{TP}{TP + FP} = \frac{3}{3 + 2} = 0.6
    \end{gather*}

    \item \textbf{Micro recall:} percentage of correct positive predictions with respect to the positive target; defined as
    \begin{gather*}
        \frac{TP}{TP + FN} = \frac{3}{3 + 3} = 0.5
    \end{gather*}

    \item \textbf{Micro f1:} harmonic mean of micro precision and micro recall; defined as
    \begin{gather*}
        2 \cdot \frac{MicroPrecision \cdot MicroRecall}{MicroPrecision + MicroRecall} =
        2 \cdot \frac{0.6 \cdot 0.5}{0.6 + 0.5} = 0.54
    \end{gather*}

    \item \textbf{Macro precision examples:} mean of the percentages of correct positive predictions with respect to all the positive predictions of each example; defined as
    \begin{gather*}
        \frac{\sum_{x \in X}\frac{TP(x)}{TP(x) + FP(x)}}{|X|}=
        \frac{0.5 + 0 + 1}{3}=0.5
    \end{gather*}

    \item \textbf{Macro recall examples:} mean of the percentages of correct positive predictions with respect to the positive target of each example; defined as
    \begin{gather*}
        \frac{\sum_{x \in X}\frac{TP(x)}{TP(x) + FN(x)}}{|X|}=
        \frac{0.5 + 0 + 1}{3}=0.5
    \end{gather*}

    \item \textbf{Macro f1 examples:} harmonic mean of micro precision examples and micro recall examples; defined as
    \begin{gather*}
        2 \cdot \frac{MacroPrecisionExamples \cdot MacroRecallExamples}{MacroPrecisionExamples + MacroRecallExamples} =\\
        = 2 \cdot \frac{0.5 \cdot 0.5}{0.5 + 0.5} = 0.5
    \end{gather*}

    \item \textbf{Macro precision classes:} mean of the percentages of correct positive predictions with respect to all the positive predictions of each class; defined as
    \begin{gather*}
        \frac{\sum_{t \in T}\frac{TP(t)}{TP(t) + FP(t)}}{|T|} =
        \frac{1 + 0 + 0.5}{3} = 0.5
    \end{gather*}

    \item \textbf{Macro recall classes:} mean of the percentages of correct positive predictions with respect to the positive target of each class; defined as
    \begin{gather*}
        \frac{\sum_{t \in T}\frac{TP(t)}{TP(t) + FN(t)}}{|T|} =
        \frac{0.66 + 0 + 0.5}{3} = 0.38
    \end{gather*}

    \item \textbf{Macro f1 classes:} harmonic mean of macro precision classes and macro recall classes; defined as
    \begin{gather*}
        2 \cdot \frac{MacroPrecisionClasses \cdot MacroRecallClasses}{MacroPrecisionClasses + MacroRecallClasses} = \\
        = 2 \cdot \frac{0.5 \cdot 0.38}{0.5 + 0.38} = 0.43
    \end{gather*}
\end{itemize}


\documentclass[a4paper,12pt]{report}

\usepackage{amsmath,amsfonts,mathtools}
\usepackage{amssymb}
\usepackage{amsbsy}
\usepackage{hyperref}

\begin{document}
\title{ECE259 Abridged}
\author{Aman Bhargava}
\date{Janaury 2020}
\maketitle

\tableofcontents

\chapter{Electrostatics}
\section{Coulomb's Law and Electric Field}

$$\vec{F}_e = k\frac{Q_1Q_2}{|\vec{R}^2|}(\vec{R_2} - \vec{R_1})$$

\section{Electric Field Intensity $\vec{E}$}
\begin{itemize}
\item \textbf{Source} charges 'make' the charge.
\item \textbf{Test} charges 'feel' the charge.
\item Field lines point in the direction that a \textbf{positive test charge} would be pushed if it were placed at a given point in space.
\end{itemize}

\paragraph{Electric Field at $R_2$ due to $Q_1$ at $R_1$: }
$$\vec{E_1} = \lim_{Q_2 \to 0} \frac{\vec{F}_{12}}{Q_2} = \frac{Q_1}{4\pi \varepsilon_0 |\vec{R}_2 - \vec{R}_1|^3}(\vec{R}_2 - \vec{R}_1)$$
\textit{Note: $F_{12}$ is the force acting on 1 due to charge 2}.

\paragraph{Properties of $\vec{E}$}
\begin{itemize}
\item Points away from positive charges.
\item Points toward negative charges.
\item Points along line between source and point of measurement.
\item Linear such that $\vec{E}_{tot} = \sum \vec{E}_i$
\end{itemize}

\section{$\vec{E}$ from Continuous Charge Distribution}

$$\vec{E}_{tot} = \int d\vec{E}' = \int \frac{dQ' (\vec{R} - \vec{R}')}{4\pi\varepsilon_0 |\vec{R} - \vec{R}'|^3}$$

Possible charge distribution types consist of \textbf{linear, surface, and volumes}. Arbitrary surfaces will not be tested - they generally fall into
\textbf{disk, cone, cylinder, sphere, and cube}.

\paragraph{Steps for Finding $\vec{E}_{tot}$:}
\begin{enumerate}
\item Write down Coulomb's Law:
$$\vec{E} = \int d\vec{E}' = \int \frac{dQ'}{4\pi\varepsilon_0 |\vec{R}-\vec{R}'|^3} (\vec{R}-\vec{R}') $$
\item State $dQ'$, $\vec{R}$, and $\vec{R}'$.
$$dQ' = \rho_s dS$$

\item Integrate:
\begin{itemize}
\item Determine $d\vec{E}' = \frac{dQ'(\vec{R}-\vec{R}')}{4\pi\varepsilon_0 |\vec{R}-\vec{R}'|^3}$
\item Ensure that position vectors do not vary with spatial coordinates (if they do, convert them to cartesian or otherwise).
\item Cancel any unit vectors you can using symmetry.
\item Perform the integration.
\end{itemize}
\end{enumerate}

\section{Gauss's Law}
\subsection{Fundamental Postulates of Electrostatics}
$$\nabla \times \vec{E} = 0 \,\, \to \,\, \int_C \vec{E} \cdot d\vec{l} = 0$$
$$\nabla \cdot \vec{D} = \rho_S \,\, \to \,\, \iint_C \vec{D} \cdot d\vec{S} = Q_{enc} = \iiint \rho_v dV$$

The second line is Gauss's law. The first is simply stating that electric fields are conservative/irrotational/etc.

\paragraph{What is $\vec{D}$? } $\vec{D} = \varepsilon \vec{E} = \varepsilon_r \varepsilon_o \vec{E}$. $\vec{D}$ is electric \textbf{flux density} while
$\vec{E}$ is the electric \textbf{field density}.

\subsection{Why is Gauss's law true?}

Why should it be the case that local charge density is given by the divergence of electric flux density? Let's
think about the properties of electric fields. We know that electric field lines (and thus electric flux lines) point away from positive charges.
\textbf{Divergence is how much the vector field points away} (or to) a given point. For that reason, it makes a lot of sense for the divergence to give
you the magnitude of local charge density. If you have a positive charge, your field lines will point away from that charge. Therefore, the divergence of
$\vec{D}$ will be correlated (in this case, equal) to the charge density!

\subsection{Problem Solving with Gauss's Law}
Using Gauss's law, we can greatly simplify the process of finding $\vec{E}$ if a few conditions are met. We need to pick a surface that surrounds a
given charge mass that has the following properties:

\paragraph{Gaussian Surface Properties: }
\begin{enumerate}
\item Closed.
\item $\vec{E}$ is either perpenndicular or parallel to $d\vec{S}$.
\item $|\vec{E}|$ is constant over the surface.
\end{enumerate}

\paragraph{Steps to getting $\vec{E}$ with Gauss's Law:}
\begin{enumerate}
\item Determine the charge distribution from the given source.
\item Choose a corresponding Gaussian surface.
\item $\iint \vec{E} \cdot d\vec{S} \,\, \to \,\, E_R \iint d\vec{S} = E_r\cdot SA$. From here, we can solve for $E_R$, or the
electric field at a given point on the surface (which is constant). The direction of that field can be found via common sense...
\end{enumerate}

You can also solve things with the non-differential form of Gauss's law by knowing that $\nabla\cdot \vec{D} = \rho_v$.

\section{Electric Scalar Potential}
We have the following methods of finding $\vec{E}$ from a charge distribution:
\begin{enumerate}
\item Coulomb's law with integral superposition.
\item Gauss's Law.
\item \textbf{Potential Theory}
\item Getting a computer to do it for us.
\end{enumerate}

We define electric potential $\Delta V$ as the amount of work needed to move a 1-Coulomb charge from
one place to another in an electric field:
$$\Delta V = -\int_{p_1}^{p_2} \vec{E} \cdot dl = \frac{W_{ext}}{Q}$$
$$\nabla V = -\vec{E}$$
$$V = \frac{1}{4\pi\varepsilon} \int_{v, s, l} \frac{dQ'}{|\vec{R} - \vec{R}'|}$$

That second one is Maxwell's 2nd equation.

Fortunately, this is conservative and linear. If you know that $\Delta V$ from point $a$ to point $b$ and the
$\Delta V$ from point $b$ to point $c$, you can easily get the $\Delta V$ from point $a$ to point $c$.

\paragraph{Absolute $V$: } If we take our reference point as one that is infinite distance away, we define
\textbf{absolute $V$} as the energy required to move a 1-Coulomb test charge from infinite distance to a given
point. If it's not otherwise stated, this is the voltage value you are being given.

\paragraph{Equipotential surfaces: } These surfaces have the same $V$ value. Remember how $\nabla V = -\vec{E}$?
Well thanks to our knowledge of gradients, we know that these are always going to be perpendicular to $\vec{E}$
lines. Also, we now know that $\vec{E}$ points from \textbf{high to low $V$} thanks to our awesome vector calculus
prowess. Very cool.

\paragraph{Steps for Problem Solving: }
\begin{itemize}
\item Write $\Delta V = -\int_{p_1}^{p_2} \vec{E}_a \cdot dl$.
\item Evaluate $V_{origin \to p_1}$ and $V_{origin \to p_2}$.
\item Subtract.
\end{itemize}

\paragraph{Electric Potential of a Point Charge: } Using Coulomb's law, we get: $$V = \frac{Q}{4\pi \varepsilon_0 |\vec{R} - \vec{R}'|}$$

For larger bodies, $V$ is a \textbf{simple scalar summation} of the voltage due to individual point charges.

Note that the formulae for the \textbf{gradient operator} $\nabla$ in various coordinate systems are on the aid sheet for the sheet.

\section{Dielectrics}

If you put a material that's not conductive in an electric field, the electron clouds will stretch, and you'll get some surface-bound net charges $\rho_{sb}$. You don't actually have any volume charges, because in the middle of the material, the net charges still cancel out with adjacent atoms since you don't have any net flow of electrons away from their nucleii.

In the case of a capacitor, the original electric field is due entirely to the surface charge on the plates of the capacitor $\pm \rho_s$. This is the sole factor for generating the actual field within the capacitor $E_0 = \frac{\rho_{s}}{\varepsilon_0}$. Similarly, there is an electric field due to polarization within the material due to the \textbf{bound charge density} $\rho_{sb}$:

$$\vec E_p = \frac{\rho_{sb}}{\varepsilon_0};\,\,\, E_{tot} = E_0 + E_p = \frac{\vec E_0}{\varepsilon_r}$$

After some fancy algebra, we also get:

$$\vec P = \rho_{sb} \hat n; \,\, \vec D = \rho_s \hat n = \varepsilon_0 \vec E + \vec P = \varepsilon_r \varepsilon_0 \vec E$$

This is super cool, because it shows that $D$ doesn't really care about dielectrics or anything that gets in its way -- it just cares about the original sources of electric charge: \textbf{free charge} densities.

We also have these super important relationships for when you don't actually have any field causing the polarization and you want to know stuff about the polarization vector or whatever.

$$\rho_{p, v} = -\nabla \cdot \vec P; \,\, \rho_{p, s} = -\hat a_n \cdot (\vec P_2 - \vec P_1)$$

Where $\rho_{p, v}$ is the volume charge density caused by the polarization, etc.

\subsection{Dielectric Strength}

Dielectrics have a maximum $\vec{E}_b$ at which they turn into conductors because the electrons are ripped into the conduction band.

\subsection{Dielectric Boundary Conditions}

At the interface between two materials, the magnitude and direction of the electric field changes. There are \textbf{two boundary conditions} that are able to effectively describe that change, derived from Maxwell's Equations.

\begin{itemize}
\item $E_{t1} = E_{t2}$. \textit{Tangential $\vec{E}$ is continuous across boundary}.
\item $D_{n1} - D_{n2} = \rho_s$. \textit{Normal $\vec{D}$ is discontinuous by difference of $\rho_s$ across boundary}.
\end{itemize}

These both apply in static AND time-varying situations.

\paragraph{Resultant properties of boundary conditions: }
\begin{itemize}
\item $\vec{E} = 0$ for all conductors.
\item \textbf{Current densities} at imperfect conductor boundaries are: $$\frac{J_{t1}}{\sigma_1} = \frac{J_{t2}}{\sigma_2}; J_{n1} = J_{n2} = J_n$$
\item At imperfect boundaries, the surface charge density is: $$\rho_s = J_n\{ \frac{\varepsilon_{r1}\varepsilon_0}{\sigma_1} - \frac{\varepsilon_{r2}\varepsilon_0}{\sigma_2} \}$$
\end{itemize}

Do note that all these rules only apply at interfaces, not in free spaces.

\subsection{Capacitance}

$$Q = C\Delta V;\,\,\,\, C = \frac{Q}{V}$$

Capacitance is the proportionality constant for a given setup between the voltage applied and the charge accumulated. Converting the above statement into integrals, we get:

$$C = \frac{Q}{V} = \frac{\iint_s \vec{D}\cdot d\vec{S}}{|-\int \vec{E} \cdot dl|}$$

\paragraph{Capacitors: } Pretty wacky, can usually be solved with a combination of Gauss's law and knowing your material properties and how to get voltage from an electric field or electric flux density distribution.

\begin{itemize}
\item \textbf{Compound capacitors} have multiple dielectrics. BOUNDARY CONDITIONS MUST BE APPLIED when solving these.
\item \textbf{DIELECTRIC RESISTANCE} is given by: $$RC = \frac{\varepsilon_r \varepsilon_0}{\sigma}$$
\item Supercapacitors use nanoengineering to make high capacitance capacitors.
\end{itemize}

\section{Electrostatic Energy}

\subsection{Parallel Plate Capacitor}

$$Q = CV_0; |\vec D| = \rho_s = \frac{Q}{S}$$
$$\vec E = \frac{\vec D}{\varepsilon_r \varepsilon_0} = \frac{\rho_s}{\varepsilon_R \varepsilon_0} = \frac{V_0}{d}$$

\textbf{Energy} in an electrostatic system is defined as \textbf{work} is required to go from \textbf{infinite disperasl of particles} to the given configuration of charges.

$$W_e = \frac{1}{2} \sum_{i = 1}^{n} Q_i V_i$$

$$W_e = \frac{1}{2} \int_l \rho_l V dl = \frac{1}{2} \iint_s \rho_s V dS = \frac{1}{2} \iiint \rho_v V dv$$

$$W_e = \frac{1}{2} \iiint \vec{D} \cdot \vec{E} dv = \frac{1}{2} \iiint \frac{|\vec{D}^2|}{\varepsilon_r \varepsilon_0} dv$$

\begin{enumerate}
\item $V_i$ is the voltage 'seen' by particle $i$.
\item $Q_i$ is the charge of particle $i$.
\item $\frac{1}{2}$ is because we technically count each charge/associated energy twice.
\end{enumerate}

\paragraph{Energy density: } $w_e = \frac{1}{2} \vec{D}\cdot\vec{E}$

\paragraph{Two Paths to Energy $W_e$}
\textbf{Pathway I: }
\begin{enumerate}
\item $\nabla V = \vec{E}$
\item $\vec{D} = \varepsilon_0 \varepsilon_r \vec{E}$
\item $\rho_s = |\vec{D}|$
\item $Q = \iiint \rho_v dv$
\item $C = \frac{Q}{V_0}$ $$W_e = \frac{1}{2} CV_0^2$$
\end{enumerate}

\textbf{Pathway II: }
$$W_e = \frac{1}{2} \iiint_v \varepsilon_r \varepsilon_0 |\vec{E}|^2 dv = \frac{1}{2} CV_0^2 $$

\section{LaPlace and Poisson's Equations}

These are techniques for going from \textbf{charge density} to \textbf{$\vec{E}$} and are generally used in most practical situations.

Poisson's Equation:

$$\nabla\cdot(\varepsilon_r\varepsilon_0\nabla V) = -\rho_v$$

Laplace's Equation:

$$\nabla\cdot(\varepsilon_r\varepsilon_0 \nabla V) = 0$$

\paragraph{Some vocabulary: }
\begin{itemize}
\item $\nabla \nabla V = \frac{-\rho_v}{\varepsilon_r\varepsilon_0} \to \vec{\nabla}^2 V$ is the \textbf{Laplacian}
\item Therefore $\vec{\nabla}^2 V = 0$ is the true version of Laplace's equation.
\item Under the same notation, $\vec{\nabla}^2V = -\frac{\rho_s}{\varepsilon_r \varepsilon_0}$.
\end{itemize}

This leaves us with a \textbf{boundary value problem}. If we know the voltage at the bounds (or we can infer it from something else), we can then use the fact that $\vec{\nabla{V}}^2 = 0$ wherever there is no surface charge to solve the rest!

\paragraph{Notes on solving the BVP: }
\begin{itemize}
\item Even though the dielectric can be polarized in a question, it doesn't count because it's not a \textbf{FREE} charge.
\item Since you rarely know the actual $\rho_s$ (you would likely know the $V_0$), this is a far more utile problem solving strategy.
\item A reliable \textbf{technique to solve the boundary value problem} is to \textit{integrate the equation twice}.
\end{itemize}

\paragraph{Procedure for BVP's: }
\begin{itemize}
\item Solve \textbf{LaPlace or Poisson's} equation via \textit{direct integration} or \textit{separation of variables}.
\item Apply \textit{boundary conditions} to solve for arbitrary constants to get to a \textit{particular solution}.
\item Use the following formulae to transform to any other variable of interest after solving for the voltage distribution:
$$\vec{E} = -\nabla V; \,\,\,\, \vec{D} = \varepsilon_r\varepsilon_0 \vec{E}; \,\,\,\, \vec{J} = \sigma \vec{E}$$
$$R = \frac{V_0}{\iint \vec{J} \cdot dS} = \frac{\varepsilon_r \varepsilon_0}{\sigma C}$$
\end{itemize}

\paragraph{Electric Shielding}

A conducting material can be used to `shield' the inside from external $\vec{E}$. This is because you can't have a $\Delta V$ across a conductor -- it just conducts the
difference in charge. Since we know that $V_{in} = V_{out}$, we can solve for $$\vec{\nabla}V = 0 \to V(x, y, z) = V_0$$

By the uniquess principle, we know that this HAS to be the only solution. That's how \textbf{Faraday cages} work!

\section{Resistance and Joule's Law}

Recall that
\begin{itemize}
\item $\vec{\nabla} \cdot (\varepsilon_r \varepsilon_0 \vec{\nabla} V) = -\rho_v$
\item $D_{n1} - D_{n2} = \rho_s$
\item $E_{t1} = E_{t2}$
\end{itemize}

\subsection{Volume Current Density}

$\vec{J}$ is the vector field that represents microscopic current flow. $$\vec{J} = \sigma \vec{E}$$
$$I = \iint_S \vec{J} \cdot dS$$
$$\mu_e = \frac{e \tau}{m_e}$$
$$\sigma = \frac{N_e e^2 \tau}{m_e}$$

\paragraph{Resistance: } plays into the situation as follows.

$$R = \frac{V_0}{I} = \frac{|-\int \vec{E}\cdot dl|}{\iint_s \vec{J} \cdot dS} = \frac{|-\int \vec{E}\cdot dl|}{|\iint_s \sigma \vec{E} \cdot d\vec{S}|}$$

And if \textbf{$S$ is uniform over $L$}:

$$R = \frac{L}{\sigma S}$$

% Continue from end of March 5/Beginning of March 6

\subsection{Power}

$$P = \iiint_V \vec{E} \cdot \vec{J} dV$$

This gives the power loss due to resistance leading to heat loss.

\chapter{Magnetostatics}

\section{Biot-Savart Law}

$\vec H$ is the magnetic field intensity and $\vec B$ is the magnetic flux density. $\vec B$ is kind of like $\vec E$ and $\vec H$ is like $\vec D$.

\textbf{All magnetic fields} are due to moving charges of one sort or another. In general,

$$d\vec B = \frac{\mu_0 I d\vec{l} \times (\vec R - \vec R ')}{4\pi |\vec R - \vec R'|^3}$$

\begin{itemize}
\item Point charge current: $$\vec{B} = \frac{\mu_0}{4\pi} \frac{Q\vec{u} \times (\vec R - \vec R')}{|\vec R - \vec R'|^3}$$
\item Line current: $$B = \frac{\mu_0 I}{4 \pi} \int_C \frac{dl' \times (\vec R - \vec R')}{|\vec R - \vec R'|^3}$$
\item Surface current: $$B = \frac{-\mu_0}{4\pi} \iint_S \frac{\vec J_s \times (\vec R - \vec R')}{|\vec R - \vec R'|^3}$$
\item Volume current: $$B = \frac{\mu_0}{4\pi} \iiint_{vol} \frac{\vec{J} \times (\vec R - \vec R')}{|\vec R - \vec R'|^3} dV'$$
\end{itemize}

$\mu$ is the new version of the electric permeability: $$\vec B =  \mu \vec H = \mu_0 \mu_r \vec H$$

\section{Boundary Conditions}

$$B_{n1} = B_{n2}; H_{t1} - H_{t_2} = J_s$$

\section{Energy}

$$w_m = \frac{1}{2} \vec B \cdot \vec H$$

$$W_m = \frac{1}{2} \iiint_{vol} \vec B \cdot \vec H dV$$

\section{Lorentz Force}

This relates the movement of a charge in a magnetic field to the force it experiences.

$$F_m = q\vec u \times \vec B = \vec I l \times \vec B$$

You use the right-hand-rule for this relationship: Your fingers represent the direction of motion $\vec u$, your palm is the field $\vec B$, and then your thumb is $F_m$.

$$F_{tot} = F_e + F_m = q\vec E + q \vec u + \vec B$$

\section{Ampere's Law}

$$\vec \nabla \times \vec H = \vec J$$

$$\int_C \vec H \cdot d\vec l = \iint_S \vec J \cdot d\vec S = I_{enc}$$

You relate the current with $\vec H$ via the right hand rule. Your fingers wrap around the wire in the direction of $\vec{H}$ while your thumb points in the direction of the net current.

This is basically Gauss's law. Make sure that your $\vec H$ is going to be constant and either be perpendicular or parallel to the closed path you draw, and then use the fact that:   $$\int_C \vec H \cdot d\vec l = |\vec{H}| \cdot \text{circumference}$$

\section{Magnetization}

\textbf{Magnetic Dipole: } A closed loop of current. $\vec m = I S \hat n$, where $I$ is the current, $S$ is the surface area of the loop, and $\hat n$ is given by the right hand rule.

\textbf{Torque: } Is given by

$$\vec T = \vec m \times \vec B$$

In other worse, $\vec m$ will rotate until it conforms to $\vec B$ so that torque is minimized. This leads to an internal magnetic field $$\vec B_{material} > \vec B_{external}$$

\textbf{Bound current density: } $\vec J_{ms} = \vec M \times \hat n$

\textbf{Magnetic field intensity: } $\vec H = \frac{\vec B}{\mu_0} - \vec{M}$

\textbf{Magnetic susceptibility: } $\vec{M} = \chi_m \vec H$

\textbf{Relative permeability: } $\mu_r = \chi_m + 1$

Much like with electrostatics, $\vec H$ only arises from \textbf{free currents}. $\vec B$ is the one that deals with both free and bound currents.

\section{Material Properties: Atomic Magnetic Dipoles}

\begin{enumerate}
\item \textbf{Non-zero moment} materials will have $\vec M$ align with $\vec B$. If strong alignment is achieved, then the field is enhanced (\textit{ferromagnetism}. If weak alignment, then there will be moderate enhancement (\textit{paramagnetic}).
\item \textbf{Net-zero moment} materials will have a small \textit{reduction} in $\vec B$, leading to \textit{diamagnetism}.
\end{enumerate}

\begin{itemize}
\item \textbf{Diamagnetic: } $\mu_r \approx \leq 1$ (values like 0.999). $B_{internal} < B_{applied}$.
\item \textbf{Paramagnetic: } $\mu_r \approx \geq 1$ (values like 1.01). $B_{internal} > B_{applied}$.
\item \textbf{Ferromagnetic: } $\mu_r >>> 1$. $B_{internal} >>> B_{applied}$.
\item \textbf{Ferrimagnetic: } $\mu_r > 1$. $B_{internal} > B_{applied}$.
\end{itemize}

\section{Modeling Transformer Circuits}

\begin{tabular}{|l|l|}
\hline
\textbf{Electric} & \textbf{Magnetic} \\
\hline
Voltages & $V_m = NI_0$ \\
Current & $\Phi$ \\
Resistance & $ R = \frac{L}{\mu S}$ \\
Conductivity & Permeability $\mu = \mu_r \mu_0$ \\
\hline
\end{tabular}

\subsection{Mesh Analysis}

\section{Inductance}

\end{document}


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{November 3, 2014}
\maketitle
\section*{5.3 properties of continuous functions}
let $f:S\to \mathbb{R}^m$ be a function. the following are equivalent
\begin{enumerate}
\item
  f is continuous on S
\item
  if $\{a_k\}$ is a sequence of elements in S such that $\lim a_k=v\in S$ then $\lim f(a_k)=f(v)$
\item
  if $U\subseteq \mathbb{R}^m$ is open them $f^{-1}(U)$ is an open set in $S$
\end{enumerate}

a set $V$ is open in $S$ if $V=U\cap S$ where $U$ is open in $\mathbb{R}^n$

\subsection*{examples}
let $S=[0,1]$
then $[0,\frac{1}{2})$ is open in $S$ because $[0,\frac{1}{2})=(-\frac{1}{2},\frac{1}{2})\cap S$.

$(0,\frac{1}{2})=(0,\frac{1}{2})\cap S$.

\subsubsection*{proof of above thrm}
by definition of limit, given any small $\delta>0$ there exists $N$ such that $|a_k-V|<\delta$ if $k\ge N$. We want to study $|f(a_k)-f(v)|$. Because $f$ is continuous $|f(a_k-f(v)|<\varepsilon$ if $|a_k-v|<r$ there exists $r(\varepsilon,v)>0$. pick $r=\delta$. then $|a_k-v|<r$ for all $k\ge N$ implies $|f(a_k)-f(v)|< \varepsilon$ and so $\lim f(a_k)=f(v)$

for $2\to1$ assume that $f$ is not continuous. we will prove that $2$ fails.

if $f$ is not continuous, then there exists some pint $p\in S$ and $\varepsilon>0$ such that $\forall r>0$ then $|x-p|<r$ and $|f(x)-f(p)|\ge \varepsilon$. consider $a_k\in S$ such that $\lim a_k=p$. by hypothesis $\lim f(a_k)=f(p)$. but then we have $|a_k-p|<r$ and $|f(a_k)-f(p)|<\varepsilon$

for $1\to3$. we want to show that given and open set $U\subseteq \mathbb{R}^m, f^{-1}(U)$ is open  in $S$. pick $x\in f^{-1}(U)$. we need to find a ball $B(x,r)\subseteq f^{-1}(U)$.

$f(x)\in U$. $U$ is open, so there exists some $\epsilon>0$ such that $B(f(x),\varepsilon)\subseteq U$. hence $f^{-1}(B(f(x),\varepsilon))\subseteq f^{-1}(U)$.

given $\varepsilon>0$ there exists $r>0$ such that if $||x-y||<r\to ||f(x)-f(y)||<\varepsilon$. continuity gives us a radius $r$ such that if $y\in B(x,r)$ then $||f(x)-f(y)||<\varepsilon$ and so $f(y)\in B(f(x),\varepsilon)$. So we have found $B(x,r)\subseteq f^{-1}(B(f(x),\varepsilon)\subseteq f^{-1}(U)$

\subsubsection*{moral of the story}
continuity can be seen in terms of finding balls.

\subsubsection*{example}
$f(x)=x^2$

$f^{-1}(c,d)=(\sqrt{c},\sqrt{d})\cup (-\sqrt{c},-\sqrt{d})$

$f^{-1}(-1,1)=(-1,1)$

$f^{-1}(-2,-1)=\emptyset$

$f$ is continuous iff $f^{-1(U)}$ is open if $U$ is open, but if $U$ is open then $f(U)$ is not necessarily open.

$f(-1,1)=[0,1)$ which is not open in $\mathbb{R}$

\subsection*{prop5.3.5}
let $f:\mathbb{R}^n\to\mathbb{R}^m, g:\mathbb{R}^m\to\mathbb{R}^p$ assume $f,g$ are continuous. then $g\circ f$ is continouos.

assume that $U\in \mathbb{R}^p$ is open. we need to show that $(g\circ f)^{-1}(U)$ is open. $(g\circ f)^{-1}(U)=f^{-1}(g^{-1}(U))$. because g is continuous, $g^{-1}(U)$ is open. beccause $f$ is continuous, $f^{-1}(g^{-1}(U)$ is open.

\subsection*{prop 5.3.2}

if in addition, $f$ and $g$ are continous at $a$ then so are $f\pm g, f\cdot g, \alpha f,\frac{f}{g}$.

corollary, we know that $f(x)=x$ is continous $f:\mathbb{R}^n\t\mathbb{R}^n$ then $f(x)=x^{m}$ is continuous a $m\in \mathbb{N}$. and any  polynomial is continous. and any rational function  is continous a $f(x)/g(x)$ such that $g(x)\ne 0$.
\end{document}


\subsection{Tank Models}

Accurately modelling tank pressure changes is essential for accurate
maneuver modelling and reconstruction.  The following sections
discuss three types of tank models:  pressurant tank, regulated fuel
tank, and blowdown fuel tank.  For each tank there are three models:
isothermal, heat transfer, and adiabatic.

The models used in GMAT are based on work by Estey\cite{Estey:83} ,
Hearn\cite{Hearn:01} and Moran\cite{Moran}.  For each tank, we
select a set of state variables that when defined, allow us to
determine all remaining properties of the tank.  For the state
variables, we provide differential equations that describe how the
state variables change with respect to time.  The number of state
variables varies between different tanks, and with the model type
such as isothermal and heat transfer.

For each of the three tanks, we develop a heat transfer model, an
adiabatic model, and an isothermal model.  The heat transfer model
is derived using the laws of conservation of energy and the
conservation of mass. An adiabatic model is provided by setting the
heat transfer rates to zero in the heat transfer model. The
isothermal model for each tank is developed separately. Each ot
these models is useful for certain classes of maneuvers.  Isothermal
models are useful for maneuvers with low mass flow rates, adiabatic
models are useful for short maneuvers with high mass flow rates.
Heat transfer models are useful for long maneuvers with large mass
flow rates.

When developing heat transfer models, we'll assume that specific
internal energy is given by
%
\begin{equation}
    u = c T
\end{equation}
%
specific enthalpy for a liquid is given by
%
\begin{equation}
    h_\ell = c_\ell T_\ell
\end{equation}
%
and specific enthalpy  for a gas is given by
%
\begin{equation}
    h_g = T_g( c_g + R_g)
\end{equation}
%
The notation used in tank model development is shown below.  After
presenting notation, we present the dynamics model for a pressurant
tank.

 \noindent\textit{Nomenclature}\vspace{-.1 in}
\begin{tabbing}
    -----------------------     \= Reynolds number based on length $s$ \kill
    $A_g,A_\ell,A_w$    \> = Heat transfer area     \\
    $c_v, c_g$        \>  = Specific heat at constant volume     \\
    $D$        \>  = Tank diameter     \\
    $d$        \>  = Liquid surface diameter    \\
    $Gr$        \>  = Grashof number  \\
    $h_\ell, h_v$        \>  = Enthalpy     \\
    $m_g,m_\ell,m_w,m_v$    \> = Mass   \\
    $P_g,P_v,P_t$    \> = Pressure   \\
    $R_v,R_g$    \> = Gas constant   \\
    $T_g,T_\ell,T_w,T_v,T_a$    \> = Temperature   \\
    $u_g,u_\ell,u_w,u_v$    \> = Specific internal energy   \\
    $V_g,V_\ell,V_t$    \> = Volume   \\
    $\dot{W}$    \> = Work rate   \\
    $\dot{Q}_g,\dot{Q}_v,\dot{Q}_l,\dot{Q}_w$    \> = Heat transfer rate     \\
    $\nu_l,\nu_g,\nu_v$    \> = Specific volume  \\
\end{tabbing}
%
\noindent\textit{Subscripts}\vspace{-.1 in}
\begin{tabbing}
    -----------------------     \= Reynolds number based on length $s$ \kill
    $a$    \> = Ambient    \\
    $g$    \> = Pressurant gas    \\
    $\ell$    \> = Propellant liquid  \\
    $t$    \> = Total    \\
    $v$    \> = Propellant vapor \\
    $w$    \> = Tank wall      \\
    $e$    \> = Exit-flow      \\
    $i$    \> = In-flow
\end{tabbing}

\subsubsection{Pressurant Tank}

The pressurant tank model is the simplest of the tank models
primarily due to the fact that there is only one substance, the
pressurant gas, contained in the tank.  In this section, we develop
a state space model for pressurant tank dynamics.  We choose the
state variables to be pressurant gas mass and temperature, $m_g$ and
$T_g$ respectively, and tank wall temperature $T_w$.

In Fig.\ref{fig:PressurantTank} we see an illustration of a
pressurant tank.  We divide the tank into two control volumes: the
gas region and the tank wall region.  The only mass flow in the
system occurs where pressurant gas exits the tank.  Heat transfer
occurs between the gas and the wall, and the wall and the ambient
surroundings.
%
\begin{figure}[ht]
\centerline{
    \begin{picture}(110,440)
    \special{psfile= ./Images/PressurantTank.eps hoffset= -120 voffset= 115
    hscale=55 vscale=55}
    \makebox(90,525){$\dot{m}_e$,$h_g$}
    \makebox(-105,790){1.Gas}
    \makebox(-105,765){$m_g$, $P_g$, $T_g$}
    \makebox(-165,680){$\dot{Q}_g$}
    \makebox(-295,760){$\dot{Q}_w$}
    \makebox(-260,865){2.Tank Wall}
    \makebox(-270,840){$m_w$,  $T_w$}
    \end{picture}}\vskip -3.65 in  \caption{ Pressurant Tank Diagram} \label{fig:PressurantTank}
\end{figure}
%

Knowing the volume of the tank and the state variables  $m_g$,
$T_g$, and $T_w$, we calculate pressure from one of the following
two equations of state:
%
\begin{equation}
   P_g = \frac{m_g R_g T_g}{V_g}
\end{equation}
%
or from the Beattie-Bridgeman Eq.
%
\begin{equation}
   P_g = \frac{R_g T_g}{V_g} + \frac{a_g}{V_g^2} + \frac{b_g}{V_g^3}
\end{equation}
%

The state variables $m_g$, $T_g$, and $T_w$ are described by
ordinary differential equations found by applying the first law of
thermodynamics and the conservation of mass.  The 1st Law applied to
the gas control volume yields
%
\begin{equation}
   \frac{d}{dt}\left(m_g u_g \right) =  \dot{Q}_g - \dot{m}_e h_g
  \label{Eq:PressurantGas1stLaw}
\end{equation}
%
The 1st Law applied to the wall control volume  yields
%
\begin{equation}
     \frac{d}{dt}\left( m_w u_w \right) = \dot{Q}_w -  \dot{Q}_g \label{Eq:PressurantWall1stLaw}
\end{equation}
%
and finally from conservation of mass we obtain
%
\begin{equation}
    \dot{m}_g = -\dot{m}_e \label{Eq:PressurantMassCon}
\end{equation}
%
For these equations to be useful for numerical integration, we need
to expand the derivatives, and if necessary, decouple the equations
(as we'll see, for the pressurant tank, the equations are not
coupled).

Expanding the terms in Eq.~(\ref{Eq:PressurantGas1stLaw}) we have
%
\begin{equation}
    \dot{m}_g c_g T_g + m_g c_g \dot{T}_g = \dot{Q}_g - \dot{m}_e T_g \left( c_g + R_g\right)
\end{equation}
%
Similarly, expanding Eq.~(\ref{Eq:PressurantWall1stLaw}) we obtain
%
\begin{equation}
    m_w c_w \dot{T}_w = \dot{Q}_w -  \dot{Q}_g
\end{equation}
%
Solving the system of equations yields the following differential
equations of state for the pressurant tank heat transfer model.
%
\begin{eqnarray}
    \dot{m}_g &=& -\dot{m}_e\\
    %
    \dot{T}_g &=& \frac{1}{m_g c_g} \left( \dot{Q}_g - T_g R_g  \dot{m}_e  \right)\\
    %
    \dot{T}_w &=& \frac{1}{m_w c_w} \left( \dot{Q}_w - \dot{Q}_g  \right)
\end{eqnarray}
%
The adiabatic model is obtained by setting the terms $\dot{Q}_g$ and
$\dot{Q}_w$ to zero in the above equations.  (Note for the adiabatic
model there are only two state variables, $m_g$ and $T_g$, as the
wall temperature $T_w$ is removed from the system of equations.)
Similarly, the isothermal model is obtained by setting $\dot{T}_g$
and $\dot{T}_w$ to zero.  So, for the isothermal model there is only
one state variable $m_g$.

In summary, for the pressurant tank, all models calculate the tank
pressure using
%
\[
   P_g = \frac{m_g R_g T_g}{V_g}
\]
%
 then the specific equations for the heat transfer, adiabatic, and
isothermal models, are as follows

\noindent\textit{Pressurant Tank:  Heat Transfer}

\noindent State Variables:  $m_g$, $T_g$, $T_w$
%
\begin{eqnarray}
    \dot{m}_g &=& -\dot{m}_e \nonumber\\
    %
    \dot{T}_g &=& \frac{1}{m_g c_g} \left( \dot{Q}_g - T_g R_g  \dot{m}_e  \right)\nonumber\\
    %
    \dot{T}_w &=& \frac{1}{m_w c_w} \left( \dot{Q}_w - \dot{Q}_w  \right)\nonumber
\end{eqnarray}
%
\textit{Pressurant Tank:  Adiabtic}

\noindent State Variables:  $m_g$, $T_g$
%
\begin{eqnarray}
    \dot{m}_g &=& -\dot{m}_e \nonumber\\
    %
    \dot{T}_g &=& \dot{m}_e\frac{T_g R_g   }{m_g c_g} \nonumber
\end{eqnarray}
%
\noindent\textit{Pressurant Tank:  Isothermal}

\noindent State Variables:  $m_g$
%
\begin{equation}
    \dot{m}_g = -\dot{m}_e
\end{equation}

Now let's look at a model for a fuel tank operating in blow down
mode.

%\subsubsection{Blow-Down Tank w/o Vapor Pressure}
%
%
%\begin{figure}[ht]
%\centerline{
%    \begin{picture}(100,510)
%    \special{psfile= ./Images/BlowDownTank.eps hoffset= -120 voffset= 170
%    hscale=55 vscale=55}
%    \makebox(80,525){$\dot{m}_e$,$h_l$}
%    \makebox(-80,970){1.Gas}
%    \makebox(-90,940){$m_g, P_g, T_g$}
%    \makebox(-190,905){$\dot{Q}_v$}
%    %\makebox(-140,905){$\dot{m}_v, h_v$}
%    \makebox(10,905){$\dot{Q}_g$}
%    \makebox(-135,820){2.Liquid}
%    \makebox(-145,790){$m_\ell, T_\ell$}
%    \makebox(-235,740){$\dot{Q}_\ell$}
%    \makebox(-335,990){3.Tank Wall}
%    \makebox(-335,970){$m_w, T_w$}
%    \makebox(-277,1020){$\dot{Q}_w$}
%    \end{picture}}\vskip -3.65 in  \caption{ Bi-Prop Thruster Diagram} \label{fig:BlowDownTankWOVap}
%\end{figure}
%
%\textit{Assumptions}
%\begin{itemize}
%    \item Vapor pressure is zero.
%    \item Liquid density is constant.
%    \item Gas mass is constant.
%\end{itemize}
%%
%Assume we are given $m_g$, the tank diameter $D$, and hence know the
%total tank volume $V_t$, and we know the physical constants
%associated with the liquid and gas ($R_g$,$c_g$,$\nu_g$,$c_\ell$,
%$\nu_\ell$). We choose the state variables $m_\ell$, $T_\ell$,
%$T_g$, and $T_w$, all other tank properties can be calculated from
%these state variables using the following equations:
%%
%\begin{eqnarray}
%    V_\ell & = &  \nu_\ell m_\ell\\
%   %
%    V_g & = &  V_t - V_\ell\\
%   %
%   P_g & = &  \frac{m_g R_g T_g}{V_g}\\
%\end{eqnarray}
%%
%
%We require differential equations that describe the time rate of
%change of the state variables $m_\ell$, $T_\ell$, $T_g$, and $T_w$.
%The differential equations are found by applying the 1st law of
%thermodynamics and conservation of mass to the three control volumes
%illustrated in Fig. \ref{fig:BlowDownTankWOVap}. The 1st Law applied
%to the gas control volume yields
%%
%\begin{equation}
%   \frac{d}{dt}\left(m_g u_g \right) = \dot{Q}_v + \dot{Q}_g - P_g \dot{V}_g
%  \label{Eq:Blowdown1stLawWOVap}
%\end{equation}
%%
%The 1st Law applied to the liquid control volume yields
%%
%\begin{equation}
%   \frac{d}{dt}\left( m_\ell u_\ell \right) = \dot{Q}_\ell - \dot{Q}_v +
%   P_g \dot{V}_g   - \dot{m}_e h_\ell \label{Eq:BlowdownLiquid1stLawWOVap}
%\end{equation}
%%
%The 1st Law applied to the wall control volume  yields
%%
%\begin{equation}
%     \frac{d}{dt}\left( m_w u_w \right) = \dot{Q}_w - \dot{Q}_\ell - \dot{Q}_g
%\end{equation}
%%
%and finally from conservation of mass we obtain
%%
%\begin{equation}
%    \dot{m}_\ell = -\dot{m}_e \label{Eq:BlowdownMassConWOVap}
%\end{equation}
%
%
%The equations above give us four ordinary differential equations
%that allow us to solve for the tank states as a function of time.
%For numerical integration, we need to decouple these equations.
%
%Let's continue with Eq.~(\ref{Eq:Blowdown1stLawWOVap}).   Taking the
%derivative assuming $\dot{m}_g = 0$ and noting that $\dot{V}_g = -
%\nu_\ell \dot{m}_\ell $ yields
%%
%\begin{equation}
%     m_g c_g \dot{T}_g = \dot{Q}_v + \dot{Q}_g + P_g\nu_\ell \dot{m}_\ell
%\end{equation}
%%
%Gathering all state terms on the left hand side yields
%%
%\begin{equation}
%       -P_g\nu_\ell \dot{m}_\ell  + m_g c_g \dot{T}_g = \dot{Q}_v + \dot{Q}_g \label{Eq:CV1}
%\end{equation}
%
%
%Continuing with Eq.~(\ref{Eq:BlowdownLiquid1stLawWOVap}), we take
%the derivative and group terms to obtain
%%
%\begin{equation}
%   \left( c_\ell T_\ell  + P_g \nu_\ell\right)\dot{m}_\ell +
%    m_\ell c_\ell \dot{T}_\ell  =  \dot{Q}_\ell - \dot{Q}_v -  c_\ell T_\ell \dot{m}_e\label{Eq:CV2}
%\end{equation}
%%
%Similarly for the wall region, we arrive at
%%
%\begin{equation}
%     m_w c_w \dot{T}_w = \dot{Q}_w - \dot{Q}_\ell - \dot{Q}_g \label{Eq:CV3}
%\end{equation}
%
%Equations \ref{Eq:CV1} -\ref{Eq:CV3} and
%Eq.\ref{Eq:BlowdownMassConWOVap} can be written in matrix form as
%follows.
%%
%\begin{equation}
%   \left(\begin{array}{ccccccc}
%   A_{11} & 0 & A_{13} & 0 \\
%    A_{21} & A_{22} & 0  & 0 \\
%    0 & 0 & 0  & A_{34} \\
%    A_{41} &  & 0  & 0 \\
%   \end{array}\right)
%   %
%   \left(\begin{array}{c}
%    \dot{m}_\ell \\
%    \dot{T}_\ell  \\
%    \dot{T}_g \\
%   \dot{T}_w  \\
%   \end{array}\right) =
%   %
%   \left(\begin{array}{c}
%    b_1\\
%    b_2  \\
%    b_3 \\
%    b_4  \\
%   \end{array}\right)
%\end{equation}
%%
%where
%%
%\begin{eqnarray}
%   A_{11}& = &  - P_g \nu_\ell \\
%   %
%   A_{13}& = &  m_g c_g\\
%   %
%   A_{21} & = & c_\ell T_\ell + P_g \nu_\ell \\
%   %
%   A_{22} & = & m_\ell c_\ell\\
%   %
%   A_{34} & = & m_w c_w\\
%   %
%   A_{41} & = & 1\\
%   %
%   b_1 & = & \dot{Q}_v + \dot{Q}_g \\
%   %
%   b_2 & = & \dot{Q}_\ell - \dot{Q}_v -  c_\ell T_\ell\dot{m}_e\\
%   %
%   b_3 & = & \dot{Q}_w -\dot{Q}_\ell - \dot{Q}_g\\
%   %
%   b_4 & = & -\dot{m}_e\\
%\end{eqnarray}
%%
%
%Solving the system of equations yields
%%
%\begin{eqnarray}
%    \dot{m}_\ell &=& -\dot{m}_e\\
%    %
%    \dot{T}_\ell &=& \frac{1}{m_\ell c_\ell}\left( \dot{Q}_\ell - \dot{Q}_v  + P_g \nu_\ell \dot{m}_e\right)\\
%    %
%    \dot{T}_g &=&  \frac{1}{m_g c_g}\left( \dot{Q}_v + \dot{Q}_g - P_g \nu_\ell \dot{m}_e\right)\\
%    %
%    \dot{T}_w &=&  \frac{1}{m_w c_w}\left(\dot{Q}_w - \dot{Q}_\ell - \dot{Q}_g \right)\\
%\end{eqnarray}

\subsubsection{Blowdown Tank}

The blowdown tank model is significantly more complex than the
pressurant tank model due to the presence of liquid fuel and fuel
vapor contained in the tank ullage.   In this section, we develop a
state space model for a blow down tank.  We choose the state
variables to be the liquid mass and temperature, $m_\ell$ and
$T_\ell$, the gas temperature $T_g$, and tank wall temperature
$T_w$.

In Fig.\ref{fig:BlowDownTank} we see an illustration of a blow down
tank. We divide the tank into three control volumes: the gas region,
the liquid region, and the tank wall region. Mass flow occurs where
the pressurant gas exits the tank and at the boundary between the
liquid and gas in the form of evaporation. Heat transfer occurs
between all three control volumes as well as with the surroundings.
In summary, the physical processes modelled for a blow down tank are
%
\begin{compactenum}
    \item Vapor pressure is a function of liquid temperature.
    \item Liquid density is a function of liquid temperature.
    \item Heat transfer between the liquid and gas.
    \item Heat transfer between the tank wall and gas.
    \item Heat transfer between the tank wall and liquid.
    \item Heat transfer between the surroundings and tank.
    wall.
\end{compactenum}
%
The assumptions made in the tank model are
%
\begin{compactenum}
    \item Pressurant does not dissolve in liquid ($m_g = C$).
    \item Vapor and gas temperatures are equal.
    \item Vapor and gas volumes are equal.
\end{compactenum}
%
\begin{figure}[ht]
\centerline{
    \begin{picture}(100,510)
    \special{psfile= ./Images/BlowDownTankWVap.eps hoffset= -120 voffset= 170
    hscale=55 vscale=55}
    \makebox(80,525){$\dot{m}_e$,$h_l$}
    \makebox(-80,970){1.Gas/Vapor}
    \makebox(-90,940){$m_g, m_v, P_g, P_v, T_g$}
    \makebox(-190,905){$\dot{Q}_v$}
    \makebox(-140,905){$\dot{m}_v, h_{v}$}
    \makebox(10,905){$\dot{Q}_g$}
    \makebox(-135,820){2.Liquid}
    \makebox(-145,790){$m_\ell, T_\ell$}
    \makebox(-235,740){$\dot{Q}_\ell$}
    \makebox(-335,990){3.Tank Wall}
    \makebox(-335,970){$m_w, T_w$}
    \makebox(-265,1030){$\dot{Q}_w$}
    \end{picture}}\vskip -3.65 in  \caption{ Blow Down Tank Diagram} \label{fig:BlowDownTank}
\end{figure}

Assume we are given $m_g$, the tank diameter $D$, and hence know the
total tank volume $V_t$, and we know the physical constants
associated with the liquid and gas ($R_g$, $c_g$, $\nu_g$, $c_\ell$,
$\nu_\ell(T_\ell)$ and $P_v(T_\ell))$. We choose the state variables
$m_\ell$, $T_\ell$, $T_g$, and $T_w$, all other tank properties can
be calculated from these state variables using the following
equations:
%
\begin{eqnarray}
    V_\ell & = &  \nu_\ell(T_\ell)m_\ell \label{Eq:BlowDownVell}\\
   %
    V_g & = &  V_t - V_\ell\\
   %
   P_g & = &  \frac{m_g R_g T_g}{V_g}\\
   %
   P_v & = &  P_v(T_\ell)\\
   %
   m_v & = & \frac{P_v V_g}{R_v T_g}\\
   %
   P_t & = &  P_v + P_g \label{Eq:BlowDownPt}
\end{eqnarray}

%
To determine the state equations governing $m_\ell$, $T_\ell$,
$T_g$, and $T_w$ we apply the 1st law of thermodynamics and the law
of conservation of mass. The 1st Law applied to the gas control
volume is
%
\begin{equation}
   \frac{d}{dt}\left( m_v u_v + m_g u_g \right) = \dot{Q}_v + \dot{Q}_g - P_t \dot{V}_g +
    \dot{m}_v h_{v} \label{Eq:BlowdownGas1stLaw}
\end{equation}
%
The 1st Law applied to the liquid control volume is
%
\begin{equation}
   \frac{d}{dt}\left( m_\ell u_\ell \right) = \dot{Q}_\ell - \dot{Q}_v +
   P_t \dot{V}_g - \dot{m}_v h_{lg} - \dot{m}_e h_\ell \label{Eq:BlowdownLiquid1stLaw}
\end{equation}
%
The 1st Law applied to the wall control volume yields
%
\begin{equation}
     \frac{d}{dt}\left( m_w u_w \right) = \dot{Q}_w - \dot{Q}_\ell - \dot{Q}_g \label{Eq:BlowdownWall1stLaw}
\end{equation}
%
and finally from conservation of mass:
%
\begin{equation}
    \dot{m}_\ell = -\dot{m}_e - \dot{m}_v \label{Eq:BlowdownMassCon}
\end{equation}
%
we also know that
%
\begin{equation}
    \dot{m}_v = \frac{P_v \dot{V}_g}{R_v T_g} - \frac{P_v V_g \dot{T}_g}{R_v T_g^2} \label{Eq:BlowDownGasLaw}
\end{equation}
%
where we assume that
%
\begin{equation}
   \dot{P}_v \approx 0
\end{equation}

Equations (\ref{Eq:BlowdownGas1stLaw}) - (\ref{Eq:BlowDownGasLaw})
are five equations in five unknowns ($m_v$, $m_\ell$, $T_\ell$,
$T_g$, and $T_w$). Our approach is to use
Eq.~(\ref{Eq:BlowdownMassCon}) to eliminate $\dot{m}_v$ terms.  The
result is a system of four equations in four unknowns using
Eqs.~(\ref{Eq:BlowdownGas1stLaw}), (\ref{Eq:BlowdownLiquid1stLaw}),
(\ref{Eq:BlowdownWall1stLaw}), and (\ref{Eq:BlowDownGasLaw}).  The
result we seek is four decoupled ordinary differential equations for
$m_\ell$, $T_\ell$, $T_g$, and $T_w$.

Let's continue with Eq.~(\ref{Eq:BlowdownGas1stLaw}).  We need to
rewrite the equation in terms of $\dot{m}_\ell$ and $\dot{T}_g$
($\dot{T_w}$ and $\dot{T}_\ell$ don't appear explicitly).  Expanding
the derivatives assuming $\dot{m}_g = 0$ yields
%
\begin{equation}
   \dot{m}_v c_v T_g + m_v c_v \dot{T}_g +  m_g c_g \dot{T}_g = \dot{Q}_v + \dot{Q}_g - P_t \dot{V}_g + \dot{m}_v h_{v}
\end{equation}
%
Now, substituting $\dot{m}_v = -\dot{m}_\ell - \dot{m}_e$ and noting
that $\dot{V}_g = -\nu_l \dot{m}_\ell$ if we assume
%
 \[\dot{\nu}_\ell = \frac{d \nu_\ell}{dT_\ell }\dot{T}_\ell
\approx 0
\]
%
we arrive at
%
\begin{equation}
   \begin{split}
      \left( T_g R_v - P_t \nu_\ell  \right) \dot{m}_\ell + \left( m_v c_v + m_g c_g\right)\dot{T}_g = \\
      \dot{Q}_v + \dot{Q}_g - \dot{m}_e T_g R_v   \label{Eq:BlowdownWVaporEq1}
   \end{split}
\end{equation}
%

Now continuing with Eq.~(\ref{Eq:BlowdownLiquid1stLaw}) expanding
the derivatives and making similar substitutions as we made
previously we obtain
%
\begin{equation}
\begin{split}
    \dot{m}_\ell c_\ell T_\ell + m_\ell c_\ell \dot{T}_\ell = \dot{Q}_\ell - \dot{Q}_v +
    P_t(-\nu_\ell \dot{m}_\ell) - \\ (-\dot{m}_\ell - \dot{m}_e)h_{v} - \dot{m}_e c_\ell T_\ell
\end{split}
\end{equation}
%
Grouping terms we obtain
%
\begin{equation}
\begin{split}
    ( c_\ell T_\ell  + P_t v_l - h_{v})\dot{m}_\ell + ( m_\ell c_\ell )\dot{T}_\ell = \\
    \dot{Q}_\ell - \dot{Q}_v + \dot{m}_e (h_v - c_\ell T_\ell) \label{Eq:BlowdownWVaporEq2}
\end{split}
\end{equation}

For the wall region, described by Eq.~(\ref{Eq:BlowdownWall1stLaw}),
we arrive at
\begin{equation}
     (m_w c_w) \dot{T}_w = \dot{Q}_w - \dot{Q}_\ell - \dot{Q}_g \label{Eq:BlowdownWVaporEq3}
\end{equation}

Finally, by eliminating $\dot{m}_v$ in the Gas Law shown in
Eq.~(\ref{Eq:BlowDownGasLaw}) we obtain
%
\begin{equation}
    -\dot{m}_\ell - \dot{m}_e =   \frac{P_v (-\nu_\ell \dot{m}_\ell)}{R_v T_g} - \frac{P_v V_g \dot{T}_g}{R_v T_g^2}
\end{equation}
%
Grouping terms yields the result
\begin{equation}
    \left(  1 - \frac{P_v\nu_\ell }{R_v T_g}  \right) \dot{m}_\ell - \frac{P_v V_g }{R_v T_g^2}\dot{T}_g  =  - \dot{m}_e \label{Eq:BlowdownWVaporEq4}
\end{equation}

Equations (\ref{Eq:BlowdownWVaporEq1}),
(\ref{Eq:BlowdownWVaporEq2}), (\ref{Eq:BlowdownWVaporEq3}), and
(\ref{Eq:BlowdownWVaporEq4}) are four coupled ordinary differential
equations that can be decoupled by casting them in matrix form as
follows:
%
\begin{equation}
   \left(\begin{array}{ccccccc}
   A_{11} & 0 & A_{13}  & 0 \\
    A_{21} & A_{22} & 0  & 0 \\
    0 & 0 & 0  & A_{34} \\
    A_{41} &  & A_{43}  & 0 \\
   \end{array}\right)
   %
   \left(\begin{array}{c}
    \dot{m}_\ell \\
    \dot{T}_\ell  \\
    \dot{T}_g \\
   \dot{T}_w  \\
   \end{array}\right) =
   %
   \left(\begin{array}{c}
    b_1\\
    b_2  \\
    b_3 \\
    b_4  \\
   \end{array}\right)
\end{equation}
%
where
%
\begin{eqnarray}
   A_{11}& = & T_g R_v - P_t \nu_\ell \label{Eq:BlowDownA11}\\
   %
   A_{13}& = & m_v c_v + m_g c_g\\
   %
   A_{21} & = & c_\ell T_\ell + P_t v_l - h_{v}\\
   %
   A_{22} & = & m_\ell c_\ell\\
   %
   A_{34} & = & m_w c_w\\
   %
   A_{41} & = & 1  - \nu_\ell/\nu_v\\
   %
   A_{43} & = & - m_v/T_g\\
   %
   b_1 & = & \dot{Q}_v + \dot{Q}_g - \dot{m}_e T_g R_v \label{Eq:BlowDownb1}\\
   %
   b_2 & = & \dot{Q}_\ell - \dot{Q}_v + \dot{m}_e (h_v - c_\ell T_\ell) \\
   %
   b_3 & = & \dot{Q}_w -\dot{Q}_\ell - \dot{Q}_g\\
   %
   b_4 & = & -\dot{m}_e \label{Eq:BlowDownb4}
\end{eqnarray}
%

The solution to the equations is
%
\begin{eqnarray}
  \dot{m}_\ell &=& \frac{A_{43} b_{1}-A_{13} b_{4}}{A_{11} A_{43}-A_{41} A_{13}} \label{Eq:BlowDownmdotDiffEq}\\
  %
  %\dot{T}_\ell &=& \frac{-A_{21}A_{43}b_1+ (A_{11}A_{43}-A_{41}A_{13})b_2+A_{21}A_{13}b_4}{A_{22}\left( A_{11}A_{43}-A_{41}A_{13}\right)}\\
  \dot{T}_\ell &=& \frac{1}{A_{22}}\left( b_2 -  A_{21} \frac{A_{43} b_{1}-A_{13} b_{4}}{A_{11} A_{43}-A_{41} A_{13}}\right)\\
  %
  \dot{T}_g &=& \frac{A_{11} b_{4} - A_{41} b_{1}}{A_{11} A_{43}-A_{41} A_{13}}\\
  %
  \dot{T}_w &=& \frac{b_3}{A_{34}} \label{Eq:BlowDownTwdotDiffEq}
\end{eqnarray}
%
For the adiabatic model we set all heat transfer rates, $\dot{Q}$,
to zero in Eqs.~(\ref{Eq:BlowDownb1})-(\ref{Eq:BlowDownb4}) and so
there are only two state variables as $\dot{T}_w = 0$ and so $T_w =$
constant.

Now let's develop equations for an isothermal model of a blow down
tank.  In the isothermal model, we assume $T_\ell = T_g = T_w = T$.
The only state variable that requires a differential equation is
$m_\ell$.  Because $T_g$, $T_\ell$, and hence, $P_v$ are constant,
we know that
%
\begin{equation}
    \dot{m}_v = \frac{P_v \dot{V}_g}{R_v T_g}
\end{equation}
%
Subtituting this result into Eq.(\ref{Eq:BlowdownMassCon}) and
solving for $\dot{m}_\ell$ we obtain.
%
\begin{equation}
    \dot{m}_\ell = -\frac{\dot{m}_e}{\left( 1 - \displaystyle\frac{P_v \nu_\ell}{R_v T}\right)}
\end{equation}

In summary for the heat transfer model for a blow down tank, we
choose $m_\ell$, $T_\ell$, $T_g$, and $T_w$ are state variables.
Eqs.~(\ref{Eq:BlowDownVell})-(\ref{Eq:BlowDownPt}) are used to
calculate the remaining tank properties, and
Eqs.~(\ref{Eq:BlowDownmdotDiffEq})-(\ref{Eq:BlowDownTwdotDiffEq})
are used to model the tank states as functions of time.

For the all three models, heat transfer, adiabatic, and isothermal,
knowing the state variables $m_\ell$, $T_\ell$, $T_g$, and $T_w$ we
compute the remaining tank properties using
%
\begin{eqnarray}
    V_\ell & = &  \nu_\ell(T_\ell)m_\ell  \nonumber \\
   %
    V_g & = &  V_t - V_\ell\nonumber \\
   %
   P_g & = &  \frac{m_g R_g T_g}{V_g}\nonumber \\
   %
   P_v & = &  P_v(T_\ell)\nonumber \\
   %
   m_v & = & \frac{P_v V_g}{R_v T_g}\nonumber \\
   %
   P_t & = &  P_v + P_g \nonumber
\end{eqnarray}

%
The models differ in the number of state variables and in the state
rate equations.  A summary is presented below.

\noindent\textit{Blow Down Tank: Heat Transfer}

\noindent State Variables:  $m_\ell$, $T_\ell$, $T_g$, $T_w$
%
\begin{eqnarray}
  \dot{m}_\ell &=& \frac{A_{43} b_{1}-A_{13} b_{4}}{A_{11} A_{43}-A_{41} A_{13}}\nonumber \\
  %
  %\dot{T}_\ell &=& \frac{-A_{21}A_{43}b_1+ (A_{11}A_{43}-A_{41}A_{13})b_2+A_{21}A_{13}b_4}{A_{22}\left( A_{11}A_{43}-A_{41}A_{13}\right)}\\
  \dot{T}_\ell &=& \frac{1}{A_{22}}\left( b_2 -  A_{21} \frac{A_{43} b_{1}-A_{13} b_{4}}{A_{11} A_{43}-A_{41}
  A_{13}}\right) \nonumber \\
  %
  \dot{T}_g &=& \frac{A_{11} b_{4} - A_{41} b_{1}}{A_{11} A_{43}-A_{41}
  A_{13}} \nonumber \\
  %
  \dot{T}_w &=& \frac{b_3}{A_{34}} \nonumber
\end{eqnarray}
%
where $A_{ij}$ and $b_i$ are given by
Eqs.~(\ref{Eq:BlowDownA11})-(\ref{Eq:BlowDownb4}).

\noindent\textit{Blow Down Tank:  Adiabtic}

\noindent State Variables:  $m_\ell$, $T_\ell$, $T_g$

%
\begin{eqnarray}
  \dot{m}_\ell &=& \frac{A_{43} b_{1}-A_{13} b_{4}}{A_{11} A_{43}-A_{41} A_{13}}\nonumber \\
  %
  %\dot{T}_\ell &=& \frac{-A_{21}A_{43}b_1+ (A_{11}A_{43}-A_{41}A_{13})b_2+A_{21}A_{13}b_4}{A_{22}\left( A_{11}A_{43}-A_{41}A_{13}\right)}\\
  \dot{T}_\ell &=& \frac{1}{A_{22}}\left( b_2 -  A_{21} \frac{A_{43} b_{1}-A_{13} b_{4}}{A_{11} A_{43}-A_{41}
  A_{13}}\right) \nonumber \\
  %
  \dot{T}_g &=& \frac{A_{11} b_{4} - A_{41} b_{1}}{A_{11} A_{43}-A_{41}
  A_{13}} \nonumber
\end{eqnarray}
%
where $A_{ij}$ and $b_i$ are given by
Eqs.~(\ref{Eq:BlowDownA11})-(\ref{Eq:BlowDownb4}).  Note that all
heat flow rates, $\dot{Q}$, are set to zero.

\noindent\textit{Blow Down Tank:  Isothermal}

\noindent State Variables:  $m_\ell$
%
\begin{equation}
    \dot{m}_\ell = -\frac{\dot{m}_e}{\left( 1 - \displaystyle\frac{P_v \nu_\ell}{R_v
    T}\right)} \nonumber
\end{equation}

\subsubsection{Pressure Regulated Tank}

The pressure regulated fuel tank model is the most complex tank
model supported in GMAT.  The model complexity is due to the
presence of liquid fuel and fuel vapor contained in the tank ullage,
and due to mass and energy transfer from the pressurant tank to the
ullage of the regulated fuel tank. In this section, we develop a
state space model for a pressure regulated tank. Note, to model a
pressure regulated tank using a heat transfer or adiabitic model, we
must simultaneously solve the equations associated with the
pressurant tank.  For the regulated tank model, we choose the state
variables to be the liquid mass and temperature, $m_\ell$ and
$T_\ell$, the gas temperature $T_g$,  tank wall temperature $T_w$,
and the incoming pressurant gas mass $m_i$.

In Fig.\ref{fig:PressureRegulatedTank} we see an illustration of a
pressure regulated tank. Like the blow down tank model, we divide
the tank into three control volumes: the gas region, the liquid
region, and the tank wall region. Mass flow occurs where the
pressurant gas exits the tank, at the boundary between the liquid
and gas in the form of evaporation, and from the pressurant tank to
the ullage of the regulated tank.  Heat transfer occurs between all
three control volumes as well as with the surroundings. Hence, the
physical processes modelled for a blow down tank are the same as
those listed for the blow down tank, with the added process of mass
flow from the pressurant tank.
%
\begin{figure}[ht]
\centerline{
    \begin{picture}(100,510)
    \special{psfile= ./Images/PressureRegulatedTank.eps hoffset= -120 voffset= 170
    hscale=55 vscale=55}
    \makebox(80,525){$\dot{m}_e$,$h_l$}
    \makebox(-80,970){1.Gas/Vapor}
    \makebox(-90,940){$m_g, m_v, P_g, P_v, T_g$}
    \makebox(-190,905){$\dot{Q}_v$}
    \makebox(-140,905){$\dot{m}_v, h_{lg}$}
    \makebox(10,905){$\dot{Q}_g$}
    \makebox(-135,820){2.Liquid}
    \makebox(-145,790){$m_\ell, T_\ell$}
    \makebox(-235,740){$\dot{Q}_\ell$}
    \makebox(-335,990){3.Tank Wall}
    \makebox(-335,970){$m_w, T_w$}
    \makebox(-265,1030){$\dot{Q}_w$}
    \makebox(-045,1030){$\dot{m}_i$, $h_i$}
    \end{picture}}\vskip -3.65 in  \caption{ Pressure Regulated Tank Diagram} \label{fig:PressureRegulatedTank}
\end{figure}

The derivation of the state equations for a pressure regulated tank
follows naturally from the derivation of the blow down tank.  The
only control volume that differs between the two models is the
gas/vapor control volume.  Applying the 1st Law of thermodynamics to
the gas/vapor control volume of the pressure regulated tank gives us
%
\begin{equation}
   \frac{d}{dt}\left( m_v u_v + m_g u_g \right) = \dot{Q}_v + \dot{Q}_g - P_t \dot{V}_g +
    \dot{m}_v h_v + \dot{m}_p h_p\label{Eq:RegulatedGas1stLaw}
\end{equation}
%
Taking the time derivative of the gas law for the gas contained in
the tank ullage yields
%
\begin{equation}
   \dot{m}_g = \frac{P_g \dot{V}_g}{R_g
   T} - \frac{P_g V_g \dot{T}_g}{R_g T_g^2} \label{Eq:RegulatedGasLawDeriv}
\end{equation}
%

Equations (\ref{Eq:RegulatedGas1stLaw}) and
(\ref{Eq:RegulatedGasLawDeriv}), together with equations
(\ref{Eq:BlowdownWVaporEq2}), (\ref{Eq:BlowdownWVaporEq3}), and
(\ref{Eq:BlowdownWVaporEq4}) are a system of 5 equations in 5
unknowns which can be decoupled using simple linear algebra.
However, first we must expand Eqs.~(\ref{Eq:RegulatedGas1stLaw}) and
(\ref{Eq:RegulatedGasLawDeriv}) and write them in terms of the state
rate derivatives.  Expanding Eq.~(\ref{Eq:RegulatedGas1stLaw}) we
arrive at
\begin{equation}
   \begin{split}
   \left( R_v T_g - P_t \nu_\ell \right)\dot{m}_\ell + \left( m_v c_v + m_g c_g \right)
   \dot{T}_g + \\ \left(c_g Tg - h_p \right)\dot{m}_g = \dot{Q}_v +
   \dot{Q}_g - \dot{m}_e R_v T_g
   \end{split}
\end{equation}
%
Similarly, for Eq.~(\ref{Eq:RegulatedGasLawDeriv}) we obtain
%
\begin{equation}
    \frac{\nu_\ell}{\nu_g}\dot{m}_\ell + \frac{m_g}{T_g}\dot{T}_g + \dot{m}_g = 0
\end{equation}
%

To integrate the state equations we must decouple the equations and
this is easily done by casting the equations in matrix form and
solving the system of equations.  We can write the equations is
state space for as follows
%
\begin{equation}
   \left(\begin{array}{ccccccc}
   A_{11} & 0 & A_{13}  & 0 & A_{15}\\
    A_{21} & A_{22} & 0  & 0 & 0 \\
    0 & 0 & 0  & A_{34} & 0\\
    A_{41} & 0 & A_{43}  & 0 & 0\\
    A_{51} & 0 & A_{43}  & 0 &  A_{55}\\
   \end{array}\right)
   %
   \left(\begin{array}{c}
    \dot{m}_\ell \\
    \dot{T}_\ell  \\
    \dot{T}_g \\
   \dot{T}_w  \\
   \dot{m}_g
   \end{array}\right) =
   %
   \left(\begin{array}{c}
    b_1\\
    b_2  \\
    b_3 \\
    b_4  \\
    0
   \end{array}\right)
\end{equation}
%
where the coefficients $A_{ij}$ and $b_i$ are given by
%
\begin{eqnarray}
   A_{11}& = & T_g R_v - P_t \nu_\ell \label{Eq:RegulatedA11}\\
   %
   A_{13}& = & m_v c_v + m_g c_g\\
   %
   A_{15} & = & c_g T_g - h_p\\
   %
   A_{21} & = & c_\ell T_\ell + P_t v_l - h_{lg}\\
   %
   A_{22} & = & m_\ell c_\ell\\
   %
   A_{34} & = & m_w c_w\\
   %
   A_{41} & = & 1  - \nu_\ell/\nu_v\\
   %
   A_{43} & = & - m_v/T_g\\
   %
   A_{51} & = & \nu_\ell/\nu_g\\
   %
   A_{53} & = & m_g/T_g \\
   %
   A_{55} & = & 1 \\
   %
   b_1 & = & \dot{Q}_v + \dot{Q}_g - \dot{m}_e R_v T_g \label{Eq:Regulatedb1}\\
   %
   b_2 & = & \dot{Q}_\ell - \dot{Q}_v + \dot{m}_e (h_{lg} - c_\ell T_\ell)\\
   %
   b_3 & = & \dot{Q}_w -\dot{Q}_\ell - \dot{Q}_g\\
   %
   b_4 & = & -\dot{m}_e \label{Eq:Regulatedb4}
\end{eqnarray}

\begin{eqnarray}
   \dot{m}_\ell &=& \frac{A_{55} A_{43} b_1 - b_4 A_{13} A_{55} + b_4 A_{15} A_{53}}{D}\\
   \dot{T}_\ell &=& \frac{b_2 - A_{21}\dot{m}_\ell}{A_{22}}\\
   %
   \dot{T}_g  &=& \frac{-A_{41} A_{55} b_1 + b_4 A_{11} A_{55} - b_4 A_{51}
    A_{15}}{D}\\
   %
   \dot{T}_w &=& \frac{b_3}{A_{34}}\\
   %
   \dot{m}_g &=& \frac{-b_1 A_{51} A_{43} + b_1 A_{41} A_{53} - b_4 A_{11} A_{53} + b_4 A_{51} A_{13}}{D}
\end{eqnarray}
%
where
%
\begin{equation}
      D = A_{55} A_{43} A_{11} - A_{43} A_{51} A_{15} + A_{41} A_{15} A_{53} - A_{41} A_{13} A_{55}
\end{equation}

For the adiabatic model we set all heat transfer rates, $\dot{Q}$,
to zero in  Eqs.~(\ref{Eq:Regulatedb1})-(\ref{Eq:Regulatedb4}). For
the adiabatic model there is only four state variables as $\dot{T}_w
= 0$ and so $T_w =$ constant.

Now let's develop equations for an isothermal model of a pressure
regulated tank. In the isothermal model, we assume $T_\ell = T_g =
T_w = T$. The only state variables that require differential
equations are $m_\ell$ and $m_g$. Because $T_g =$ constant, and
hence, $P_v =$ constant, we know that
%
\begin{equation}
    \dot{m}_\ell = -\frac{\dot{m}_e}{\left( 1 - \displaystyle\frac{P_v \nu_\ell}{R_v
    T}\right)}
\end{equation}
%
Similarly, for $m_g$ we obtain
%
\begin{equation}
   \dot{m}_g = \frac{\nu_\ell}{\nu_g}\frac{\dot{m}_e}{\left( 1 - \displaystyle\frac{P_v \nu_\ell}{R_v
    T}\right)}
\end{equation}

\subsubsection{Heat Transfer}

Heat transfer models are from Ring\cite{Ring:64} and
Incropera\cite{Incropera:06} and Pitts\cite{Pitts:98}

\begin{equation}
    \dot{Q} = h A \Delta T
\end{equation}

\begin{equation}
    \frac{h L}{k} = Nu = c(Gr_L Pr)^a
\end{equation}
%
so
%
\begin{equation}
       h = \frac{k c}{L}(Gr_L Pr)^a
\end{equation}
\begin{table}[ht]
\centering \caption{ Dimensionless Heat Transfer Terms
\cite{Incropera:06}}
\begin{tabular}{p{.65 in} p{.950 in} p{1.4 in}}
  \hline\hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  Parameter & Definition & Interpretation \\
  \hline
  Grashof number ($Gr_L$) & \hspace{ 1 in} $\displaystyle\frac{g \beta(T_s - T_\infty)L^3}{\nu^2}$  & Measure of the ratio of buoyancy forces to viscous forces.\\
  %
  & \\
  %
  Prandtl number ($Pr$) & \hspace{ 1 in} $\displaystyle\frac{c \mu}{k} = \frac{\mu}{\alpha}$  & Ratio of the momentum and thermal diffusivities.\\
  %
  & \\
  %
  Nusselt number ($Nu_L$) & \hspace{ 1 in} $\displaystyle\frac{h L}{k_f}$ & Ratio of convection to pure conduction heat transfer.  \\
  %
  & \\
  %
  Reynolds number ($Re_L$) & \hspace{ 1 in} $\displaystyle\frac{V L}{\nu}$ & Ratio of inertia and viscous forces.  \\
  \hline
\end{tabular}
\end{table}

\subsubsection{ Physiochemical Properties }

Hydrazine Properties \cite{HydraBook}
\[
c = 3084 \mbox{J/kg/K}
\]
\[
\rho \mbox{ (kg/m}^3) = 1025.6 - 0.87415 \mbox{ }T \mbox{ }(^o\mbox{C})- 0.45283e^{-3}\mbox{ }T^2 \mbox{ }(^o\mbox{C})
\]
%
\[
\rho \mbox{ (kg/m}^3) = 1230.6 - 0.62677 \mbox{ }T \mbox{ }(^o\mbox{K})- 0.45283e^{-3}\mbox{ }T^2 \mbox{ }(^o\mbox{K})
\]

Some models are from \cite{Ricciardi:87}

\begin{eqnarray}
  \rho_\ell(T_\ell) & = &K_1 + K_2 T_\ell + K_3 T_\ell^2
  \mbox{  (kg/m$^3$)}\\
  %
  \frac{d \rho_\ell}{dT_\ell } &  = & K_2 + 2K_3 T_\ell
  \mbox{  (kg/m$^3$)}
\end{eqnarray}
%
\begin{eqnarray}
  P_v & =  &\displaystyle C_1 e^{(C_2 + C_3 T_\ell + C_4 T_\ell^2)} \mbox{
  (N/m$^2$)}\\
  %
  \frac{d P_v}{d T_\ell}& = &\displaystyle C_1 ln{(C_2 + C_3 T_\ell C_4 T_\ell^2)}\left(C_3 + 2C_4T_\ell\right)
\end{eqnarray}
%
\begin{equation}
    m_d = P_g m_\ell^\alpha\left( \frac{T_\ell}{294}\right)^2
\end{equation}
%
\begin{equation}\begin{split}
    \frac{d m_d}{dt} =  m_\ell^\alpha\left(
    \frac{T_\ell}{294}\right)^2\dot{P}_g + \alpha P_g m_\ell^{(\alpha - 1)}\left(
    \frac{T_\ell}{294}\right)^2 \dot{m}_\ell \\ + 2 P_g m_\ell^\alpha\left(
    \frac{T_\ell}{294}\right)\dot{T}_\ell
    \end{split}
\end{equation}
%

\begin{table} \centering
\caption{Constants for Density Equations}
\begin{tabular}{lcc}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  Const. & \mbox{N}$_2$\mbox{0}$_4$ & CH$_3$N$_2$H$_3$ \\
  \hline \hline
  $K_1$ (kg/m$^3$) & 2066 & 1105.3 \\
  $K_2$ (kg/m$^3$/K )& -1.979 & -0.9395 \\
  $K_3$ (kg/m$^3$/K$^2) $ & -4.826e-4 & 0 \\
  \hline
\end{tabular}
\end{table}

\begin{table} \centering
\caption{Constants for Vapor Pressure Equations}
\begin{tabular}{lcc}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  Const. & \mbox{N}$_2$\mbox{0}$_4$ & CH$_3$N$_2$H$_3$ \\
  \hline \hline
  $C_1$ (kg/m$^3$) & 6895 & 6895\\
  $C_2$ (kg/m$^3$/K )& 18.6742 & 12.4293 \\
  $C_3$ (kg/m$^3$/K$^2) $ & -5369.57 & 2543.37 \\
  $C_4$ (kg/m$^3$/K$^2) $ & 194721 & 0 \\
  \hline
\end{tabular}
\end{table}

\begin{table} \centering
\caption{Constants for Dissolved Pressurant Equations}
\begin{tabular}{lcc}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  Const. & \mbox{N}$_2$\mbox{0}$_4$ & CH$_3$N$_2$H$_3$ \\
  \hline \hline
  $\alpha$ & 3.335e-11 & 2.059e-11 \\
  \hline
\end{tabular}
\end{table}


\documentclass[12pt]{article}
\usepackage{times}
\usepackage{indentfirst}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{float}
\usepackage{amsmath}
\graphicspath{ {./img/} }
%Setup the layout of the pages
\topmargin 0.0cm
\oddsidemargin 0.2cm
\textwidth 16cm
\textheight 21cm
\footskip 1.0cm

\title{
    Machine Learning Review\\
}
\author{Molin Liu}

\begin{document}

\maketitle

\section*{Introduction}

This is a review work for the Machine Learning course in
\textit{Univeristy of Glasgow}.

\section{Regression}

\subsection{Linear Regression}

For $x = (x_1, x_2, ..., x_m)$,
where $x_i$ is the $i_{th}$ attribute of $x$,
a lenear model tries to train a linear combination function
from these attributes, i.e:
$$f(x) = w_1 x_1 + w_2 x_2 +...+ w_m x_m+b$$
which can be written in vector as:
$$f(x)=w^Tx+b$$
where $w=(w_1, w_2,...,w_m)$.

The linear regression model is trained by \textit{loss function}.
Generally, we define our \textit{loss function} as:
$$min\sum_{i=1}^{m}{(y_i-f(x_i))^2}$$

\subsubsection{Loss Function}

There are several kinds of \textit{loss functions} we can choose from.

- \textbf{L1-norm}: L1-norm can be represented as follow:
$$S=\sum_{i=1}^{m}\left|y_{i}-f\left(x_{i}\right)\right|$$

- \textbf{L2-norm}: L2-norm is what we used above:
$$S=\sum_{i=1}^{m}\left(y_{i}-f\left(x_{i}\right)\right)^{2}$$

\subsubsection{Least Square Solution}
The solution of \textbf{Least Square} is:
$$
\vec{w}=\left(X^{\top} X\right)^{-1} X^{\top} Y
$$

\textbf{Prove:}

The error vector $(Y-X \vec{w})$ should be orthogonal to every column of $X$:
$$
(Y-X \vec{w}) \cdot X_{j}=0
$$

which can be written as a matrix equation:
$$
(Y-X \vec{w})^{\top} X=\overrightarrow{0}
$$

Then we can easily derive the equation from the following process:
$$
\begin{aligned} X^{\top}(Y-X \vec{w}) &=X^{\top} Y-X^{\top} X \vec{w}=0 \\ \Longrightarrow &\left(X^{\top} X\right) \vec{w}=X^{\top} Y \\ \Longrightarrow \quad \vec{w}=\left(X^{\top} X\right)^{-1} X^{\top} Y \end{aligned}
$$
\subsubsection{Conclusion}

\subsection{Polynomial Regression}

The \textbf{Polynomial Regression} can be written as:
$$
t=w_{0}+w_{1} x+w_{2} x^{2}+w_{3} x^{2}+\ldots+w_{K} x^{K}=\sum_{k=0}^{\kappa} w_{k} x^{k}
$$

Define the loss funcion:
$$
\mathcal{L}=\frac{1}{N}(\mathbf{t}-\mathbf{X} \mathbf{w})^{\top}(\mathbf{t}-\mathbf{X} \mathbf{w})
$$
\subsubsection{Generalization \& Overfitting}

We can find out that the \textbf{loss} will always decrease
as the model is made more complex.

How to choose the right model complexity?
\textbf{Cross-validation}

\subsubsection{Cross-Validation}

\section{Classification}

The \textbf{Classification} task is to classify
a set of \textit{N} objects $x_i$ with attributes.
Each object has an associated label $t_i$

\textbf{Probabilistic classifier} produce a probability of class membership:

$P(t_{\text {new}}=k | \mathbf{x}_{\text {new }}, \mathbf{X}, \mathbf{t})$

\textbf{non-Probabilistic classifier} produce a hard assignment:

$t_{new}=1$ or $t_{new}=0$

\subsection{KNN}

K-Nearest Neighbours(KNN)

- Non-probabilistic classifier;

- Supervised trainning;

- Fast;

- We can use CV to find the right $K$;

\subsubsection{Problem}
- As $K$ increases, the small classes will disppear.

\subsection{Logistic Regression}

\subsection{SVM}
\subsubsection{Hard Margin}
If the training data is linearly seperable,
we can select two parallel hyperplanes that separate the two classes of data,
so that the distance between them is as large as possible.

These hyperplanes can be described by the equations:
$$
\vec{w} \cdot \vec{x}_{i}-b \geq 1, \text { if } y_{i}=1
$$
or
$$
\vec{w} \cdot \vec{x}_{i}-b \leq-1, \text { if } y_{i}=-1
$$

We can easily infer that
$$
y_{i}\left(\vec{w} \cdot \vec{x}_{i}-b\right) \geq 1, \quad \text { for all } 1 \leq i \leq n
$$

We want to maximise $\gamma=\frac{1}{\|\mathbf{w}\|}$,
equivalent to minimising $\|\mathbf{w}\|$

Note: $y_i$ is the label in the data, which is in $\{-1, 1\}$,
rather than vertical axis value of the data.
\begin{figure}[H]
    \center
    \includegraphics{img/600px-SVM_margin.png}
    \caption{Hard margin}
    \label{fig:svm_hard_margin}
\end{figure}

\subsubsection{Soft Margin}
Soft-margin function for the data are not linearly seperable.

\subsubsection{Inner Product}

\section{ROC}
Sensitivity/Recall

$$
S_{e}=\frac{T P}{T P+F N}
$$

Specificity

$$
S_{p}=\frac{T N}{T N+F P}
$$

\section{Unsupervised Learning}
\subsection{K-Means}

\subsection{Gaussion Mixture Model}
\end{document}