Systems of linear equations to calculate $\alpha$ and $\beta$

Point $1$: When there is $1$ car passing the road, the average speed is $50$ km/h.

Point $2$: When there are $5$ cars passing the road, the average speed is $45$ km/h.

Point $3$: When there are $12$ cars passing the road, the average speed is $38$ km/h.

A traffic engineering company decides to model the average speed (shown by $u$) as a linear function of the number of cars (shown by $n$). So we want to have

$u(n)=\alpha+\beta n$ .

  • Using Point $1$ , Point $2$ and Point $3$ information: write a system of linear equations to calculate $\alpha$ and $\beta$ using all three points; i.e. we will have three equations with two unknowns.

Solution 1:

Using only Point 1 and 2 you have:

$$ \begin{align} \alpha&=50-\beta\\ \alpha+5\beta&=45\\ \Rightarrow 50+4\beta&=45\\ \beta&=-1.25 \end{align} $$ and then using the first line you get $\alpha=50-(-1.25)=51.25$. Using MATLAB, it's a simple linear system which you can solve using linsolve.

A = [1 1; 1 5]
B = [50 ; 45]

linsolve(A, B)

What this command does is that it solves the system but written in matrix form:

$$ \begin{align} \mathbf{Ax}&=\mathbf{B}\\ \begin{pmatrix}1 &1\\1 & 5\end{pmatrix}\begin{pmatrix}\alpha \\ \beta\end{pmatrix}&=\begin{pmatrix}50 \\ 45\end{pmatrix} \end{align} $$

I think MATLAB for computational reasons uses LU decomposition, but you could also premultiply by $\mathbf{A}^{-1}$: $$ \begin{align} \mathbf{x}&=\mathbf{A}^{-1}\mathbf{B}\\ \begin{pmatrix}\alpha \\ \beta\end{pmatrix}&=\frac{1}{4}\begin{pmatrix}5 &-1\\-1 & 1\end{pmatrix}\begin{pmatrix}50 \\ 45\end{pmatrix}=\begin{pmatrix}\frac{205}{4}\\-\frac{5}{4}\end{pmatrix}=\begin{pmatrix}51.25\\-1.25\end{pmatrix} \end{align} $$

Using this approach, you could run the following in MATLAB instead of the linsolve command:

A = [1 1; 1 5]
B = [50 ; 45]

inv(A)*B

EDIT: If you were to do the same for Point 2 and Point 3, the system is instead:

$$ \begin{align}\alpha+5\beta&=45\\ \alpha+12\beta&=38 \end{align} $$ Rewriting this in matrix notation gives us:

$$ \begin{pmatrix}\alpha+5\beta\\\alpha+12\beta\end{pmatrix}=\begin{pmatrix}45\\38\end{pmatrix}\Leftrightarrow \begin{pmatrix}1 & 5 \\ 1 & 12 \end{pmatrix}\begin{pmatrix}\alpha\\\beta\end{pmatrix}=\begin{pmatrix}45\\38\end{pmatrix} $$

This means that $$ \mathbf{A}=\begin{pmatrix}1 & 5 \\ 1 & 12 \end{pmatrix}, \quad \mathbf{B}=\begin{pmatrix}45\\38\end{pmatrix} $$ which in MATLAB then is

A = [1 5; 1 12]
B = [45 ; 38]

linsolve(A, B)

Solution 2:

You are given the equation, and also a few data points: for each of the three scenarios, you have the number of cars ($n$) and the observed average speed ($u(n)$).

So your three equations are \begin{align*} 50 &= \alpha + \beta\\ 45 &= \alpha + 5\beta\\ 38 &= \alpha + 12\beta \end{align*}

  1. Can you write this in matrix form, i.e. can you write down a matrix $M$ and vector $b$ such that $$M\left[\begin{array}{c}\alpha\\\beta\end{array}\right] = b?$$

  2. An overconstrained system of equations does not always have a solution. But you can always find an $\alpha$ and $\beta$ that minimizes the error, i.e. minimizes the square residual: $$\min_{\alpha, \beta}\quad \left\|M\left[\begin{array}{c}\alpha\\\beta\end{array}\right] - b\right\|^2.$$ Finding this minimizier is called solving the least squares problem. Do you need more help for how to solve it here?