using Plots
x_min, x_max = -5, 5
y_min, y_max = -5, 5
α, β = 0.2, 0.1
# Axes
gs = 3
z = range(x_min, stop = x_max, length = gs)
x = zeros(gs)
y = zeros(gs)
plot(x, y, z, color=:black, linewidth=2, alpha=0.5, label="", legend=false)
plot!(z, x, y, color=:black, linewidth=2, alpha=0.5, label="")
plot!(y, z, x, color=:black, linewidth=2, alpha=0.5, label="")
# Fixed linear function, to generate a plane
f(x, y) = α .* x + β .* y
# Vector locations, by coordinate
x_coords = [3, 3]
y_coords = [4, -4]
z = f(x_coords, y_coords)
# Lines to vectors
n = 2
x_vec = zeros(n, n)
y_vec = zeros(n, n)
z_vec = zeros(n, n)
labels = []
for i ∈ 1:n
x_vec[:, i] = [0; x_coords[i]]
y_vec[:, i] = [0; y_coords[i]]
z_vec[:, i] = [0; f(x_coords[i], y_coords[i])]
lab = string("a", i)
push!(labels, lab)
end
plot!(x_vec, y_vec, z_vec, color=[:blue :red], linewidth=1.5,
alpha=0.6, label=labels)
# Draw the plane
grid_size = 20
xr2 = range(x_min, stop = x_max, length = grid_size)
yr2 = range(y_min, stop = y_max, length = grid_size)
z2 = Matrix{Float64}(undef, grid_size, grid_size)
for i ∈ eachindex(grid_size)
for j ∈ eachindex(grid_size)
z2[j, i] = f(xr2[i], yr2[j])
end
end
surface!(xr2, yr2, z2, cbar=false, alpha=0.2, fill=:blues,
xlims=(x_min, x_max), ylims=(x_min, x_max),
zlims=(x_min, x_max), xticks=[0], yticks=[0],
zticks=[0])
(source: QuantEcon Julia Lectures: linearalgebra with Julia v"1.0.0"
)