In [1]:
## Show the action of a matrix in the vector 1-norm
# 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.76896   2.34695   -1.91023   -1.34192   â€¦  -1.32674   0.46685   -1.98131
0.392831  0.556629  -0.481567  -0.383886     -0.381276  0.197595  -0.493783
In [2]:
## Plot it
using Plots
pyplot(legend = false, size=(750,750), dpi=150)
myshow() = begin; if isdefined(:Atom); gui(); else; return plot!(); end; end
scatter(X[1,:],X[2,:])
scatter!(Y[1,:],Y[2,:])
myshow()

Accessibility encountered a DBus error: QDBusError("org.a11y.Bus.Error", "Failed to execute child process \"/bin/dbus-daemon\" (No such file or directory)")

Out[2]:
In [3]:
## Compare with the matrix norm
@show norm(A,1)
@show maximum(sum(abs.(Y),1))

norm(A, 1) = 3.0454897680982054
maximum(sum(abs.(Y), 1)) = 
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 norm(A,Inf)
@show max(maximum(abs.(Y)))

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

# 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
norm(A, Inf) = 0.5652819769702074
max(maximum(abs.(Y))) = 0.5585861304789459

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,1)))

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

norm(A, 2) = 1.3785326163601803
sqrt(maximum(sum(Y .^ 2, 1))) = 
Out[5]:
1.378475204657182