More Systems of Linear Equations

A resource for review

The glossary from the end of Strand: glossary.pdf

Intuitions about RRE form

Systems with non-unique solutions

Solve for the variables \(x, y\), and \(z\) in the system

\[ \begin{aligned} z & =2 \\ x+y+z & =2 \\ 2 x+2 y+4 z & =8 \end{aligned} \]

. . .

Make an augmented matrix: Example 1.20. Solve for the variables \(x, y\), and \(z\) in the system

\[ \left[\begin{array}{llll} 0 & 0 & 1 & 2 \\ 1 & 1 & 1 & 2 \\ 2 & 2 & 4 & 8 \end{array}\right] \]

. . .

\[ \left[\begin{array}{llll} 0 & 0 & 1 & 2 \\ 1 & 1 & 1 & 2 \\ 2 & 2 & 4 & 8 \end{array}\right] \stackrel{E_{12}}{\longrightarrow}\left[\begin{array}{llll} (1 & 1 & 1 & 2 \\ 0 & 0 & 1 & 2 \\ 2 & 2 & 4 & 8 \end{array}\right] \xrightarrow[E_{31}(-2)]{\longrightarrow}\left[\begin{array}{rlll} 1 & 1 & 1 & 2 \\ 0 & 0 & 2 & 4 \\ 0 & 0 & 1 & 2 \end{array}\right] \]

We keep on going… \[ \begin{aligned} & {\left[\begin{array}{rrrr} (1) & 1 & 1 & 2 \\ 0 & 0 & 2 & 4 \\ 0 & 0 & 1 & 2 \end{array}\right] \xrightarrow[E_{2}(1 / 2)]{\longrightarrow}\left[\begin{array}{rrrr} 1 & 1 & 1 & 2 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 1 & 2 \end{array}\right]} \\ & \overrightarrow{E_{32}(-1)}\left[\begin{array}{rrrr} (1) & 1 & 1 & 2 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 0 & 0 \end{array}\right] \xrightarrow[E_{12}(-1)]{\longrightarrow}\left[\begin{array}{rrrr} (1) & 1 & 0 & 0 \\ 0 & 0 & 1 & 2 \\ 0 & 0 & 0 & 0 \end{array}\right] . \end{aligned} \]

There’s still no information on \(y\).

\[ \begin{aligned} & x=-y \\ & z=2 \\ & y \text { is free. } \end{aligned} \]

Free versus bound variables

Suppose we have another augmented matrix, which after GJ elimination has become:

\[ \left[\begin{array}{rrrrr} x & y & z & w & \mathrm{rhs} \\ 1 & 2 & 0 & -1 & 2 \\ 0 & 0 & 1 & 3 & 0 \\ 0 & 0 & 0 & 0 & 0 \end{array}\right] . \]

. . .

Solutions are: \[ \begin{aligned} x+2 y-w & =2 \\ z+3 w & =0 . \end{aligned} \]

How can we tell from looking at the matrix which variables are free vs bound?

Columns which contain pivots correspond to bound variables. The others correspond to free variables.

(Columns with pivots are called “basic” columns.)

Zero solutions

Solve this system… \[ \begin{array}{r} x+y=1 \\ 2 x+y=2 \\ 3 x+2 y=5 . \end{array} \]

. . .

\[ \left[\begin{array}{lll} 1 & 1 & 1 \\ 2 & 1 & 2 \\ 3 & 2 & 5 \end{array}\right] \xrightarrow[E_{21}(-2)]{E_{31}(-3)}\left[\begin{array}{lrl} 1 & 1 & 1 \\ 0 & -1 & 0 \\ 0 & -1 & 2 \end{array}\right] \xrightarrow[E_{32}(-1)]{\longrightarrow}\left[\begin{array}{rrr} 1 & 1 & 1 \\ 0 & -1 & 0 \\ 0 & 0 & 2 \end{array}\right] \]

. . .

System is inconsistent.

Consistency

For an augmented matrix in RREF, if the only only nonzero entry in a row appears on the right-hand side,

\[\text { Row } i \longrightarrow\left( \begin{array}{cccccc|c} * & * & * & * & * & * & * \\ 0 & 0 & 0 & * & * & * & * \\ 0 & 0 & 0 & 0 & * & * & * \\ 0 & 0 & 0 & 0 & 0 & 0 & \alpha \\ \bullet & \bullet & \bullet & \bullet & \bullet & \bullet & \bullet \\ \bullet & \bullet & \bullet & \bullet & \bullet & \bullet & \bullet \end{array} \right) \longleftarrow \alpha \neq 0 \]

the \(i^{\text {th }}\) equation of the associated system is

\[ 0 x_{1}+0 x_{2}+\cdots+0 x_{n}=\alpha . \]

If \(\alpha\ne 0\), this has no solution!

This is an inconsistent system.

What Reduced Row Echelon Form tells us

Suppose a matrix \(A_{m \times n}\) has a reduced row echelon form \(E_{m \times n}\): \[ E_A=\left(\begin{array}{cccccccc}1 & * & 0 & 0 & * & * & 0 & * \\ 0 & 0 & 1 & 0 & * & * & 0 & * \\ 0 & 0 & 0 & 1 & * & * & 0 & * \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & * \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right)\]

Which variables are free and bound

Suppose a matrix \(A_{m \times n}\) has a reduced row echelon form \(E_{m \times n}\): \[ E_A=\left(\begin{array}{cccccccc}1 & * & 0 & 0 & * & * & 0 & * \\ 0 & 0 & 1 & 0 & * & * & 0 & * \\ 0 & 0 & 0 & 1 & * & * & 0 & * \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & * \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right)\]

“Basic columns” correspond to the columns in \(A\) which contain the pivotal positions.

Each non-basic column can be formed as a sum of the basic columns to the left.

Basic columns are the same in \(E\) and \(A\)!

Rank

Suppose a matrix \(A_{m \times n}\) has a reduced row echelon form \(E_{m \times n}\): \[ E_A=\left(\begin{array}{cccccccc}1 & * & 0 & 0 & * & * & 0 & * \\ 0 & 0 & 1 & 0 & * & * & 0 & * \\ 0 & 0 & 0 & 1 & * & * & 0 & * \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & * \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right)\]

rank(\(A\)) = # of pivots = # of nonzero rows in \(E\) = # bound variables in the system

Nullity

Suppose a matrix \(A_{m \times n}\) has a reduced row echelon form \(E_{m \times n}\): \[ E_A=\left(\begin{array}{cccccccc}1 & * & 0 & 0 & * & * & 0 & * \\ 0 & 0 & 1 & 0 & * & * & 0 & * \\ 0 & 0 & 0 & 1 & * & * & 0 & * \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & * \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\end{array}\right)\]

nullity(\(A\)) = # of non-pivot columns = # free variables in the system

Consistency

Equivalent ways of saying \(A\) is consistent:

  • In row reducing \([\mathbf{A} \mid \mathbf{b}]\), a row of the following form never appears:

. . . \[ \left(\begin{array}{llll|l} 0 & 0 & \cdots & 0 & \alpha \tag{2.3.2} \end{array}\right) \text {, where } \alpha \neq 0 \text {. } \]

  • \(\operatorname{rank}[\mathbf{A} \mid \mathbf{b}]=\operatorname{rank}(\mathbf{A})\), in which case either:

    • \(\operatorname{rank}[\mathbf{A}=n\), and system has a unique solution or
    • \(\operatorname{rank}[\mathbf{A}<n\), and system has infinite solutions
  • \(\mathbf{b}\) is a nonbasic column in \([\mathbf{A} \mid \mathbf{b}]\).

  • \(\mathbf{b}\) is a combination of the basic columns in \(\mathbf{A}\).

Meyers p. 51

Homogeneous Systems

  • The general linear system with \(m \times n\) coefficient matrix \(A\) and right-hand-side vector \(\mathbf{b}\) is homogeneous if the entries of \(\mathbf{b}\) are all zero.

  • Otherwise, the system is inhomogeneous.

  • Homogeneous systems are always consistent!

  • Can solve by setting all variables to zero. This is the trivial solution

  • If rank of the matrix = n, there is only the trivial solution

Example + tutorial: Pagerank

Pagerank

Goal: rank pages in terms of “importance”. Suppose we have four pages:

How can we rank these pages? Which one is most important?

Working through PageRank: try 3

\[ \begin{equation*} x_{i}=\sum_{x_{j} \in L_{i}} \frac{x_{j}}{n_{j}} \end{equation*} \]

Write down the system of equations this gives us. Then make it in an augmented matrix.

JupyterLab

https://tinyurl.com/stat24320notebook1

Now what about the second try?

Remember this was our ‘second try’: \[ \begin{equation*} x_{i}=\sum_{x_{j} \in L_{i}} x_{j} \end{equation*} \]

This was the system of equations. \[ \begin{aligned} & x_{1}=x_{2}+x_{3} \\ & x_{2}=x_{1}+x_{3} \\ & x_{3}=x_{1}+x_{4} \\ & x_{4}=x_{3} . \end{aligned} \]

What happens if we try to solve this? Try it in Python.

Diffusion

Discretizing continuous functions

  • Rod with fixed temperatures \(y_{left}\) and \(y_{right}\) at each end, internal heat source given as \(f(x), 0 \leq x \leq 1\)

  • What’s the temperature at each point along the length?

Discrete approximation to temperature function (n=5)

Discrete approximation to temperature function \((n=5)\)

. . .

Equations to balance the flow of heat from each node to its neighbors:

\[ \begin{equation*} -y_{i-1}+2 y_{i}-y_{i+1}=\frac{h^{2}}{K} f\left(x_{i}\right) \end{equation*} \]


Suppose:

  • rod of material with \(K=1\) on x-axis, for \(0 \leq x \leq 1\).
  • known internal heat source \(f(x)\)
  • left and right ends of the rod are held at \(0{ }^{\circ} \mathrm{C}\) (degrees Celsius)
  • \(n=5\) nodes

. . .

What are the discretized steady-state equations?

. . .

\[ \begin{array}{lllllr} 2 y_{1}&-y_{2} & & & & =f(1 / 6) / 36 \\ -y_{1}&+2 y_{2}&-y_{3} & & & =f(2 / 6) / 36 \\ &-y_{2}&+2 y_{3}&-y_{4} & & =f(3 / 6) / 36 \\ &&-y_{3}&+2 y_{4}&-y_{5} & =f(4 / 6) / 36 \\ &&&-y_{4}&+2 y_{5} & =f(5 / 6) / 36 \end{array} \]

Build the matrix representing the system of equations:

N=6
M = sym.zeros(N)
for i in range(N):
  if (i>0):
      M[i-1,i]=-1
  M[i,i]=2
  if (i<N-1):
      M[i+1,i]=-1
M

\(\displaystyle \left[\begin{matrix}2 & -1 & 0 & 0 & 0 & 0\\-1 & 2 & -1 & 0 & 0 & 0\\0 & -1 & 2 & -1 & 0 & 0\\0 & 0 & -1 & 2 & -1 & 0\\0 & 0 & 0 & -1 & 2 & -1\\0 & 0 & 0 & 0 & -1 & 2\end{matrix}\right]\)

\[ \begin{equation*} -y_{i-1}+2 y_{i}-y_{i+1}=\frac{h^{2}}{K} f\left(x_{i}\right) \end{equation*} \]

Decide on a function for f. Let’s say \(\frac{h^{2}}{K} f = x_i^2\).

Say that x is running from 0 to 1. Then we can have

import numpy as np
x=np.arange(0,1,1/N)
f=x**2
x=sym.Matrix(x)
f=sym.Matrix(f)

sol=M.gauss_jordan_solve(f)
sol[0]

\(\displaystyle \left[\begin{matrix}0.416666666666667\\0.833333333333333\\1.22222222222222\\1.5\\1.52777777777778\\1.11111111111111\end{matrix}\right]\)

Now you

  1. Implement this yourself in Python
  2. Make a plot of the output (you’ll want to use PyPlot)
  3. Increase N and make more plots
  4. This was assuming the temperature at the ends was 0. How can we change this?

Reaction-Diffusion in Biology

Turing pattern formation

https://colab.research.google.com/github/ijmbarr/turing-patterns/blob/master/turing-patterns.ipynb#scrollTo=GsEPBsz33E14