In [2]:
using MatrixDepot
using PyPlot
In [3]:
matrixdepot()
show all the symmetric
and pos-def
matrices in the collection
In [4]:
matrixdepot("symmetric", "pos-def")
Out[4]:
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 [5]:
matrixdepot("Collection/somematrix", :get)
HB/1138_bus (undirected graph drawing, UF Sparse Matrix Collection, Tim Davis and Yifan Hu)
In [6]:
matrixdepot("HB/1138_bus", :get)
In [7]:
matrixdepot()
In [8]:
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 [9]:
matrixdepot("data")
Out[9]:
Define a new group for a paper
In [10]:
@addgroup paper1_test = ["HB/1138_bus", "hilb", "cauchy", "pei"]
Out[10]:
In [2]:
matrixdepot("paper1_test")
Out[2]: