In [1]:
using PyPlot

In [52]:
function sym_ones(n,x)
    if ! (x in 1:n)
        error("x should be between 1 and n")
    end
    return hcat(zeros(n,x),eye(n,n-x)) + vcat(zeros(x,n),eye(n-x,n))
end
function matrixA(n)
    return sym_ones(n, 1)
end
function matrixB(n)
    out = zeros(n,n)
    for i in 1:n-1
        out += i*sym_ones(n, i)
    end
    return out
end


WARNING: Method definition sym_ones(Any, Any) in module Main at In[48]:2 overwritten at In[52]:2.
WARNING: Method definition matrixA(Any) in module Main at In[48]:8 overwritten at In[52]:8.
WARNING: Method definition matrixB(Any) in module Main at In[48]:11 overwritten at In[52]:11.
Out[52]:
matrixB (generic function with 1 method)

In [53]:
imshow(matrixA(100), cmap="gray", interpolation="none")


Out[53]:
PyObject <matplotlib.image.AxesImage object at 0x7f94f7bec350>

In [54]:
imshow(matrixB(100), cmap="gray", interpolation="none")


Out[54]:
PyObject <matplotlib.image.AxesImage object at 0x7f94f7ae7610>

In [74]:
for i in 2:16
    plot(fill(i, i), eigvals(matrixA(i)), "o")
end
xlabel("n")
ylabel("Eigenwerte")
show()



In [99]:
ev = eigvecs(matrixA(8))
for i in 1:8
    plot(1:8, ev[:,i], "-x", label="Eigenvektor $i")
end
ax = gca()
ax[:set_position]([0.06,0.06,0.8,0.91])
xlabel("Basisvektor")
ylabel("Wert")
legend(loc="center left", bbox_to_anchor=(1, 0.5))
show()



In [ ]: