In [1]:
## Show the action of a matrix in the vector 1-norm
using LinearAlgebra
# pick a random matrix
A = randn(2,2)
# pick 100 random points
X = randn(2,100)
# normalize the points to be unit 1-norm
for i = 1:100
    X[:,i] = X[:,i]/norm(X[:,i],1)
end
Y = A*X #transform all the points by the matrix
Out[1]:
2×100 Array{Float64,2}:
 -1.68649   1.43179   -0.324807   1.02396  …  -1.6737   0.13716    1.61911
  1.4576   -0.561207   0.83914   -1.27792      1.4126  -0.721375  -1.22046
In [2]:
## Plot it
using Plots
pyplot(legend = false, size=(750,750), dpi=150,
    aspect_ratio=1)
#myshow() = begin; if isdefined(:Atom); gui(); else; return plot!(); end; end
scatter(X[1,:],X[2,:])
scatter!(Y[1,:],Y[2,:])
#myshow()
Out[2]:
In [3]:
## Compare with the matrix norm
@show opnorm(A,1)
@show maximum(sum(abs.(Y),dims=1))
opnorm(A, 1) = 3.513111091579127
maximum(sum(abs.(Y), dims=1)) = 3.507007222708853
Out[3]:
3.507007222708853
In [4]:
## Same thing with the infinity norm
# Pick a random matrix and points
A = randn(2,2)
X = randn(2,100)

# normalize the points to be unit inf-norm
for i = 1:100
    X[:,i] = X[:,i]/norm(X[:,i],Inf)
end

Y = A*X # transform all the points by the matrix

# Compare with the matrix norm
println("Infinity norm")
@show opnorm(A,Inf)
@show max(maximum(abs.(Y)))

# Show the result
scatter(X[1,:],X[2,:])
scatter!(Y[1,:],Y[2,:])

# to re-display, uncomment the following:
# display(f)
# display(g)
# to save the figures:
# savefig(f,"one-norm.pdf")
# savefig(g,"inf-norm.pdf")
Infinity norm
opnorm(A, Inf) = 4.158846417808522
max(maximum(abs.(Y))) = 4.032228875364384
Out[4]:
In [5]:
## Same thing with the 2-norm
# Pick a random matrix and points
A = randn(2,2)
X = randn(2,100)

# normalize the points to be unit 2-norm
for i = 1:100
    X[:,i] = X[:,i]/norm(X[:,i],2);
end
Y = A*X # transform all the points by the matrix


# Compare with the matrix norm
@show norm(A,2)
@show sqrt(maximum(sum(Y.^2,dims=1)))

# Show the result
scatter(X[1,:],X[2,:])
scatter!(Y[1,:],Y[2,:])
norm(A, 2) = 1.3826769990262606
sqrt(maximum(sum(Y .^ 2, dims=1))) = 1.1051034336848624
Out[5]: