Here both \(A\) and \(B\) are \(2 \times 2\) matrices. Matrices can be multiplied together in this way provided that the number of columns of \(A\) match the number of rows of \(B\text{.}\) We always list the size of a matrix by rows, then columns, so a \(3 \times 5\) matrix would have 3 rows and 5 columns. So, if \(A\) is \(m \times n\) and \(B\) is \(p \times q\text{,}\) then we can multiply \(AB\) if and only if \(n = p\text{.}\) A column vector can be thought of as a \(p \times 1\) matrix and a row vector as a \(1 \times q\) matrix. Unless otherwise specified we will assume a vector \(\vb\) to be a column vector and so \(A\vb\) makes sense as long as the number of columns of \(A\) matches the number of entries in \(\vb\text{.}\)
Just as for vectors, adding a ‘.’ before ‘*’, ‘/’, or ‘^’ produces entry-wise multiplication, division and exponentiation. If you enter
>> B*B
the result will be \(BB\text{,}\) i.e. matrix multiplication of \(B\) times itself. But, if you enter
>> B.*B
the entries of the resulting matrix will contain the squares of the same entries of \(B\text{.}\) Similarly if you want \(B\) multiplied by itself 3 times then enter
>> B^3
but, if you want to cube all the entries of B then enter
>> B.^3
Note that B*B and B^3 only make sense if \(B\) is square, but B.*B and B.^3 make sense for any size matrix.
Subsection2.1.3The identity matrix and the inverse of a matrix
The \(n \times n\) identity matrix is a square matrix with ones on the diagonal and zeros everywhere else. It is called the identity because it plays the same role that \(1\) plays in multiplication, i.e.
\begin{equation*}
A I = A, \qquad I A = A, \qquad I \vb = \vb
\end{equation*}
for any matrix \(A\) or vector \(\vb\) where the sizes match. An identity matrix in MATLAB is produced by the command
A square matrix \(A\) can have an inverse which is denoted by \(A^{-1}\text{.}\) The definition of the inverse is that
\begin{equation*}
A A^{-1}= I \qquad \text{and}\qquad A^{-1}A = I\text{.}
\end{equation*}
In theory an inverse is very important, because if you have an equation
\begin{equation*}
A \xb = \bb
\end{equation*}
where \(A\) and \(\bb\) are known and \(\xb\) is unknown (as we will see, such problems are very common and important) then the theoretical solution is
We will see later that this is not a practical way to solve an equation, and \(A^{-1}\) is only important for the purpose of derivations.In MATLAB we can calculate a matrix’s inverse very conveniently:
For a vector, the “norm” means the same thing as the length (geometrically, not the number of entries). Another way to think of it is how far the vector is from being the zero vector. We want to measure a matrix in much the same way and the norm is such a quantity. The usual definition of the norm of a matrix is
The maximum in the definition is taken over all vectors with length \(1\) (unit vectors), so the definition means the largest factor that the matrix stretches (or shrinks) a unit vector. This definition seems cumbersome at first, but it turns out to be the best one. For example, with this definition we have the following inequality for any vector \(\vb\text{:}\)
For a matrix the norm defined above and calculated by MATLAB is not the square root of the sum of the square of its entries. That quantity is called the Froebenius norm, which is also sometimes useful, but we will not need it.
Write a well-commented MATLAB script program myinvcheckplot that calls myinvcheck for \(n=10,20,40,\ldots,2^{i}10\) for \(i\) as large as possible, records the results of each trial, and plots the scalar residual versus n using a log plot. (See help loglog.)
What happens to the scalar residual as \(n\) gets big? Turn in the program, the plot, and a very brief report on the results of your experiments. (Do not print any large random matrices.)