\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{enumerate}
\usepackage{ifthen}
\usepackage{ulem} % for strikethrough \sout{...} command
\usepackage{color}
\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{-0.5in}
\setlength{\headheight}{0.0in}
\setlength{\headsep}{0.0in}
\setlength{\topskip}{0.0in}
\setlength{\textheight}{9.45in}
\setlength{\textwidth}{7.5in}


\usepackage{tikz,pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta}

\newcommand{\bdot}{\, {\scriptstyle{\bullet}} \,}
\newcommand{\B}[1]{{\bf {#1}}}
\newcommand{\la}{\langle}
\newcommand{\ra}{\rangle}

\newcommand{\myspace}{\parbox[c][0.2in]{0.2in}{\hfill}}
\newcommand{\varspace}[2]{\mbox{\parbox[c][#1]{#2}{\hfill}}}
\newcommand{\force}{{$\mbox{\,\!}$}}

\begin{document}

%\pagestyle{empty}

\noindent
\parbox{2in}{\bf Math 2240}
\hfill {\Large \bf Homework \#1} \hfill
\parbox{2in}{\bf \hfill Due: Fri., Sept. 5${}^\mathbf{th}$\!,\  2025}

%\vspace{0.2in}

\force \hfill {\bf Be sure to show your work!} \hfill \force

\vspace{0.05in}

\noindent
{\it Notes:} 
\begin{itemize}
\item You can copy/paste my {\color{red}sample code} into Maple. If you prefer to do computations using different software (like Sage), that is fine, but \underline{make sure you turn in {\it all} of your work} (including computer code).
\item If you end up doing the entire assignment in Maple, feel free to turn in a Maple worksheet (.mw file) instead of a pdf. 
\item Don't try to do this stuff in a calculator or by hand.\\ \force \hfill A calculator is a poor choice since I want {\it exact} answers not decimal approximations.
\end{itemize}

\vspace{0.15in}

\noindent {\bf\large 1.} Basic matrix operations. 

\vspace{0.1in}

\noindent 
{\color{red}
\verb# restart; #\\
\verb# with(LinearAlgebra): #\\
\verb# A := <<1|2|3|4|5>,<6|7|8|9|10>,<11|12|13|14|15>,<16|17|18|19|20>,<21|22|23|24|25>>; #\\
\verb# B := <<1,0,1,0,1>|<0,-1,0,-1,0>|<1,1,1,1,1>|<-1,-1,-1,-1,-1>|<5,4,3,2,1>>; #
}

\vspace{0.1in}

\noindent
This will result in\dots

\vspace{-0.15in}

{\color{blue}
$$A := \begin{bmatrix} 1 &  2 &  3 &  4 &  5 \\
                        6 &  7 &  8 &  9 & 10\\
                      11 & 12 & 13 & 14 & 15\\
                      16 & 17 & 18 & 19 & 20\\
                      21 & 22 & 23 & 25 & 25 \end{bmatrix}
      \quad \mathrm{\color{black}and} \quad
 B := \begin{bmatrix} 1 & 0 & 1 & -1 & 5 \\ 0 & -1 & 1 & -1 & 4 \\ 1 & 0 & 1 & -1 & 3 \\ 0 & -1 & 1 & -1 & 2 \\ 1 & 0 & 1 & -1 & 1 
      \end{bmatrix}$$
}

\vspace{0.05in}

\noindent
Notice that in Maple, matrices are either entered row by row or column by column.\\ \force \hfill The ``$|$'' (on the keyboard a pipe is shift $\backslash$) moves over a column and ``,'' (comma) moves down a row.

\vspace{0.05in}

\begin{enumerate}[(a)]
\item Compute $(AB)^5\left(\left(6I_5-B\right)^{-2}\right)^T$ where $I_5$ is the $5\times 5$ identity matrix.
\item Compute the reduced row echelon form of $B$.
\end{enumerate}

\vspace{0.1in}

\noindent {\bf\large 2.} Consider the follow linear system:

$$\begin{array}{rcrcrcrcrcr}
        &  & -3x_2 & + & x_3 & + & x_4 &  - & 2x_5 & = & -1 \\ 
2x_1 & + & x_2 & + & 2x_3 & + & x_4 &  + & x_5 & = & 0 \\ 
 x_1 &    &  & + & 3x_3 &  & &  + & x_5 & = & 6 \\ 
 &  & 4x_2 & + & 2x_3 & - & x_4 &  + & 4x_5 & = & -5 \\ 
-2x_1 & + & x_2 & + & x_3 & - & x_4 &  + & 2x_5 & = & 2 
\end{array}$$

\noindent
Here's code for creating a vector ${\bf x}$ of variables\\ \force \hfill (I'll include the code to wipe memory and load the linear algebra package as well):

\vspace{0.1in}

\noindent 
{\color{red}
\verb# restart; #\\
\verb# with(LinearAlgebra): #\\
\verb# X := <x[1],x[2],x[3],x[4],x[5]>; #\\
}

\vspace{0.1in}

\noindent
Note that my vector of variables is a capital X whereas the variables themselves are lowercase x's. If we are doing this in Maple, we can define our coefficient matrix $A$ by ``{\color{red}\verb#A := <# stuff \verb#>;#}'' and constant term by ``{\color{red}\verb#b := <# stuff \verb#>;#}''. Then the command ``{\color{red}\verb#A.X=b;#}'' would display the system. 

\begin{enumerate}[(a)]

\item Create an augmented matrix $[A\;:\;{\bf b}]$, find its RREF (use software not by hand), and read off the system's solution.

{\it Note:} As long as sizes are compatible, Maple can create a new matrix block-by-block from old matrices. For example, ``{\color{red}\verb#<A|B>#}'' slaps B next to A and ``{\color{red}\verb#<A,B>#}'' puts B below A. We would want ``{\bf \color{red}\verb#<A|b>;#}'' for our system.

\item It turns out that $A$ is invertible. Find $A^{-1}$. Then use the inverse to once again solve our system: $A{\bf x}={\bf b}$.
\end{enumerate}

\newpage

\noindent {\bf\large 3.} Balancing Chemical Equations. We begin with an example: 

The amount of various substances created or consumed by chemical reactions can be determined by solving linear systems. For example, when propane gas burns, the propane ($C_3H_8$ = 3 carbon and 8 hydrogen atoms) combines with oxygen ($O_2$ = 2 oxygen atoms) to form carbon dioxide ($CO_2$ = 1 carbon and 2 oxygen atoms) and water ($H_2O$ = 2 hydrogen and 1 oxygen atoms). The number of propane and oxygen molecules going in must be comprised of the same number of various types of atoms as the carbon dioxide and water coming out of this reaction.

Let $x_1$ be the number of propane molecules, $x_2$ the number of oxygen molecules, $x_3$ the number of carbon dioxide molecules, and $x_4$ the number of water molecules. We write this reaction as $(x_1)C_3H_8 + (x_2)O_2 \rightarrow (x_3)CO_2 + (x_4)H_2O$. Focusing on the carbon, we have $3x_1+0x_2$ carbon atoms going in and $1x_3+0x_4$ carbon atoms coming out of this process. Looking at hydrogen, we have $8x_1+0x_2$ atoms in and $0x_3+2x_4$ atoms out. Finally, considering oxygen, we have $0x_1+2x_2$ atoms in and $2x_3+1x_4$ atoms out. In this chemical reaction, atoms are neither created nor destroyed, so we must have: $3x_1+0x_2=1x_3+0x_4$, $8x_1+0x_2=0x_3+2x_4$, and $0x_1+2x_2=2x_3+1x_4$. Translating into standard form then an augmented matrix, we have:

\vspace{-0.2in}

$$\begin{bmatrix} 3 & 0 & -1 & 0 & : & 0 \\ 8 & 0 & 0 & -2 & : & 0 \\ 0 & 2 & -2 & -1 & : & 0 \end{bmatrix} \sim \begin{bmatrix} 1 & 0 & 0 & -1/4 & : & 0 \\ 0 & 1 & 0 & -5/4 & : & 0 \\ 0 & 0 & 1 & -3/4 & : & 0 \end{bmatrix}$$

The RREF reveals: $x_1-\frac14x_4=0$, $x_2-\frac54x_4=0$, and $x_3-\frac34x_4=0$. Thus $x_4=t$ is free with $x_1=\frac14t$, $x_2=\frac54t$, and $x_3=\frac34t$. While there are infinitely many solutions to this system, only solutions consisting of non-negative integers make sense (we need whole number quantities of molecules). Also, we will follow the convention of choosing the minimal non-trivial solution (i.e., the solution consisting of positive integers). In particular, $t=4$ does just this giving $x_1=1$, $x_2=5$, $x_3=3$, and $x_4=4$. In other words, in this reaction, {\it for every propane molecule paired with five oxygen molecules going in, our reaction outputs three carbon dioxide and four water molecules.} We write: 

\vspace{-0.15in}

\force\hfill\hfill \fbox{$\displaystyle C_3H_8+5O_2 \rightarrow 3CO_2+4H_2O$} \hfill\force

\vspace{0.1in}

{\bf Problem:} As in the example above, balance the following chemical equation: $$??MnS+??As_2Cr_{10}O_{35}+??H_2SO_4 \rightarrow ??HMnO_4+??AsH_3+??CrS_3O_{12}+??H_2O$$

\vspace{0.05in}

{\it Note:} $Mn$ is manganese, $S$ is sulfur, $As$ is arsenic, $Cr$ is chromium, $O$ is oxygen, and $H$ is hydrogen. For example, $HMnO_4$ is permanganic acid. A molecule of this acid consists of one hydrogen, one manganese, and four oxygen atoms. 

\vspace{0.05in}

Write down equations, put them in standard form, translate to a matrix, find its RREF, write down the general solution, and then find the minimum positive integer solution and record the balanced equation. {\it Show this work!}

\vspace{0.1in}

\noindent {\bf\large 4.} Traffic Flow. 

\vspace{0.1in}

\noindent
\begin{minipage}{4in}
Consider the diagram to the right. This represents traffic flowing in and out of several intersections (labeled A, B, C, and D). Suppose that our numbers represent cars per minute. We must have the same number of cars entering and exiting our intersections at any particular moment of time. For example: At intersection B we must have $200=x_1+x_2$ since we have 200 cars per minute flowing in with $x_1$ cars per minute heading toward intersection A and $x_2$ cars per minute heading toward intersection C.
\end{minipage}

\vspace{-1.5in}

\force\hfill
\begin{tikzpicture}[scale=0.75,
    intersection/.style={circle, fill=black, inner sep=3pt},
    traffic/.style={-{Stealth[length=3mm]}, thick, blue},
    flow_label/.style={font=\footnotesize, black},
    node_label/.style={font=\small, black}
]

% Define intersection points (arranged as in the original diagram)
\node[intersection] (A) at (0, 2) {};
\node[intersection] (B) at (2, 5) {};
\node[intersection] (C) at (7, 2) {};
\node[intersection] (D) at (3, 0) {};

% Label intersections
\node[node_label, above left] at (A) {A};
\node[node_label, above right] at (B) {B};
\node[node_label, below right] at (C) {C};
\node[node_label, below right] at (D) {D};

% Flows
\draw[traffic] (A) -- (-1.5, 2) node[flow_label, midway, above] {40};
\draw[traffic] (2, 6.5) -- (B) node[flow_label, midway, above right] {200};
\draw[traffic] (C) -- (8.5, 2) node[flow_label, midway, above left, xshift=2pt] {100};
\draw[traffic] (D) -- (3, -1.5) node[flow_label, midway, left] {60};

% Internal network flows (variables)
\draw[traffic] (B) -- (A) node[flow_label, midway, above, sloped] {$x_1$};
\draw[traffic] (B) -- (C) node[flow_label, midway, above, sloped] {$x_2$};
\draw[traffic] (A) -- (C) node[flow_label, midway, above, yshift=1pt] {$x_3$};
\draw[traffic] (A) -- (D) node[flow_label, midway, below, sloped] {$x_4$};
\draw[traffic] (C) -- (D) node[flow_label, midway, above, sloped] {$x_5$};

\end{tikzpicture}

\begin{enumerate}[(a)]
\item Write down a system of equations describing the flow of traffic. Put this system into standard form and translate to an augmented matrix. Then solve this system and write down a general solution.
\item Suppose the road from intersection A to intersection D is closed. Specialize the general solution to this situation. In this case, what is the minimum possible $x_1$ value?

{\it Note:} We assume that the traffic must flow in the direction indicated by the arrow in each diagram. In other words, in a valid solution, the variables should not take on negative values.
\end{enumerate}



\end{document}

