Prev: W5 Next: W7

📗 Tuesday lectures: 4:00 to 4:50, Zoom, TopHat: Link (or Google Form: Form if TopHat not working). MATLAB.
📗 Programming Homework: P3

Slide:


# System of Two Equations

📗 \(\begin{cases} m_{11} x_{1} + m_{12} x_{2} = b_{1} \\ m_{21} x_{1} + m_{22} x_{2} = b_{2} \\ \end{cases}\) is a system of two equations and two unknowns \(x_{1}\) and \(x_{2}\).
📗 The system can be written in matrix form: \(\begin{bmatrix} m_{11} & m_{12} \\ m_{21} & m_{22} \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \end{bmatrix} = \begin{bmatrix} b_{1} \\ b_{2} \end{bmatrix}\).
📗 The system may have 0, 1, or infinite number of solutions.
➩ \(\begin{bmatrix} 1 & 2 \\ 3 & 6 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \end{bmatrix} = \begin{bmatrix} 4 \\ 5 \end{bmatrix}\) has no solution.
➩ \(\begin{bmatrix} 1 & 2 \\ 3 & 6 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \end{bmatrix} = \begin{bmatrix} 4 \\ 12 \end{bmatrix}\) has infinite number of solutions, \(x = \begin{bmatrix} 4 - 2 t \\ t \end{bmatrix}\) for any real number \(t\).
➩ \(\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \end{bmatrix} = \begin{bmatrix} 5 \\ 11 \end{bmatrix}\) has a unique solution \(\begin{bmatrix} 1 \\ 2 \end{bmatrix}\).
📗 In general, if \(d = m_{11} m_{22} - m_{12} m_{21} = 0\), then there are either no solution or infinite number of solutions; otherwise, there is a unique solution \(x = \dfrac{1}{d} \begin{bmatrix} m_{22} b_{1} - m_{12} b_{2} \\ m_{11} b_{2} - m_{21} b_{1} \end{bmatrix}\).
Example
Table



# Solving Two Equations

📗 [m11 m12; m21 m22] \ [b1; b2] or [b1; b2] / [m11 m12; m21 m22] solves the system \(\begin{bmatrix} m_{11} & m_{12} \\ m_{21} & m_{22} \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \end{bmatrix} = \begin{bmatrix} b_{1} \\ b_{2} \end{bmatrix}\) for \(\begin{bmatrix} x_{1} \\ x_{2} \end{bmatrix}\).
📗 The MATLAB command will always output a solution, usually close to infinity if there are none; and only output one if there are infinite number of them.
➩ There will be a warning about the matrix being singular.
TopHat Quiz
📗 Solve \(x_{1} - x_{2} = 0\) and \(x_{1} + x_{2} = 2\).
➩ A: [1 -1; 1 1] / [0; 2]
➩ B: [1 1; -1 1] / [0; 2]
➩ C: [1 -1; 1 1] \ [0; 2]
➩ D: [1 1; -1 1] \ [0; 2]


# System of Equations

📗 \(\begin{cases} m_{11} x_{1} + m_{12} x_{2} + ... + m_{1n} x_{n} = b_{1} \\ m_{21} x_{1} + m_{22} x_{2} + ... + m_{2n} x_{n} = b_{2} \\ ... \\ m_{k1} x_{1} + m_{k2} x_{2} + ... + m_{k n} x_{n} = b_{k} \\ \end{cases}\) is a system of \(k\) equations and \(n\) unknowns \(x_{1}, x_{2}, ..., x_{n}\).
📗 The system can be written in matrix form \(\begin{bmatrix} m_{11} & m_{12} & ... & m_{1n} \\ m_{21} & m_{22} & ... & m_{2n} \\ ... & ... & ... & ... \\ m_{k1} & m_{k2} & ... & m_{k n} \end{bmatrix} \begin{bmatrix} x_{1} \\ x_{2} \\ ... \\ x_{n} \end{bmatrix} = \begin{bmatrix} b_{1} \\ b_{2} \end{bmatrix} ... b_{k}\) or \(M x = b\).
📗 \(x\) can be solved by hand using Gaussian elimination. It is faster to solve for \(x\) using LU decomposition.
➩ Every matrix \(M\) can be written in the form \(P M = L U\).
➩ \(P\) is a permutation matrix (each row and each column contain one \(1\) and all other entries are \(0\)s).
➩ \(L\) is a lower triangular matrix (all entries above the diagonal are \(0\)s).
➩ \(U\) is an upper triangular matrix (all entries below the diagonal are \(0\)s).
➩ \(M x = b\) can be solved by solving \(L y = P b\) for \(y\) then solving \(U x = y\) for \(x\).
Example
📗 \(M = \begin{bmatrix} m_{11} & m_{12} \\ m_{21} & m_{22} \end{bmatrix}\) can be written as \(L U = \begin{bmatrix} 1 & 0 \\ \dfrac{m_{21}}{m_{11}} & \dfrac{1}{m_{11}} \end{bmatrix} \begin{bmatrix} m_{11} & m_{12} \\ 0 & m_{11} m_{22} - m_{12} m_{21} \end{bmatrix}\)
📗 Here \(P = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\) is the permutation matrix matrix assuming \(m_{11} \neq 0\), and if \(m_{11} = 0\), \(P = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\) can be used instead.
📗 This makes solving \(L y = b\) and \(U x = y\) very fast since only forward and backward substitutions are required.

