In [1]:
using MatrixDepot
using PyPlot
In [2]:
matrixdepot()
show all the symmetric
and pos-def
matrices in the collection
In [3]:
matrixdepot("symmetric", "pos-def")
Out[3]:
In [2]:
matrixdepot("magic")
In [17]:
A = matrixdepot("magic", 5)
Out[17]:
In [27]:
matrixdepot("magic", Float32, 5)
Out[27]:
A magic square is an arrangement of n^2
distinct numbers in a n-by-n
square matrix such that the numbers in each row, each column, and the numbers on the diagonal and anti-diagonal all add up to the same number.
In [16]:
sum(A,1)
Out[16]:
In [17]:
sum(A,2)
Out[17]:
In [19]:
sum(diag(A))
Out[19]:
In [22]:
p = [5:-1:1]
sum(diag(A[:,p]))
Out[22]:
In [7]:
matshow(A)
Out[7]:
In [9]:
B = matrixdepot("wilkinson", 12)
Out[9]:
In [10]:
matshow(full(B))
Out[10]:
In [16]:
matrixdepot("rando", Bool, 6)
Out[16]:
We set the precision of BigFloat
and generate matrices of arbitrary precision.
In [26]:
set_bigfloat_precision(200)
H = matrixdepot("hilb", BigFloat, 5)
Out[26]:
PolarFact
is a Julia package for computing the matrix polar decomposition. It includes algorithms like Newton's method (:newton
), the QDWH method (:qdwh
), a hybrid Newton's method (:hybrid
) and the
Halley method (:halley
).
We can use Matrix Depot to compare the performance of these algorithms.
In [11]:
Pkg.add("PolarFact")
In [10]:
using PolarFact
Compare the number of iterations of four polar decomposition algorithms
In [3]:
n = length(matrixdepot("inverse", "symmetric"))
niters = zeros(4, n)
for (i,mat) in enumerate(matrixdepot("inverse", "symmetric"))
A = matrixdepot(mat, Float64, 12)
A = full(A)
r_newton = polarfact(A, alg = :newton)
r_qdwh = polarfact(A, alg = :qdwh)
r_hybird = polarfact(A, alg = :hybrid)
r_halley = polarfact(A, alg = :halley)
niters[1, i] = r_newton.niters
niters[2, i] = r_qdwh.niters
niters[3, i] = r_hybird.niters
niters[4, i] = r_halley.niters
end
In [5]:
plt.figure()
for i in 1:4
x = [1:n]
y = niters[i,:][:]
plt.plot(x,y, ".-")
plt.hold("on")
end
plt.xlabel("test matrices")
plt.ylabel("number of iterations")
plt.legend(["newton", "qdwh", "hybird", "halley"])
Out[5]:
We first run MatrixDepot.update()
, which download two html matrix name lists.
In [2]:
MatrixDepot.update()
Matrix Depot first check if the matrix is on the matrix data list before downloading it.
In [20]:
MatrixDepot.get("Collection/somematrix")
HB/1138_bus (undirected graph drawing, UF Sparse Matrix Collection, Tim Davis and Yifan Hu)
In [3]:
MatrixDepot.get("HB/1138_bus")
In [4]:
matrixdepot()
In [5]:
matrixdepot("HB/1138_bus")
In [6]:
A = matrixdepot("HB/1138_bus", :r)
Out[6]:
In [23]:
spy(A)
Out[23]:
show all the downloaded matrices
In [3]:
matrixdepot("data")
Out[3]:
Add a property for all the matrix representation of graphs
In [2]:
@addproperty graphs = ["California", "ca-HepTh", "wb-cs-stanford", "G66"]
Out[2]:
In [2]:
matrixdepot("graphs")
Out[2]: