Matrix norms

Copyright (C) 2020 Andreas Kloeckner

MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Here's a matrix of which we're trying to compute the norm:

Recall:

$$||A||=\max_{\|x\|=1} \|Ax\|,$$

where the vector norm must be specified, and the value of the matrix norm $\|A\|$ depends on the choice of vector norm.

For instance, for the $p$-norms, we often write:

$$||A||_2=\max_{\|x\|=1} \|Ax\|_2,$$

and similarly for different values of $p$.


We can approximate this by just producing very many random vectors and evaluating the formula:

First, we need to bring all those vectors to have norm 1. First, compute the norms:

Then, divide by the norms and assign to normalized_xs:

Then check the norm of a randomly chosen vector.

Let's take a look:

Now apply $A$ to these normalized vectors:


Let's take a look again:

Next, compute norms of the $Ax$ vectors:

What's the biggest one?

Compare that with what numpy thinks the matrix norm is: