Closed
Description
The code below, which constructs a sparse discrete lapacian (or –laplacian, actually) inside a cylinder and evaluates the smallest eigenvalue using eigs
, dies with an ARPACKException
for me:
Changing to Nx=Ny=100
works fine. However, Nx=Ny=400
is "only" a 100000x100000 (positive-definite real-symmetric) sparse matrix from a 2d grid (hence the sparse-direct solver should be efficient), and similar code works fine in Matlab.
What does this error mean? cc: @ViralBShah
# construct the (M+1)xM matrix D, not including the 1/dx factor
diff1(M) = [ [1.0 zeros(1,M-1)]; diagm(ones(M-1),1) - eye(M) ]
# sparse version (the lazy way):
sdiff1(M) = sparse(diff1(M))
# make the discrete -Laplacian in 2d, with Dirichlet boundaries
function Laplacian(Nx, Ny, Lx, Ly)
dx = Lx / (Nx+1)
dy = Ly / (Ny+1)
Dx = sdiff1(Nx) / dx
Dy = sdiff1(Ny) / dy
Ax = Dx' * Dx
Ay = Dy' * Dy
return kron(speye(Ny), Ax) + kron(Ay, speye(Nx))
end
# Define mesh for the cylinder
# Code adapted from lecture notes
Lx = 1
Ly = 1
Nx = 400
Ny = 400
x = linspace(-Lx,Lx,Nx+2)[2:end-1] # a column vector
y = linspace(-Ly,Ly,Ny+2)[2:end-1]' # a row vector
r = sqrt(x.^2 .+ y.^2) # use broadcasting (.+) to make Nx x Ny matrix of radii
i = find(r .< 1) # and get indices of points inside the cylinder
A = Laplacian(Nx,Ny,2Lx,2Ly)
Ai = A[i,i] # to make a submatrix for the Laplacian inside the cylinder
λi, Ui= eigs(Ai, nev=1, which="SM")
[ViralBShah: The title was ARPACKException needs better error message, which is fixed.]
Metadata
Metadata
Assignees
Labels
No labels