Geometry & Linear Algebra

Lines in the plane and Least squares method - A uniqueness problem

Part I. Lines in the plane and Least squares solution - Glimpse on theory

System of linear equations into matrix language

A very compact form to express a system of linear equations \[ \left\{ \begin{array}{rcrcrcrcr} a_{11}x_1 &+& a_{12}x_2 &+& \cdots &+& a_{1n}x_n &=& b_1 \\ a_{21}x_1 &+& a_{22}x_2 &+& \cdots &+& a_{2n}x_n &=& b_2 \\ &\vdots & & & & & & \\ a_{m1}x_1 &+& a_{m2}x_2 &+& \cdots &+& a_{mn}x_n &=& b_m \end{array} \right. \] is to use matrix language adopted from Linear Algebra.
We introduce the coefficient matrix \( A = (a_{ij})_{m{\times}n} \), the column vector \( \mathbf{b}\) for the right side known numbers and the column \( \mathbf{x}\) for the unknowns.
Then the system looks like \[ \left( \begin{array}{cccc} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{array} \right) \left( \begin{array}{c} x_1 \\ x_2 \\ \vdots \\ x_n \end{array} \right) = \left( \begin{array}{c} b_1 \\ b_2 \\ \vdots \\ b_m \end{array} \right) \] and briefly \[ A\mathbf{x} = \mathbf{b}. \]

Overdetermined systems

If we have more equations than unknowns, we usually do not get any answer to the problem at all.
The same way, a general matrix equation \( A\mathbf{x} = \mathbf{b} \) may not have solutions (also, often there are infinitely many solutions).
But if the matrix \( A \in \mathbb{R}^{m{\times}n} \) is of ''full rank'', which means that all the columns of \( A \) are linearly independent (libre),
then the normal equation \[ A^T\!A\mathbf{x} = A^T \mathbf{b} \] has a unique solution \[ \widehat{\mathbf{x}} := (A^TA)^{-1} A^T \mathbf{b}, \] which is called the Least squares solution to the matrix equation \( A\mathbf{x} = \mathbf{b} \).
This solution of the normal equation is the unique vector \( \widehat{\mathbf{x}} \), for which the residual \( \mathbf{r}(\mathbf{x}) := A\mathbf{x} - \mathbf{b} \) has minimum norm \( ||\mathbf{r}(\widehat{\mathbf{x}})|| = || A\widehat{\mathbf{x}} - \mathbf{b} || \).

Immediate application

Example 1. Solve \[ \left\{ \begin{array}{rcrcr} x_1 &+& x_2 &=& 3 \\ -2x_1 &+& 3x_2 &=& 1 \\ 2x_1 &-& x_2 &=& 2 \end{array} \right. \] Solution. There is no solution. However there might be some convenient answer, ''compromise''.
Let \( A \) be the coefficient matrix. Then the normal equation has the form \[ \begin{array}{crcl} & A^TA \mathbf{x} &=& A^T \mathbf{b}\\[3pt] \iff & \left( \begin{array}{rrr} 1 & -2 & 2 \\ 1 & 3 & -1 \end{array} \right) \left( \begin{array}{rr} 1 & 1 \\ -2 & 3 \\ 2 & -1 \end{array} \right) \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) &=& \left( \begin{array}{rrr} 1 & -2 & 2 \\ 1 & 3 & -1 \end{array} \right) \left( \begin{array}{r} 3 \\ 1 \\ 2 \end{array} \right) \\[5pt] \iff& \left( \begin{array}{rr} 9 & -7 \\ -7 & 11\end{array} \right) \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) &=& \left( \begin{array}{r} 5 \\ 4 \end{array} \right) \\[5pt] \iff& \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right) &=& \left( \begin{array}{c} \frac{83}{50} \\ \frac{71}{50} \end{array} \right) \end{array} \] The Least squares solution to \( A\mathbf{x} = \mathbf{b} \) is \[ \widehat{\left( \begin{array}{c} x_1 \\ x_2 \end{array} \right)} = \left( \begin{array}{c} \frac{83}{50} \\[3pt] \frac{71}{50} \end{array} \right) = \left( \begin{array}{c} 1{,}66 \\[3pt] 1{,}42 \end{array} \right) \] Unfortunately, it turns out that if we use a different representation of the lines, we get different solutions!

