using Plots, Interact function plot_image(M, x, tol=0.05) new_x = M * x unit_circle = [(cos(θ), sin(θ)) for θ in 0:0.01:2π] ellipse = [M*[cos(θ), sin(θ)] for θ in 0:0.01:2π]; plot([(0, 0), (x[1], x[2])], aspect_ratio=1, lw=2, leg=false, c=:green, arrow=0.4) plot!([(0, 0), (new_x[1], new_x[2])], lw=3, c=:blue, arrow=0.4) plot!(unit_circle, ls=:dash, c=:green) plot!(first.(ellipse), last.(ellipse), ls=:dash, c=:blue) # highlight when an eigenvector by changing color: ang1 = atan(x[2], x[1]) ang2 = atan(new_x[2], new_x[1]) if abs(ang1 - ang2) < tol || abs(ang1 - ang2 + π) < tol || abs(ang1 - ang2 - π) < tol plot!([(0, 0), (new_x[1], new_x[2])], lw=4, c=:magenta) plot!([(0, 0), (x[1], x[2])], lw=4, c=:magenta) end scatter!([0], [0]) xlims!(-2, 2) ylims!(-2, 2) end a = slider(-2:0.1:2, label="a") b = slider(-2:0.1:2, label="b") c = slider(-2:0.1:2, label="c") d = slider(-2:0.1:2, label="d") sliders = vbox( hbox(a, b), hbox(c, d) ) r = -2:0.01:2 θ_vals = range(-2π, 2π, length = 500) formatted_vals = map(t -> "$(floor(t/π, digits=2))π", θ_vals) #@manipulate for a in r, b in r, c in r, d in r, θ in θ = slider(θ_vals, formatted_vals, label="θ") p = map(a, b, c, d, θ) do a, b, c, d, θ M = [a b; c d] x = [cos(θ), sin(θ)] plot_image(M, x) end vbox(sliders, θ, p) using LinearAlgebra @manipulate for σ₁ in 0:0.01:2, σ₂ in 0:0.01:2, θ in 0:0.01:2π, ϕ in 0:0.01:2π, angle=-2π:0.01:2π # when phi=theta have U = V so a symmetric matrix U = [cos(θ) sin(θ); -sin(θ) cos(θ)] V = [cos(ϕ) sin(ϕ); -sin(ϕ) cos(ϕ)] Σ = Diagonal([σ₁, σ₂]) M = U * Σ * V' x = [cos(angle), sin(angle)] plot_image(M, x, 0.01) title!("evals = $(eigvals(M))") end