\documentclass[11pt]{article}
\usepackage{graphicx,fancyhdr,setspace,longtable}
\usepackage{pdflscape}
\usepackage[left=2cm,top=1cm,right=3cm,nohead,nofoot]{geometry}
%\pagestyle{fancy}
%\fancyhead[R]{Perapon Fakcharoenphol}
\usepackage{amsmath}
\setlength\topmargin{0in}
\setlength\headheight{0in}
\setlength\headsep{0in}
\setlength\textheight{7.7in}
\setlength\textwidth{6.5in}
\setlength\oddsidemargin{0in}
\setlength\evensidemargin{0in}
\setlength\parindent{0.25in}
\setlength\parskip{0.25in} 
\setlength\footskip{0.25in}
%\doublespacing
%\setlength\footheight{0.25in}
\begin {document}

\begin{center}
\section*{PEGN 624A: Compositional Modeling\\
					Homework 2}
\textbf{submitted by Perapon Fakcharoenphol}
\end{center}

Given Equation
\begin{multline}\label{mass}
\nabla\cdot\left[\bar{\bar{k}}\{X_c\xi_o\lambda_o\left(\nabla P_o-\gamma_o\nabla D\right)+Y_c\xi_g\lambda_g\left(\nabla P_g-\gamma_g\nabla D\right)+W_c\xi_w\lambda_w\left(\nabla P_w-\gamma_w\nabla D\right)\}\right] \\
+\left(X_c\xi_o\hat{q_o}+Y_c\xi_g\hat{q_g}+W_c\xi_w\hat{q_w}\right)=\frac{\partial}{\partial t}\left[\phi\left(X_c\xi_oS_o+Y_c\xi_gS_g+W_c\xi_wS_w\right)\right]
%)
\end{multline}

Given Component
\begin{table}[htbp]
	\centering
	%\caption{Given Component}
	\label{tab:comp}
\begin{tabular}{cc} 
\hline
Component No. & Description \\[1.0ex]
\hline \hline
1 & $CH_4$ \\ [1.0ex]
2 & $n-C_4H_{10}$ \\ [1.0ex]
3 & $n-C_{10}H_{20}$ \\ [1.0ex]
4 & $H_2O$ \\ 
\hline %inserts single line
\end{tabular}
\end{table}

