\documentclass{article}
\input{../macros.tex}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{Lecture 12:  Graphs, networks, incidence matrices}

When we use linear algebra to understand physical systems, we often find more structure in the matrices and vectors than appears in the examples we make up in class.  There are many applications of linear algebra; for
example, chemists might use row reduction to get a clearer picture of
what elements go into a complicated reaction.  In this lecture we explore the linear algebra associated with electrical networks.

\subsection*{Graphs and networks}

A {\em graph} is a collection of nodes joined by edges;
Figure~\ref{fig:l12_g1} shows one small graph.
\begin{figure}[h]
\centering
  \mypic{../Images/lec12fig1}\\
  \caption{A graph with $n=4$ nodes and $m=5$ edges.}\label{fig:l12_g1}
\end{figure}

We put an arrow on each edge to indicate the positive direction for
currents running through the graph.
\begin{figure}[h]
\centering
  \mypic{../Images/lec12fig2}\\
  \caption{The graph of Figure~\ref{fig:l12_g1} with a direction on each edge.}\label{fig:l12_g2}
\end{figure}

\subsection*{Incidence matrices}

The {\em incidence matrix} of this directed graph has one column for each node of the graph
and one row for each edge of the graph:
$$\mb A = \left[ \begin{array}{rrrr}
-1 & 1 & 0 & 0\\
0 & -1 & 1 & 0\\
-1 & 0 & 1 & 0\\
-1 & 0 & 0 & 1\\
0 & 0 & -1 & 1
\end{array}\right].$$
If an edge runs from node $a$ to node $b$, the row corresponding to
that edge has $-1$ in column $a$ and $1$ in column $b$; all other
entries in that row are $0$.  If we were studying a larger graph we
would get a larger matrix but it would be {\em sparse}; most of the
entries in that matrix would be $0$.  This is one of the ways matrices arising from applications might have extra structure.

Note that nodes $1, 2$ and $3$ and edges \ding{172}, \ding{173} and
\ding{174} form a loop.  The matrix describing just those nodes and edges
looks like:
$$\left[ \begin{array}{rrrr}
-1 & 1 & 0 & 0\\
0 & -1 & 1 & 0\\
-1 & 0 & 1 & 0\\
\end{array}\right].$$
Note that the third row is the sum of the first two rows; loops in the
graph correspond to linearly dependent rows of the matrix.

To find the nullspace of $\mb A$, we solve $\mb A \vb x = \vb 0$:
$$\mb A \vb x = 
\left[ \begin{array}{r}
x_2-x_1\\ x_3-x_2\\ x_3-x_1\\ x_4-x_1\\ x_4-x_3
\end{array}\right]
=
\left[ \begin{array}{r}
0\\ 0\\ 0\\ 0\\ 0
\end{array}\right].$$
If the components $x_i$ of the vector $\vb x$ describe the electrical
potential at the nodes $i$ of the graph, then $\mb A \vb x$ is a
vector describing the {\em difference} in potential across each edge
of the graph.  We see $\mb A \vb x = \vb 0$ when $x_1 = x_2 = x_3 =
x_4$, so the nullspace has dimension $1$.  In terms of an electrical
network, the potential difference is zero on each edge if each node
has the same potential.  We can't tell what that potential is by
observing the flow of electricity through the network, but if one node
of the network is grounded then its potential is zero.  From that we
can determine the potential of all other nodes of the graph.

The matrix has $4$ columns and a $1$ dimensional nullspace, so its
rank is $3$.  The first, second and fourth columns are its pivot
columns; these edges connect all the nodes of the graph without
forming a loop -- a graph with no loops is called a {\em tree}.

The left nullspace of $\mb A$ consists of the 
solutions $\vb y$ to the equation: $\mb A^T \vb y = \vb 0$.  Since
$\mb A^T$ has $5$ columns and rank $3$ we know that the dimension of
$N(\mb A^T)$ is $m-r = 2$.  Note that $2$ is the number of loops in
the graph and $m$ is the number of edges.  The rank $r$ is $n-1$,
one less than the number of nodes.  This gives us
$\mbox{\# loops} = \mbox{\# edges} - (\mbox{\#
  nodes} - 1)$, or:
$$\mbox{number of nodes} - \mbox{number of edges} + \mbox{number of loops} = 1.$$
This is Euler's formula for
connected graphs.

