Section 5.5 Octave/MATLAB recap
Eigenvalues and eigenvectors. MATLAB/Octave has its own function to evaluate eigenvalues and eigenvectors of a matrix. Given a \(n\times n\) matrixA
, one can fill up a vector e
with the list of all eigenvalues with the command e=eig(A)
. By writing, instead, [V,D]=eig(A)
, the variables V
and D
are filled with two \(n\times n\) matrices. The columns of the first are all eigenvectors of length 1. The second is a diagonal matrix whose diagonal elements are the eigenvalues of A
so that the \(k\)-th column of V
is en eigenvector of A
with eigenvalue equal to the \(k\)-th element of the diagonal of D
.
Norms. In this Chapter's code we evaluated explicitly the Euclidean norm of a 2-components vector v
. We could have accomplish the same thing using MATLAB/Octave's own function norm(v,1)
. In general, norm(v,p)
gives the \(p\)-norm
\begin{equation*}
\left[|v_1|^p+\dots+|v_n|^p\right]^{(1/p)}.
\end{equation*}
In particular, the taxicab norm is given by norm(v,1)
and the Euclidean one by norm(v,2)
. Below we re-write the power method code using this function:
QR decomposition. MATLAB/Octave can evaluate QR decompositions. The command [Q,R]=qr(A)
gives the standard QR decomposition of a square matrix \(A\text{,}\) namely \(A=QR\text{.}\) The command [Q,R,P]=qr(A)
gives the 'column pivoting' QR decomposition of a square matrix \(A\text{.}\) In this case, \(AP=QR\text{,}\) where \(P\) is a permutation matrix. It makes sense to use a pivoted decomposition when \(A\) is close to being degenerate.