You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
641 B
Julia

using SparseArrays
using MAT
if length(ARGS) == 0
println("Usage: julia laplacian.jl <N>")
exit(1)
end
N = parse(Int, ARGS[1])
println("Generating 3D Laplacian for size $N")
nx = N
ny = N
nz = N
ex = fill(1, nx - 1)
ey = fill(1, ny - 1)
ez = fill(1, nz - 1)
Dxx = spdiagm(-1 => ex, 0 => -2 * [ex; 1], +1 => ex)
Dyy = spdiagm(-1 => ey, 0 => -2 * [ey; 1], +1 => ey)
Dzz = spdiagm(-1 => ez, 0 => -2 * [ez; 1], +1 => ez)
Ix = spdiagm(0 => [ex; 1])
Iy = spdiagm(0 => [ey; 1])
Iz = spdiagm(0 => [ez; 1])
L = kron(Dxx, Iy, Iz) + kron(Ix, Dyy, Iz) + kron(Ix, Iy, Dzz)
display(sparse(L))
matwrite("laplacian_$N.mat", Dict("A" => L))