studEE16A
  • Introduction
  • Linear Algebra
    • Linear Equations
      • Description
      • Example Problems
    • Vector Spaces
      • Description
      • Example Problems
    • Inner Products
      • Description
      • Example Problems
    • Determinants
      • Description
      • Example Problems
    • Eigen-everything
      • Description
      • Example Problems
    • Matrices
      • Description
      • Example Problems
    • Least Squares
      • Description
      • Example Problems
    • Gram-Schmidt
      • Description
      • Example Problems
    • Basis
      • Description
      • Example Problems
    • Page Rank
  • Circuits
    • Circuit Basics
    • Capacitance
    • Nodal Analysis
    • Superposition
    • Thevenin and Norton
    • What, When, Where, and Why?
    • Op Amps
Powered by GitBook
On this page

Was this helpful?

  1. Linear Algebra
  2. Least Squares

Example Problems

PreviousDescriptionNextGram-Schmidt

Last updated 5 years ago

Was this helpful?

Suppose we are given the equations \left\{\begin{array}[l] 2x - y = 2 \\ x + 2y = 1 \\ x + y = 4\end{array}\right.. Let's try solving for the values of xxx and yyy that satisfy all three equations.

[211211][xy]=[214]\begin{bmatrix} 2 & 1 \\ 1 & 2 \\ 1 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 2 \\ 1 \\ 4 \end{bmatrix}​211​121​​[xy​]=​214​​

By performing Gaussian elimination, we end up with

[2−10−501][xy]=[20−3]\begin{bmatrix} 2 & -1 \\ 0 & -5 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 2 \\ 0 \\ -3 \end{bmatrix}​200​−1−51​​[xy​]=​20−3​​

The system is overdetermined! yyy cannot equal 000 and −3-3−3 simultaneously. In this type of situation, we have to resort to using least squares. We will find values of x′x'x′ and y′y'y′ that is the "closest" to each of the equations (imagine minimizing the squared distances between (x′,y′)(x', y')(x′,y′) and each of the lines). Let's solve for this using the equation ATAx⃗=ATb⃗\textbf{A}^T\textbf{A}\vec{x}=\textbf{A}^T\vec{b}ATAx=ATb.

ATA=[211−121][2−11211]=[6116]\textbf{A}^T\textbf{A} = \begin{bmatrix} 2 & 1 & 1 \\ -1 & 2 & 1 \end{bmatrix} \begin{bmatrix} 2 & -1 \\ 1 & 2 \\ 1 & 1 \end{bmatrix} = \begin{bmatrix} 6 & 1 \\ 1 & 6 \end{bmatrix}ATA=[2−1​12​11​]​211​−121​​=[61​16​]

Sanity check: ATA\textbf{A}^T\textbf{A}ATA is always a symmetric matrix. Why? (ATA)T=ATATT=ATA(\textbf{A}^T\textbf{A})^T = \textbf{A}^T\textbf{A}^{T^T} = \textbf{A}^T\textbf{A}(ATA)T=ATATT=ATA

ATb⃗=[211−121][214]=[94]\textbf{A}^T\vec{b} = \begin{bmatrix} 2 & 1 & 1 \\ -1 & 2 & 1 \end{bmatrix} \begin{bmatrix} 2 \\ 1 \\ 4 \end{bmatrix} = \begin{bmatrix} 9 \\ 4 \end{bmatrix}ATb=[2−1​12​11​]​214​​=[94​]

Now we have

[6116]x⃗=[94]\begin{bmatrix} 6 & 1 \\ 1 & 6 \end{bmatrix} \vec{x} = \begin{bmatrix} 9 \\ 4 \end{bmatrix}[61​16​]x=[94​]

x⃗=[6116]−1[94]\vec{x} = \begin{bmatrix} 6 & 1 \\ 1 & 6 \end{bmatrix}^{-1}\begin{bmatrix} 9 \\ 4 \end{bmatrix}x=[61​16​]−1[94​]

x⃗=135[6−1−16][94]=[10737]\vec{x} = \frac{1}{35} \begin{bmatrix} 6 & -1 \\ -1 & 6\end{bmatrix} \begin{bmatrix} 9 \\ 4 \end{bmatrix} = \begin{bmatrix} \frac{10}{7} \\ \frac{3}{7} \end{bmatrix}x=351​[6−1​−16​][94​]=[710​73​​]