function A = nma_lap3d(n) %generate 3D sparse matrix for poisson 3D % filename: nma_lap3d.m % % Function to generate 3D matrix for poisson 3D % by Nasser M. Abbasi % based on 2D code by Dr Robert Guy, extended to 3D % % INPUT: % n : Number of internal grid point along one dimension. % Hence, for n=3, this means there are n^3 unknowns % % OUTPUT: % A: the A matrix to use in solving the 3D problem for % HW3, problem 3, part(b). % L2=nma_lap2d(n,n); e=ones(n^3,1); L=spdiags([e e],[-n^2 n^2],n^3,n^3); Iz=speye(n); A=kron(Iz,L2)+L; end