from numpy import *
from scipy import linalg
from scipy.linalg import norm
from matplotlib.pyplot import *
from prettytable import PrettyTable
from timeit import default_timer as timer
import sys
sys.path.append('fncbook/')
import fncbook as FNC
# This (optional) block is for improving the display of plots.
# from IPython.display import set_matplotlib_formats
# set_matplotlib_formats("svg","pdf")
# %config InlineBackend.figure_format = 'svg'
rcParams["figure.figsize"] = [7, 4]
rcParams["lines.linewidth"] = 2
rcParams["lines.markersize"] = 4
rcParams['animation.html'] = "jshtml" # or try "html5"
The manipulations on matrices and vectors so far in this chapter have been algebraic, much like those in an introductory linear algebra course. In order to progress to the analysis of the algorithms we have introduced, we need a way to measure the size of vectors and matrices—size in the sense of magnitude or distance, not the number of rows and columns.
The last of these properties is known as the triangle inequality. It is natural to interpret ∥x∥=∥x−0∥ as the distance from x to the origin and ∥x−y∥ as the distance from x to y. We will be using only the three most important vector norms, defined as follows.
The 2-norm corresponds to ordinary Euclidean distance.
For any nonzero vector v, we can find a unit vector through the normalization x=v/∥v∥. Thus, we can interpret
By definition, a sequence is convergent in the infinity norm if and only if it converges componentwise. The same is true for a convergent sequence in any norm.
Although we view matrices as two-dimensional, we can also interpret them as vectors: simply stack the columns on top of one another.[2] Hence, we can define a matrix norm via the vector 2-norm.
However, it often proves to be more useful to define matrix norms differently.
The last equality above follows from linearity (as shown in Exercise 2.7.5). It is derived from the interpretation of a matrix as a linear operator between Rn and Rm. Thus in the 2-norm, for instance,
One can interpret the definition of an induced norm geometrically. Each vector x on the unit “sphere” (as defined by the chosen vector norm) is mapped to its image Ax, and the norm of A is the radius of the smallest “sphere” that encloses all such images.
The definition of an induced matrix norm may seem oddly complicated. However, there are some key properties that follow directly from the definition.
Two of the vector norms we have encountered induce matrix norms that are easy to compute from the matrix elements.
Tip
A mnemonic for (2.7.11) and (2.7.12) is that the ∞ symbol extends horizontally while the 1 character extends vertically, each indicating the direction of the summation in its formula. Also, both formulas give the same result for m×1 matrices as the vector norm. In both cases you must take absolute values of the matrix elements before summing.
Despite the lack of a simple formula for it, the 2-norm is the default choice for many applications and theorems.
Column stacking is actually how matrices are stored in memory within Julia and is known as column-major order. MATLAB and FORTRAN also use column-major order, while C and Python use row-major order, in which the rows are stacked.