Notebook 6 – Math 2121, Fall 2020

In today's notebook we'll first explore some more plots of linear transformations. Then we'll take a look at the frequency that a random linear transformation is one-to-one or onto.

Running this notebook (optional)

If you have Pluto up and running, you can access the notebook we are currently viewing by entering this link (right click -> Copy Link) in the Open from file menu in Pluto.

2.8 ms
Helper methods
11.3 s
pprint (generic function with 1 method)
44.9 μs
input_plot (generic function with 2 methods)
81.6 μs
transformation_plot (generic function with 2 methods)
70.8 μs
Linear transformations from 2×2 matrices
3.1 μs

input parameters

x1 = y1 = rotate =

x2 = y2 =

matrix parameters

θ = 0 k = 1

202 μs
x = [ 1.0]     y = [ 0.0]
    [ 0.0]         [ 1.0]
40 μs
A
2×2 Array{Float64,2}:
 1.0  -0.0
 0.0   1.0
17.1 μs
Plots.jl
−3−2−10123−3−2−10123−3−2−10123−3−2−10123
x and yAx and Ay
136 ms
Random matrices, onto and one-to-one linear transformations

We can generate a random linear transformation T:RnRm by generating a random m×n matrix A and setting T(x)=Ax.

If n>m then T is never one-to-one, and if n<m then T is never onto. If nm, however, then a random linear transformation T is injective with a high probability. If nm, similarly, then a random linear transformation T is surjective with a high probability.

In other words, a sufficiently random linear transformation is almost always one-to-one if this is possible (that is, if nm) and almost always onto if this is possible (that is, if nm).

If n=m then a random linear transformation is almost always both one-to-one and onto (which will be our definition of an invertible function next lecture).

To explore this phenomenon, we'll consider our usual model of random matrix which is not that random: namely, 01-matrices whose entries are independently 0 or 1 with some probability p. For such matrices, we can see some interesting behavior while also observing convergence to the ''almost always'' properties described above.

39.8 μs
Helper methods
6.5 μs
RREF (generic function with 2 methods)
275 μs
npivots (generic function with 2 methods)
68.3 μs
is_onto (generic function with 1 method)
25.5 μs
is_one_to_one (generic function with 1 method)
27.8 μs
random_boolean_matrix (generic function with 1 method)
33.4 μs
accumulate_mean (generic function with 1 method)
37.8 μs
accumulate_std (generic function with 1 method)
47 μs
accumulate_plot (generic function with 1 method)
68 μs
170 ms
Parameters
13.4 μs
trials
1000
1.4 μs

nrows = 10

ncols = 20

5.8 ms

To make the following plot, for various probabilities p in [0,1], we generate 1000 random 01-matrices of size 10 by 20. For each p, we compute the proportition of these matrices that correspond to onto linear transformations, as well as the standard deviation of this statistic.

Then we plot both as a function of p.

15.4 μs
Plots.jl
0.000.250.500.751.000.000.250.500.751.00
meanstdProbablity p that individual matrix entry is zeroProportionRandom 01-matrices, size 10-by-20: onto transformations
1.3 s

Interesting properties of this graph: when p is not too small or too large, our model of a random matrix is ''sufficiently'' random, so the measured proportion is 1.0: almost every random matrix corresponds to an onto linear transformation.

The standard deviation is always bimodal, with maximum value 0.5 attained at two values p1 and p2 of the probability p, which are also where the mean and standard deviation graphs intersect.

What are these two values of p? They are not symmetric, that is, p21p1.

64.2 μs

Why does the mean have value 0 when p=0 and when p=1?

9.6 μs

Here is a random 01-matrix for p=0:

9.4 μs
R
10×20 Array{Float64,2}:
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  …  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0     1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0     1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0     1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0     1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0  …  1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0     1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0     1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0     1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
 1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0     1.0  1.0  1.0  1.0  1.0  1.0  1.0  1.0
8.5 μs
1
10.6 μs

Here is a random 01-matrix for p=1:

6.7 μs
S
10×20 Array{Float64,2}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  …  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  …  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
15.6 μs
0
8.4 μs

In both cases the number of pivots is much less than the number of rows or columns, so these matrices correspond to linear transformations that are neither onto nor one-to-one.

15 μs

To make the following plot, for various probabilities p in [0,1], we generate 1000 random 01-matrices of size 20 by 10 (note: reversed from above). For each p, we compute the proportition of these matrices that correspond to one-to-one linear transformations, as well as the standard deviation of this statistic.

Then we plot both as a function of p.

12.2 μs
Plots.jl
0.000.250.500.751.000.000.250.500.751.00
meanstdProbablity p that individual matrix entry is zeroProportionRandom 01-matrices, size 20-by-10: 1-to-1 transformations
1.4 s

Why are two graphs nearly the same?

The transpose of a matrix A is then matrix AT formed by interchanging the rows and columns:

[123456]T=[135246].

We'll see later in the class, that the number of pivot positions in A is the same as in AT.

27.9 μs

This means that the number of 10 by 20 matrices with pivots in every row (corresponding to onto linear transformations) is the same as the number of 20 by 10 matrices with pivots in every column (corresponding to one-to-one linear transformations).

11.9 μs