Example 2. For example, if we take \[ \left\{ \begin{array}{rcrcr} 10x_1 &+& 10x_2 &=& 30 \\ -2x_1 &+& 3x_2 &=& 1 \\ 2x_1 &-& x_2 &=& 2 \end{array} \right. \] we have exactly the same plane lines, but the Least Squares solution would be \[ \widehat{\left( \begin{array}{c} x_1 \\ x_2 \end{array} \right)} = \left( \begin{array}{c} \frac{691}{427} \\[3pt] \frac{1181}{854} \end{array} \right) = \left( \begin{array}{c} 1{,}62 \\[3pt] 1{,}38 \end{array} \right) \] Problem. What is the least squares solution for the previous system, when the first equation is multiplied by \( 0 \)? Answer: \[ \widehat{\left( \begin{array}{c} x_1 \\ x_2 \end{array} \right)} = \left( \begin{array}{c} \frac{7}{4} \\[3pt] \frac{6}{4} \end{array} \right) = \left( \begin{array}{c} 1{,}75 \\[3pt] 1{,}50 \end{array} \right) \]

Dynamical figures (''Sketches'') allow us to experiment the problem in a visual way!

Part II. Lines in the plane and Least Squares Solution - Experiments

Now we shall do some experiments on overdetermined systems of two-unknown linear equations and the Least squares method on finding a "compromise" solution.
We see very concretely that uniqueness problems raise when we try to combine linear algebra tools and geometry.

The geometric representations of the linear equations \[ a_{i1} x_1 + a_{i2} x_2 = b_i \] are lines in the plane. Remember that a system of such equations can be written in linear algebra language as matrix equation \[ A\mathbf{x} = \mathbf{b}, \] where \( \mathbf{x} \) is the vector of the unknowns \( x_i \).


1. Solutions for systems of three equations

In this dynamic Sketch you can make parallel moves for the lines by dragging with the computer mouse the points \( P_1 \), \( Q_1 \) and \( R_1 \).
You can turn the lines around with the points \( P_2 \), \( Q_2 \) and \( R_2 \).
Also you can multiply (scale) the equations by numbers \( k_1 \), \( k_2 \) and \( k_3 \).
Try all the buttons in the figure.

The point \( \widehat{\mathbf{x}} \) is the Least squares solution of the equations on the screen.
Move the line \( P_1 P_2 \) by moving the points \( P_1\) and \( P_2 \).
Move the other lines too. Reset when you want (refreshing the browser page).

Problems

1. Explain why \( \widehat{\mathbf{x}} \) is moving, though the lines do not move when you change \( k_1 \), \( k_2 \) or \( k_3 \) (push Scale equations first).

2. How is \( \widehat{\mathbf{x}} \) moving when you vary \( k_1 \) from negative to positive direction?
Answer the same question for \( k_2 \) and \( k_3 \).

3. What is the curve drawn by \( \widehat{\mathbf{x}} \) when \( P_2 \) is moving around circle and all other given points are fixed?


Puzzle 1

Puzzle 1 Problem

Try to find the least squares solution \( \widehat{\mathbf{x}} \) of the system of the equations for the lines in the Sketch.

Give the coordinates of \( \widehat{\mathbf{x}} \):



Puzzle 2

Puzzle 2 Problem

Try to find the least squares solution \( \widehat{\mathbf{x}} \) of the system of the equations for the lines in the Sketch.

Give the coordinates of \( \widehat{\mathbf{x}} \):



Puzzle 3

Puzzle 3 Problem

Try to find the least squares solution \( \widehat{\mathbf{x}} \) of the system of the equations for the lines in the Sketch.

Give the coordinates of \( \widehat{\mathbf{x}} \):



Puzzle 4

Puzzle 4 Problem


Here you can move one of the lines by dragging the points \( P_1 \) and \( P_2 \).
Try to find such equations for the first line so that the Least squares solution \( \widehat{\mathbf{x}} \) is the given black point \( \widehat{\mathbf{x}}' \).

Give your equations:


Are there many different solutions?

Puzzle 5

Puzzle 5 Problem


Here you can move two of the lines by dragging the points \( P_1 \), \( P_2 \), \( Q_1 \) and \( Q_2 \).
Try to find such positions for the lines that the Least squares solution \( \widehat{\mathbf{x}} \) is the given black point \( \widehat{\mathbf{x}}' \).

Are there many different solutions?



Puzzle 6

Puzzle 6 Problem


Here you can move all the lines.
Try to find such positions for the lines that
- the Least Squares Solution \( \widehat{\mathbf{x}} \) is the given black point \( \widehat{\mathbf{x}}' \) and
- turning lines does not make the solution move.

Are there many different solutions?


What can you say about this (or these) solutions?

3. Solutions for systems of four equations

In this Sketch you can make parallel moves for the lines by dragging with the computer mouse the points \( P_1 \), \( Q_1 \), \( R_1 \) and \( S_1 \). You can turn the lines around with the points \( P_2 \), \( Q_2 \), \( R_2 \) and \( S_2 \).
Also you can multiply the equations by numbers \( k_1 \), \( k_2 \), \( k_3 \) and \( k_4 \). Try all the buttons in the Sketch.

Problem

Describe all possible positions of \( \widehat{\mathbf{x}} \) for the 4 given lines when \( k_1 \), \( k_2 \), \( k_3 \) and \( k_4 \) belong to \( \mathbb{R} \).

Part III Normalizing the Least squares solution of lines

1. Description of the problem

Let \( a_1 \), \( b_1 \), \( c_1 \), \( k_1 \), \( a_2 \), \( b_2 \), \( c_2 \), \( k_2 \), \( a_3 \), \( b_3 \), \( c_3 \), \( k_3 \), be real numbers such that \[ a_1^2 + b_1^2 = a_2^2 + b_2^2 = a_3^2 + b_3^2 = 1. \] We call \( d_1 \), \( d_2 \) and \( d_3 \) the straight lines of equations \[ \left\{ \begin{array}{rcrcr} k_1 a_1 x_1 &+& k_1 b_1 x_2 &=& k_1 c_1 \\ k_2 a_2 x_1 &+& k_2 b_2 x_2 &=& k_2 c_2 \\ k_3 a_3 x_1 &+& k_3 b_3 x_2 &=& k_3 c_3 \end{array} \right. \] The lines form a triangle of vertices \( S_1 = d_2\cap d_3 \), \( S_2 = d_3\cap d_1 \) and \( S_3 = d_1\cap d_2 \), see Figure 1.
Triangle
Figure 1: The triangle

We define \[ A = \left( \begin{array}{cc} k_1 a_1 & k_1 b_1 \\ k_2 a_2 & k_2 b_2 \\ k_3 a_3 & k_3 b_3 \end{array} \right), \quad \mathbf{x} = \left( \begin{array}{c} x_1 \\ x_2 \end{array} \right), \quad \mathbf{c} = \left( \begin{array}{c} k_1 c_1 \\ k_2 c_2 \\ k_3 c_3 \end{array} \right), \quad \] The matrix equation \( A\mathbf{x} = \mathbf{c} \) has in general no solution. The least squares solution \( \widehat{\mathbf{x}} \) of the normal equation \[ A^T\! A \mathbf{x} = A^T \mathbf{c} \] is such that \[ F(\mathbf{x}) = F(x_1,x_2) = || A \mathbf{x} - \mathbf{c}||^2 = (\mathbf{x}^T\,A^T - \mathbf{c}^T)(A\mathbf{x} - \mathbf{c}) \] is minimum for \( \mathbf{x} = \widehat{\mathbf{x}} \). We denote by \( d(\mathbf{x},L) \) the distance from the point \( \mathbf{x} \) to line \( L \). Computing \( F(\mathbf{x}) \) we get: \[ F(\mathbf{x}) = k_1^2 \left(d(\mathbf{x},d_1)\right)^2 + k_2^2 \left(d(\mathbf{x},d_2)\right)^2 + k_3^2 \left(d(\mathbf{x},d_3)\right)^2 \]

I Case \( k_1 = k_2 = k_3 \)

The function to be minimized is \[ F(\mathbf{x}) = \left(d(\mathbf{x},d_1)\right)^2 + \left(d(\mathbf{x},d_2)\right)^2 + \left(d(\mathbf{x},d_3)\right)^2 \] Let us call \( l_1 = S_2 S_3 \), \( l_2 = S_3 S_1 \) and \( l_3 = S_1 S_2 \), the lengths of the sides of the triangle defined by the lines \( d_1 \), \( d_2 \) and \( d_3 \). The point \( \widehat{\mathbf{x}} \) such that \( F(\mathbf{x}) \) is minimum for \( \mathbf{x} = \widehat{\mathbf{x}} \) is the barycenter of \( S_1 \), \( S_2 \) and \( S_3 \) with masses \( l_1^2 \), \( l_2^2 \) and \( l_3^2 \): \[ \widehat{\mathbf{x}} = \frac {l_1^2}{l_1^2+l_2^2+l_3^2} S_1 + \frac {l_2^2}{l_1^2+l_2^2+l_3^2} S_2 + \frac {l_3^2}{l_1^2+l_2^2+l_3^2} S_3 \]

Problems

1. If the triangle defined by the lines \( d_1 \), \( d_2 \) and \( d_3 \) is isosceles (let us say \( S_1 S_2 = S_1 S_3 \)), on what line do you expect to find \( \widehat{\mathbf{x}} \) (see Figure 2) ?

Isosceles
Figure 2: Isosceles triangle

2. If the triangle is equilateral where is \( \widehat{\mathbf{x}} \)?

3. The distances of \( \widehat{\mathbf{x}} \) to the sides of the triangle are proportional to the lengths of the corresponding sides to a certain power \( r \): \[ \frac {d(\widehat{\mathbf{x}},d_1)}{{l_1}^r} = \frac {d(\widehat{\mathbf{x}},d_2)}{{l_2}^r} = \frac {d(\widehat{\mathbf{x}},d_3)}{{l_3}^r} \] Guess what is the value of \( r \)?

Note: If \( r = -1 \), the point \( \widehat{\mathbf{x}} \) would be the center of gravity; if \( r = 0 \), the point \( \widehat{\mathbf{x}} \) would be the center of the inner circle.

4. If the triangle is rectangular, e.g. \( d_2 \perp d_3 \), on what line do you find \( \widehat{\mathbf{x}} \) (see Figure 3)?

Rectangular
Figure 3: Rectangular triangle

\[ \frac {H K_2}{S_1 S_3} = \frac {H K_3}{S_2 S_1} \ \textrm{since the triangles are similar} \]


IV Geometrical construction of LSQR-solution for three lines

1. Step by step construction from the point \( A \)

You can move the lines by dragging the intersections \( A \), \( B \) and \( C \).

With the Sketch control button you can see step by step:

- the point \( C_1 \) and the line parallel with line \( CA \) at distance \( |AC| \)
- the point \( B_1 \) and the line parallel with line \( AB \) at distance \( |AB| \)
- the intersecting point \( O_1 \) and the line joining it to \( A \)

2. stage of the construction: from the point \( B \)

You can move the lines by dragging the intersections \( A \), \( B \) and \( C \).

With the Sketch control button you can show and hide the three steps:

- the point \( A_2 \) and the line parallel with line \( AB \) at distance \( |AB| \)
- the point \( C_2 \) and the line parallel with line \( BC \) at distance \( |BC| \)
- the intersecting point \( O_2 \) and the line joining it to \( B \)

3. stage of the construction: from the point \( C \)

You can move the lines by dragging the intersections \( A \), \( B \) and \( C \).

With the Sketch control button you can show and hide the three steps:

- the point \( A_3 \) and the line parallel to line \( CA \) at distance \( |CA| \)
- the point \( B_3 \) and the line parallel to line \( BC \) at distance \( |BC| \)
- the intersecting point \( O_3 \) and the line joining it to \( C \)

4. All constructions from \( A \), \( B \) and \( C \)

You can move the lines by dragging the intersections \( A \), \( B \) and \( C \).

Here you can see the intersection of the first two lines and then check whether also the third will fit.


Median, angle bisector, symmedian - and least squares solution

You can move the lines by dragging the intersections \( A \), \( B \) and \( C \).
On the left side you can see how the symmedian ray of the median \( AA_m \) from \( A \) is constructed, reflecting over the bisector.
On the right side you see a quick image of the previous construction from the point \( A \).

Problems

The intersection of \( BC \) with \( A\widehat{\mathbf{x}} \) (or \( A O_1 \)) is denoted by \( P \).

1. Show that \( b^2 |PB| = c^2 |PC| \), where \( b = |CA| \) and \( c = |AB| \).

2. Show that \( AP \) is a symmedian of the triangle \( ABC \), that is, the image of the median in the reflection along the inner bisector shown on the picture.

3. Are the three symmedians of a triangle concurrent?


Martti E. Pesonen and Eric Lehman 2003, 21.12.2019 (+ Henri Tanskanen)