# Solving Systems

📗 M \ b or b / M solves \(M x = b\) for \(x\).
📗 [L, U, P] = lu(M) computes the LU decomposition and y = L \ (P * b); x = U \ y also solves \(M x= b\) for \(x\).
📗 In the case \(M x = b\) needs to be solved repeatedly for the same \(M\) but different \(b\)'s, it is faster to find the LU decomposition once and use \(L, U, P\) on different \(b\)'s.
📗 d = decomposition(M, 'lu'); d \ b uses the same LU decomposition approach without the need to remember how to solve for \(x\) given \(L, U, P\).
TopHat Quiz
📗 In a factor input matrix \(M\), row \(i\) column \(j\) represents the amount of material \(i\) required in the production of product \(j\). In an input vector \(b\), row \(i\) represents the amount of material \(i\) available. Given \(M, b\), compute the number of products that can be produced. Define M = [1 2 3; 4 5 6; 7 8 10]; b = [12; 15; 19];.
➩ A: M / b
➩ B: M' / b
➩ C: M / b'
➩ D: M' / b'


# Invertability

📗 A square matrix \(M\) is invertible if there exists \(M^{-1}\) such that \(M^{-1} M = I\), and \(M\) is singular if it is not invertible.
➩ If \(M\) is invertible, then the solution to \(M x = b\) is \(x = M^{-1} b\).
inv(M) finds the inverse of a square matrix \(M\).
📗 The determinant of a matrix \(M\), denoted by \(det\left(M\right)\) or \(\left| M \right|\), measures the magnitude of a matrix.
➩ \(det\left(M\right) = 0\) if and only if \(M\) is singular.
➩ When \(det\left(M\right)\) is close to \(0\), \(M\) could be difficult to invert due to numerical errors, and MATLAB issues a warning about the matrix being close to singular.
det(M) find the determinant of a square matrix \(M\).
📗 Matrices that are close to singular are also called ill-conditioned.
➩ The condition number of a matrix \(M\), denoted by \(\kappa\left(M\right)\), measures how much the solution \(x\) changes due to a small error in \(b\).
➩ The larger the condition number, the more sensitive the solution is to the changes in \(b\), which implies that numerical errors are more likely to affect the solution.
➩ If \(M\) is not inveritble, the condition number of \(M\) is infinity.
cond(M) finds the condition number of a matrix \(M\).
Example
📗 Hilbert matrix is an example of an ill-conditioned matrix.
📗 Row \(i\) column \(j\) of a Hilbert matrix is \(H_{ij} = \dfrac{1}{i + j - 1}\).
➩ For example, a \(3\) by \(3\) Hilbert matrix \(\begin{bmatrix} 1 & \dfrac{1}{2} & \dfrac{1}{3} \\ \dfrac{1}{2} & \dfrac{1}{3} & \dfrac{1}{4} \\ \dfrac{1}{3} & \dfrac{1}{4} & \dfrac{1}{4} \end{bmatrix}\) and a \(4\) by \(4\) Hilbert matrix is \(\begin{bmatrix} 1 & \dfrac{1}{2} & \dfrac{1}{3} & \dfrac{1}{4} \\ \dfrac{1}{2} & \dfrac{1}{3} & \dfrac{1}{4} & \dfrac{1}{5} \\ \dfrac{1}{3} & \dfrac{1}{4} & \dfrac{1}{5} & \dfrac{1}{6} \\ \dfrac{1}{4} & \dfrac{1}{5} & \dfrac{1}{6} & \dfrac{1}{6} \end{bmatrix}\).
hilb(n) creates the \(n\) by \(n\) Hilbert matrix.
TopHat Quiz
📗 m = hilb(n); n = m * ones(n, 1); x = m \ b; [min(x) max(x)] for \(n = 5, 25, 100\).
➩ A: \(\begin{bmatrix} 1 & 1 \end{bmatrix}\)
➩ B: \(\begin{bmatrix} 0 & 0 \end{bmatrix}\)
➩ C: \(\begin{bmatrix} -104.7468 & 74.0750 \end{bmatrix}\)
➩ D: \(\begin{bmatrix} -328.5181 & 400.4187 \end{bmatrix}\)


📗 Notes and code adapted from the course taught by Professors Beck Hasti and Michael O'Neill.
📗 You can expand all TopHat Quizzes and Discussions: .
📗 If there is an issue with TopHat during the lectures, please submit your answers on paper (include your Wisc ID and answers) or this Google form Form at the end of the lecture.





Last Updated: March 03, 2025 at 12:52 AM