Jeff Fessler, University of Michigan
# https://gist.github.com/shashi/e1ade8f935802d83ebc2 # inspiration
using LinearAlgebra: eigen, Diagonal, opnorm
using Interact # @manipulate
using Plots; default(markerstrokecolor=:auto)
The WebIO Jupyter extension was not detected. See the WebIO Jupyter integration documentation for more information.
A = [2 1; 1 3] # symmetric matrix: principal axes are eigenvectors
#A = [1 -1; 1 -1] # special outer product, cf HW01!
#A = [1 1; 1 1] # symmetric outer product
#A = [2 1; 0 2] # asymmetric matrix, not normal
#A = [cos(π/3) sin(π/3); -sin(π/3) cos(π/3)] # rotation, normal, complex eigvecs!
#A = [1 1; 0 1] # "defective" matrix: does not have lin. ind. V
display(isapprox(A'A, A*A') ? "normal!" : "not normal")
A
"normal!"
2×2 Matrix{Int64}: 2 1 1 3
Φ = range(0, 2π, 181)
xc = [cos.(Φ) sin.(Φ)]'
yc = A * xc
@manipulate for θ in slider(Φ, value=Φ[1])
#anim = @animate for θ in Φ
#for θ in (π/2,)
x = [cos(θ), sin(θ)] # vector on unit circle
y = A * x # matrix-vector multiplication of interest
plot(xc[1,:], xc[2,:], line=(:blue,:dash), label="",
xlim = (-1.1, 1.1) .* opnorm(A), xlabel="x1",
ylim = (-1.1, 1.1) .* opnorm(A), ylabel="x2",
aspect_ratio = :equal)
plot!(yc[1,:], yc[2,:], line=(:purple,:dash), label="")
plot!([0, x[1]], [0, x[2]], color=:blue, label="")
plot!([0, y[1]], [0, y[2]], color=:purple, label="")
scatter!([0, x[1]], [0, x[2]], color=:blue, label="x")
scatter!([0, y[1]], [0, y[2]], color=:purple, label="y")
end
plot!() # for saving as html
#savefig("tmp.pdf") # save figure to pdf file
#gif(anim, "03_eigshow1_2113.gif")
#gif(anim, "03_eigshow1_2102.gif")
#gif(anim, "03_eigshow1_1101.gif")
# http://docs.juliaplots.org/latest/animations/
# example fails 2018-08-20
if false
using Iterators
itr = repeatedly(()->rand(10), 20)
animate(itr, ylims=(0,1), c=:red, fps=5)
end
# saves a file - doesn't display it
if false
@gif for i=1:10
plot((1:9).^i)
end
end
(d,V) = eigen(A)
display(V)
display(V'V)
display(V * Diagonal(d) * V')
@show d;
2×2 Matrix{Float64}: -0.850651 0.525731 0.525731 0.850651
2×2 Matrix{Float64}: 1.0 0.0 0.0 1.0
2×2 Matrix{Float64}: 2.0 1.0 1.0 3.0
d = [1.381966011250105, 3.618033988749895]
ϕ=π/4; (pi, π, cos(ϕ))
(π, π, 0.7071067811865476)