Skip to main content

Exercises 6.6 Homework

1.

For each of the following systems, decide if it is: (i) overdetermined, under-determined, or square; (ii) has a unique solution, has infinitely many solutions, or is inconsistent. Briefly explain how you reached these conclusions. To save time, you may use Matlab's rank command to compute the ranks of matrices.

\begin{equation*} \begin{cases} 3x_1 -x_3 \amp = 0 \\ x_1 -2 x_2 \amp = 3 \\ 2x_2 + 5x_3 \amp = -1 \end{cases} \end{equation*}
\begin{equation*} \begin{cases} 3x_1 +4x_2 -x_3 \amp = 4 \\ x_1 -2 x_2 + 3x_3\amp = 4 \\ \end{cases} \end{equation*}
\begin{equation*} \begin{cases} 3x_1 +4x_2 -x_3 + x_4 \amp = 2 \\ x_1 -2 x_2 + 3x_3 - x_4 \amp = -3 \\ 7x_1 +6 x_2 + x_3 + x_4 \amp = 1 \\ \end{cases} \end{equation*}
2.

Write a function linearfit that takes arguments x and y (vectors of the same size) and returns two numbers c and d, coefficients of the best-fitting line \(y=cx+d\text{.}\) Then apply it to the population of your hometown during years 1950, 1960, ..., 2010, 2020. (The data should be easy to find online; if not, use a larger nearby town). The code could look like this.

x =  (1950:10:2020)';  % years as a column vector
y =                    % population of your hometown in these years 
[c, d] = linearfit(x, y);            % find the coefficients of linear fit
xx = linspace(min(x), max(x), 500);  % to be used for plotting the line
plot(x, y, 'r*', xx, c*xx + d, 'b')  % plot red points and blue line

function [c, d] = linearfit(x,y)
  ... set up and solve an overdetermined system, 
  ... then assign c and d based on its solution
end

We do not actually need 500 points in the vector xx to plot a line: two would be enough. But the code is written to be adaptable for non-linear fit in the future.

3.

Write a script that:

  1. Creates a matrix \(A\) of size \(20\times 20\) according to the formula \(A_{ij} = 1/(i+j-1)\text{.}\) This can be done either with a double loop or by using array expansion as explained in Section 2.4.
  2. Creates a column vector \(b\) with \(20\) elements which alternate like \((c, 0, c, 0, c, 0, \dots)\text{.}\) Here \(c\) is the first digit of your SUID.
  3. Computes the solution of \(Ax=b\) and displays the norm of the difference between \(Ax\) and \(b\text{.}\)

Remark. The matrix \(A\) is invertible, is not very large, and does not have any extremely large or extremely small entries: they are all between \(0.025\) and \(1\text{.}\) Yet, it is so close to being singular that the solution of this linear system is likely to be pure noise due to round-off errors.