Constitutive Relationship
$$\xi_o=f(P_o,\vec{X})$$
$$\xi_g=f(P_o,\vec{Y})$$
$$\xi_w=f(P_o)$$
$$G_i=f(P_o,\vec{X},\vec{Y})$$
$$P_w=P_o-P_{cow}$$
$$P_g=P_o+P_{cgo}$$
where $\vec{X}=[X_1,X_2,X_3]^T$ and $\vec{Y}=[Y_1,Y_2,Y_3]^T$, i=1,2,3 
\newpage
\renewcommand\theenumi{\alph{enumi}}
\begin{enumerate}
	\item Expand the left-hand-side of each component equation	\\
	
	\input {LHS.tex}
	\newpage
	\item Expand the right-hand-side of each component equation. There will be some partial derivatives you can't evaluate further without other relationships. 
	
	\input {RHS.tex}
	\newpage
	\item Expand the thermodynamic constraints in the same way as the right-hand-side component equation. There will be some partial derivatives you can't evaluate further without other relationships.
	
	Recall thermodynamics constraints $G_c=f_c^o-f_c^g=0$
	\begin{equation}\label{G}
		\begin{array}{cl}
			G_c^{n+1} & = G_c^l+\left(\frac{\partial G_c}{\partial P_o}\right)^l\delta P_o+\sum_{i=1}^2\left(\left(\frac{\partial G_c}{\partial X_i}\right)^l\delta X_i+\left(\frac{\partial G_c}{\partial Y_i}\right)^l\delta Y_i\right)\\
			\\
			& = G_c^l+\left(\frac{\partial G_c}{\partial P_o}\right)^l\delta P_o+\left(\frac{\partial G_c}{\partial X_1}\right)^l\delta X_1+\left(\frac{\partial G_c}{\partial X_2}\right)^l\delta X_2+\left(\frac{\partial G_c}{\partial Y_1}\right)^l\delta Y_1+\left(\frac{\partial G_c}{\partial Y_2}\right)^l\delta Y_2
		\end{array}
	\end{equation}
	
	\item Write the incident matrix equation (using X's) for a 5-node system.\\

	Substitute Left-Hand-Side (Eq \ref{mass_LHS}) and Right-Hand-Side (Eq \ref{mass_RHS1},\ref{mass_RHS2}  or \ref{mass_RHS3}) into Mass-Balance Equation (Eq \ref{mass})

	\begin{equation}\label{mass_matrix}
	\left[\begin{array}{cc}
	D_{C_c,P_o}\delta P_{o,i-1}+F_{C_c,P_o}\delta P_{o,i+1}+E_{C_c,P_o}\delta P_{o,i}+E_{C_c,S_o}\delta S_{o,i}\\
		+E_{C_c,S_g}\delta S_{g,i}+\sum_{j=1}^2\left(E_{C_c,X_j}\delta X_{j,i}+E_{C_c,Y_j}\delta Y_{j,i}\right)
		\end{array}\right]
		=R_{C_c}
	\end{equation}

	where,
	
	%\begin{table}[thbp]
		%\begin{tabular}{ll}
	\begin{longtable}{ll}	
			$D_{C_c,P_o,i}$ & = $T^{n}_{xoc,{i-\frac{1}{2}}}+T^{n}_{xgc,{i-\frac{1}{2}}}+T^{n}_{xwc,{i-\frac{1}{2}}}$\\
			\\
			$F_{C_c,P_o,i}$ & = $T^{n}_{xoc,{i+\frac{1}{2}}}+T^{n}_{xgc,{i+\frac{1}{2}}}+T^{n}_{xwc,{i+\frac{1}{2}}}$\\
			\\
			$E_{C_c,P_o,i}$ & = $-\left(D_{C_c,P_o,i}+F_{C_c,P_o,i}+\phi\frac{V_R}{\Delta t}\left(X_cS_o\left(c_\phi\xi_o+\frac{\partial \xi_o}{\partial P_o}\right)+Y_cS_g\left(c_\phi\xi_g+\frac{\partial \xi_g}{\partial P_o}\right)+W_cS_w\left(c_\phi\xi_w+\frac{\partial \xi_w}{\partial P_o}\right)\right)^l_i\right)$\\
			\\
			$E_{C_c,S_o,i}$ & = $-\phi\frac{V_R}{\Delta t}\left(X_c\xi_o-W_c\xi_w\right)_i^l$\\
			\\
			$E_{C_c,S_g,i}$ & = $-\phi\frac{V_R}{\Delta t}\left(Y_c\xi_g-W_c\xi_w\right)_i^l$\\
			\\
			$E_{C_c,X_1,i}$ & = $\left\{\begin{array}{lr} -\phi\frac{V_R}{\Delta t} S_o^l\left(\xi_o+X_1\frac{\partial \xi_o}{\partial X_1}\right)_i^l & for,c=1\\
												-\phi\frac{V_R}{\Delta t} S_o^l \left(X_2\frac{\partial \xi_o}{\partial X_1}\right)_i^l & for,c=2\\
												-\phi\frac{V_R}{\Delta t} S_o^l \left(\left(1-X_1-X_2\right)\frac{\partial \xi_o}{\partial X_1}-\xi_o\right)^l_i & for,c=3\end{array}\right\}$\\
			\\
			$E_{C_c,X_2,i}$ & = $\left\{\begin{array}{lr} -\phi\frac{V_R}{\Delta t} S_o^l\left(X_1\frac{\partial \xi_o}{\partial X_2}\right)_i^l & for,c=1\\
												-\phi\frac{V_R}{\Delta t} S_o^l \left(\xi_o+X_2\frac{\partial \xi_o}{\partial X_2}\right)_i^l & for,c=2\\
												-\phi\frac{V_R}{\Delta t} S_o^l \left(\left(1-X_1-X_2\right)\frac{\partial \xi_o}{\partial X_2}-\xi_o\right)^l_i & for,c=3\end{array}\right\}$\\
			\\
			$E_{C_c,Y_1,i}$ & = $\left\{\begin{array}{lr} -\phi\frac{V_R}{\Delta t} S_g^l\left(\xi_g+Y_1\frac{\partial \xi_g}{\partial Y_1}\right)_i^l & for,c=1\\
												-\phi\frac{V_R}{\Delta t} S_g^l \left(Y_2\frac{\partial \xi_g}{\partial Y_1}\right)_i^l & for,c=2\\
												-\phi\frac{V_R}{\Delta t} S_g^l \left(\left(1-Y_1-Y_2\right)\frac{\partial \xi_g}{\partial Y_1}-\xi_g\right)^l_i & for,c=3\end{array}\right\}$\\
			\\
			$E_{C_c,Y_2,i}$ & = $\left\{\begin{array}{lr} -\phi\frac{V_R}{\Delta t} S_g^l\left(Y_1\frac{\partial \xi_g}{\partial Y_2}\right)_i^l & for,c=1\\
												-\phi\frac{V_R}{\Delta t} S_g^l \left(\xi_g+Y_2\frac{\partial \xi_g}{\partial Y_2}\right)_i^l & for,c=2\\
												-\phi\frac{V_R}{\Delta t} S_g^l \left(\left(1-Y_1-Y_2\right)\frac{\partial \xi_g}{\partial Y_2}-\xi_g\right)^l_i & for,c=3\end{array}\right\}$\\
		%\end{tabular}
	%\end{table}
	\\
	%\begin{table}[t]
		%\begin{tabular}{ll}
	$R_{C_c,i}$ & = $\left\{\begin{array}{ll}-\left[\begin{array}{cc}\left(T^{n}_{xoc,{i+\frac{1}{2}}}+T^{n}_{xgc,{i+\frac{1}{2}}}+T^{n}_{xwc,{i+\frac{1}{2}}}\right)\left(P^{l}_{o,i+1}-P^{l}_{o,i}\right)\\
	-\left(T^{n}_{xoc,{i-\frac{1}{2}}}+T^{n}_{xgc,{i-\frac{1}{2}}}+T^{n}_{xwc,{i-\frac{1}{2}}}\right)\left(P^{l}_{o,i}-P^{l}_{o,i-1}\right)\end{array}\right]\\
	\\
	-\left[T^{n}_{xgc,{i+\frac{1}{2}}}\left(P^{n}_{cgo,i+1}-P^{n}_{cgo,i}\right)-T^{n}_{xgc,{i-\frac{1}{2}}}\left(P^{n}_{cgo,i}-P^{n}_{cgo,i-1}\right)\right]\\
	\\
	+\left[T^{n}_{xwc,{i+\frac{1}{2}}}\left(P^{n}_{cow,i+1}-P^{n}_{cow,i}\right)-T^{n}_{xwc,{i-\frac{1}{2}}}\left(P^{n}_{cow,i}-P^{n}_{cow,i-1}\right)\right]\\
	\\
	+\left[\begin{array}{cc}\left((T\gamma)^{n}_{xoc,{i+\frac{1}{2}}}+(T\gamma)^{n}_{xgc,{i+\frac{1}{2}}}+(T\gamma)^{n}_{xwc,{i+\frac{1}{2}}}\right)\left(D_{i+1}-D_{i}\right)\\
	-\left((T\gamma)^{n}_{xoc,{i-\frac{1}{2}}}+(T\gamma)^{n}_{xgc,{i-\frac{1}{2}}}+(T\gamma)^{n}_{xwc,{i-\frac{1}{2}}}\right)\left(D_{i}-D_{i-1}\right)\end{array}\right]\\
	\\
	-\left(X_c\xi_oq_o+Y_c\xi_gq_g+W_c\xi_wq_w\right)^n+\phi\frac{V_R}{\Delta t}\left(A_c^l-A_c^n\right)	
			\end {array}\right\}$\\
	%\end{tabular}
	\end{longtable}
	
\newpage
\begin{landscape}

\newenvironment{changemargin}[2]{\begin{list}{}{
         \setlength{\topsep}{0pt}\setlength{\leftmargin}{0pt}
         \setlength{\rightmargin}{0pt}
         \setlength{\listparindent}{\parindent}
         \setlength{\itemindent}{\parindent}
         \setlength{\parsep}{0pt plus 1pt}
         \addtolength{\leftmargin}{#1}\addtolength{\rightmargin}{#2}
         }\item }{\end{list}}

\begin{changemargin}{-1cm}{-1cm}
{\tiny{
\begin{equation}\label{eq:matrix_fm}
%\left[\begin{array}{rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr}
\left[\begin{array}{ccccccc ccccccc ccccccc ccccccc ccccccc}
% grid 1
X&X&X&X&X&X&X& &X&&&&&& &&&&&&& &&&&&&& &&&&&& \\
X&X&X&X&X&X&X&  &X&&&&&& &&&&&&& &&&&&&& &&&&&& \\
X&X&X&X&X&X&X&  &X&&&&&& &&&&&&& &&&&&&& &&&&&& \\
&X&X&X&&&& &X&&&&&& &&&&&&& &&&&&&& &&&&&& \\
X&X&&&X&X&X& &&&&&&& &&&&&&& &&&&&&& &&&&&& \\
X&X&&&X&X&X& &&&&&&& &&&&&&& &&&&&&& &&&&&& \\
X&X&&&X&X&X& &&&&&&& &&&&&&& &&&&&&& &&&&&& \\
% grid 2
&X&&&&&& X&X&X&X&X&X&X& &X&&&&&& &&&&&&& &&&&&& \\
&X&&&&&& X&X&X&X&X&X&X&  &X&&&&&& &&&&&&& &&&&&& \\
&X&&&&&& X&X&X&X&X&X&X&  &X&&&&&& &&&&&&& &&&&&& \\
&X&&&&&& &X&X&X&&&& &X&&&&&& &&&&&&& &&&&&& \\
&&&&&&& X&X&&&X&X&X& &&&&&&& &&&&&&& &&&&&& \\
&&&&&&& X&X&&&X&X&X& &&&&&&& &&&&&&& &&&&&& \\
&&&&&&& X&X&&&X&X&X& &&&&&&& &&&&&&& &&&&&& \\
% grid 3
&&&&&&& &X&&&&&& X&X&X&X&X&X&X& &X&&&&&& &&&&&&\\
&&&&&&& &X&&&&&& X&X&X&X&X&X&X&  &X&&&&&& &&&&&&\\
&&&&&&& &X&&&&&& X&X&X&X&X&X&X&  &X&&&&&& &&&&&&\\
&&&&&&& &X&&&&&& &X&X&X&&&& &X&&&&&& &&&&&&\\
&&&&&&& &&&&&&& X&X&&&X&X&X& &&&&&&& &&&&&&\\
&&&&&&& &&&&&&& X&X&&&X&X&X& &&&&&&& &&&&&&\\
&&&&&&& &&&&&&& X&X&&&X&X&X& &&&&&&& &&&&&&\\
% grid 4
&&&&&&& &&&&&&& &X&&&&&& X&X&X&X&X&X&X& &X&&&&&\\
&&&&&&& &&&&&&& &X&&&&&& X&X&X&X&X&X&X&  &X&&&&&\\
&&&&&&& &&&&&&& &X&&&&&& X&X&X&X&X&X&X&  &X&&&&&\\
&&&&&&& &&&&&&& &X&&&&&& &X&X&X&&&& &X&&&&&\\
&&&&&&& &&&&&&& &&&&&&& X&X&&&X&X&X& &&&&&&\\
&&&&&&& &&&&&&& &&&&&&& X&X&&&X&X&X& &&&&&&\\
&&&&&&& &&&&&&& &&&&&&& X&X&&&X&X&X& &&&&&&\\
% grid 5
&&&&&&& &&&&&&& &&&&&&& &X&&&&&& X&X&X&X&X&X&X\\
&&&&&&& &&&&&&& &&&&&&& &X&&&&&& X&X&X&X&X&X&X\\
&&&&&&& &&&&&&& &&&&&&& &X&&&&&& X&X&X&X&X&X&X\\
&&&&&&& &&&&&&& &&&&&&& &X&&&&&& &X&X&X&&&\\
&&&&&&& &&&&&&& &&&&&&& &&&&&&& X&X&&&X&X&X\\
&&&&&&& &&&&&&& &&&&&&& &&&&&&& X&X&&&X&X&X\\
&&&&&&& &&&&&&& &&&&&&& &&&&&&& X&X&&&X&X&X\\
\end {array}\right]
\left[\begin{array}{l}
\delta X_{2,1}\\
\delta P_{o,1}\\
\delta S_{o,1}\\
\delta S_{g,1}\\
\delta X_{1,1}\\
\delta Y_{1,1}\\
\delta Y_{2,1}\\
\delta X_{2,2}\\
\delta P_{o,2}\\
\delta S_{o,2}\\
\delta S_{g,2}\\
\delta X_{1,2}\\
\delta Y_{1,2}\\
\delta Y_{2,2}\\
\delta X_{2,3}\\
\delta P_{o,3}\\
\delta S_{o,3}\\
\delta S_{g,3}\\
\delta X_{1,3}\\
\delta Y_{1,3}\\
\delta Y_{2,3}\\
\delta X_{2,4}\\
\delta P_{o,4}\\
\delta S_{o,4}\\
\delta S_{g,4}\\
\delta X_{1,4}\\
\delta Y_{1,4}\\
\delta Y_{2,4}\\
\delta X_{2,5}\\
\delta P_{o,5}\\
\delta S_{o,5}\\
\delta S_{g,5}\\
\delta X_{1,5}\\
\delta Y_{1,5}\\
\delta Y_{2,5}
\end {array}\right]
=\left[\begin{array}{l}
R_{C1,1}\\
R_{C2,1}\\
R_{C3,1}\\
R_{W,1}\\
0\\
0\\
0\\
R_{C1,2}\\
R_{C2,2}\\
R_{C3,2}\\
R_{W,2}\\
0\\
0\\
0\\
R_{C1,3}\\
R_{C2,3}\\
R_{C3,3}\\
R_{W,3}\\
0\\
0\\
0\\
R_{C1,4}\\
R_{C2,4}\\
R_{C3,4}\\
R_{W,4}\\
0\\
0\\
0\\
R_{C1,5}\\
R_{C2,5}\\
R_{C3,5}\\
R_{W,5}\\
0\\
0\\
0
\end {array}\right]
\end {equation}}}
\begin{center}
Incident Matrix for $5\times 1\times 1$ system
\end {center}
\end{changemargin}
\end{landscape}

\end{enumerate}


\end {document}