\subsection*{Kirchhoff's law}

\begin{figure}[h]
\centering
  \mypic{../Images/lec12fig3}\\
  \caption{The currents in our graph.}\label{fig:l12_g3}
\end{figure}

In our example of an electrical network, we started with the
potentials $x_i$ of the nodes.  The matrix
$\mb A$ then told us something about potential differences.  An engineer
could create a matrix $\mb C$ using Ohm's law and information about
the conductance of the edges and use that matrix to determine the current $y_i$ on each edge.  Kirchhoff's Current Law then says that $\mb A^T \vb y = \vb 0$,
where $\vb y$ is the vector with components $ y_1, y_2, y_3, y_4,
y_5$.
Vectors in the nullspace of $\mb A^T$ correspond to collections of currents that
satisfy Kirchhoff's law.

\begin{figure}[h]
$$\begin{array}{ccc}
\vb x = x_1, x_2, x_3, x_4 & & \mb A^T \vb y = 0\\
\mbox{potentials at nodes} & & \mbox{Kirchhoff's Current Law}\\
\\
\vb e = \mb A \vb x\downarrow & & \uparrow \mb A^T \vb y \\
\\
x_2 - x_1, \mbox{etc.} & \vb y = \mb C \vb e & y_1, y_2, y_3, y_4, y_5\\
\mbox{potential differences} & \longrightarrow & \mbox{currents on edges}\\
& \mbox{Ohm's Law} & \\
\end{array}$$
\end{figure}

Written out, $\mb A^T \vb y = \vb 0$ looks like:
$$\left[ \begin{array}{rrrrr}
-1 & 0 & -1 & -1 & 0\\
1 & -1 & 0 & 0 & 0\\
0 & 1 & 1 & 0 & -1\\
0 & 0 & 0 & 1 & 1
\end{array}\right]
\left[ \begin{array}{r}
y_1\\
y_2\\
y_3\\
y_4\\
y_5
\end{array}\right]
=
\left[ \begin{array}{r}
0\\
0\\
0\\
0
\end{array}\right].$$
Multiplying the first row by the column vector $\vb y$ we get $-y_1 -
y_3 - y_4 = 0$.
  This tells us that the total current flowing out of
node $1$ is zero -- it's a balance equation, or a conservation law.
Multiplying the second row by $\vb y$ tells us $y_1 - y_2 = 0$; the
current coming into node $2$ is balanced with the current going out.  Multiplying the bottom rows, we get $y_2 + y_3 - y_5 = 0$ and $y_4 + y_5 = 0$.

We could use the method of elimination on $\mb A^T$ to find its column space, but we already know the rank.  To get a basis for $N(\mb
A^T)$ we just need to find two independent vectors in this space.  Looking at the equations $y_1 - y_2 = 0$ we might guess $y_1 =
y_2 = 1$.  Then we could use the conservation laws for node $3$  to guess $y_3 = -1$ and $y_5 = 0$.  We satisfy the 
conservation conditions on node $4$ with $y_4 = 0$, giving us a basis vector
$\left[ \small \begin{array}{r}1 \\ 1 \\ -1 \\ 0
    \\ 0 \end{array}\right]$.  This vector represents one unit of
current flowing around the loop joining nodes $1$, $2$ and $3$; a
multiple of this vector represents a different amount of current
around the same loop.

We find a second basis vector for $N(\mb A^T)$ by looking at the loop formed by nodes $1$, $3$ and $4$: $\left[
  \small \begin{array}{r}0 \\ 0 \\ 1 \\ -1 \\ 1 \end{array}\right]$.
The vector $\left[ \small \begin{array}{r}1 \\ 1 \\ 0 \\ -1
    \\ 1 \end{array}\right]$ that represents a current around the
outer loop is also in the nullspace, but it is the sum of the first
two vectors we found.

\bigskip

We've almost completely covered the mathematics of simple circuits.  More complex
circuits might have batteries in the edges, or current sources between
nodes.  Adding current sources changes the $\mb A^T \vb y = \vb 0$ in
Kirchhoff's current law to $\mb A^T \vb y = \vb f$.  Combining the equations $\vb e = \mb A \vb x$, $\vb y = \mb C \vb e$ and $\mb A^T \vb y = \vb f$ gives us:
$$\mb A^T \mb C \mb A \vb x = \vb f.$$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
