kron(), that's pretty useful for doing multidimensional finite difference methods on PDEs:
kron()takes the Kroenecker product of two matrices. This is especially useful when constructing the large, sparse matrices needed for finite difference approximations.
K is the tridiagonal matrix created for a central difference approximation to the second derivative:
n = 5;
K = spdiag(2*ones(n,1),0) + spdiag(-ones(n-1,1),-1) + spdiag(-ones(n-1,1),1);
K is the differences for a 1D row of points, now we can create the 2-dimensional version for a plane of points with
K2D = kron(speye(n),K) + kron(K,speye(n));
The extension to 3 dimensions is exactly as before, now we have a matrix describing the differences between points on the same line in the first sub and superdiagonal, differences across lines in the next bands out from those, and differences across planes in the furthest out bands:
K3D = kron(speye(n),K2D) + kron(K2D,speye(n));
Pretty simple! Now you're ready to solve multidimensional partial differential equations.