Processing math: 100%
Skip to main content

Section 5.5 Python/MATLAB recap

Eigenvalues and eigenvectors. MATLAB/Python has its own function to evaluate eigenvalues and eigenvectors of a matrix. Given a n×n matrix A, 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×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/Python's own function norm(v,1). In general, norm(v,p) gives the p-norm
[|v1|p+⋯+|vn|p](1/p).
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/Python can evaluate QR decompositions. The command [Q,R]=qr(A) gives the standard QR decomposition of a square matrix A, namely A=QR. The command [Q,R,P]=qr(A) gives the 'column pivoting' QR decomposition of a square matrix A. In this case, AP=QR, where P is a permutation matrix. It makes sense to use a pivoted decomposition when A is close to being degenerate.