Code covered by the BSD License  

Highlights from
Laplacian in 1D, 2D, or 3D

5.0

5.0 | 3 ratings Rate this file 41 Downloads (last 30 days) File Size: 5.27 KB File ID: #27279
image thumbnail

Laplacian in 1D, 2D, or 3D

by Andrew Knyazev

 

17 Apr 2010 (Updated 01 Aug 2011)

Sparse (1-3)D Laplacian on a rectangular grid with exact eigenpairs.

| Watch this File

File Information
Description

The code computes the exact eigenpairs of (1-3)D negative Laplacian on a rectangular finite-difference grid for combinations of Dirichlet, Neumann, and Periodic boundary conditions using explicit formulas from
http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors_of_the_second_derivative

The code can also compute the sparse matrix itself, using Kronecker sums of 1D Laplacians. For more information on tensor sums, see
http://en.wikipedia.org/wiki/Kronecker_sum_of_discrete_Laplacians

Example, compute everything for 3D negative Laplacian with mixed boundary conditions:
[lambda,V,A] = laplacian([100,45,55],{'DD' 'NN' 'P'}, 20);
Compute only the eigenvalues:
lambda = laplacian([100,45,55],{'DD' 'NN' 'P'}, 20);
Compute the matrix only:
[~,~,A] = laplacian([100,45,55],{'DD' 'NN' 'P'});

GNU OCTAVE compatible.

This code is a part of the BLOPEX eigensolver package, see
http://en.wikipedia.org/wiki/BLOPEX
or go directly to
http://code.google.com/p/blopex/

Copyright owners: Bryan C. Smith and Andrew V. Knyazev

MATLAB release MATLAB 7.11 (2010b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
07 Nov 2010 Thomas Clark

This works extremely well, extremely flexibly and with no fuss.

I'm SO upset I didn't find this earlier. I've basically coded an alternative, already, but it isn't close to being as good.

Thank you very much!

12 Sep 2011 Mr Smart  
11 Mar 2012 Marios Karaoulis

Hi, useful add on, but one question.
Let's say we have a 3x3 grid, then why all the element on the diagonal are 4? Should be something like this
[2 -1 0 -1 0 0 0 0 0
 -1 3 -1 0 -1 0 0 0
 0 -1 2 0 0 -1 0 0 0 ....

...]

Only line 5 should have 4 on it's diagonal.

12 Mar 2012 Andrew Knyazev

Re: Marios Karaoulis

It depends on boundary conditions. Your example apparently uses Neumann boundary condition as is http://en.wikipedia.org/wiki/Laplacian_matrix#As_an_approximation_to_the_negative_continuous_Laplacian
while the code default us the Dirichlet boundary conditions. To get your matrix, please use

[~,~,A]=laplacian([3 3],{'NN' 'NN'})

full(A) shows what you want:

     2 -1 0 -1 0 0 0 0 0
    -1 3 -1 0 -1 0 0 0 0
     0 -1 2 0 0 -1 0 0 0
    -1 0 0 3 -1 0 -1 0 0
     0 -1 0 -1 4 -1 0 -1 0
     0 0 -1 0 -1 3 0 0 -1
     0 0 0 -1 0 0 2 -1 0
     0 0 0 0 -1 0 -1 3 -1
     0 0 0 0 0 -1 0 -1 2

14 Mar 2012 Marios Karaoulis

Thanks for the reply Andrew, you are right.

Please login to add a comment or rating.
Updates
30 Apr 2010

updated description

01 Aug 2011

Revision 1.1 changes: rearranged the output variables, always compute the eigenvalues, compute eigenvectors and/or the matrix on demand only.

Tag Activity for this File
Tag Applied By Date/Time
matrix Andrew Knyazev 19 Apr 2010 10:57:25
mathematics Andrew Knyazev 19 Apr 2010 10:57:25
laplacian wang Jacken 21 Apr 2010 06:23:20
boundary condition Thomas Clark 07 Nov 2010 13:22:00
pde Thomas Clark 07 Nov 2010 13:22:00
poisson Thomas Clark 07 Nov 2010 13:22:00
boundary conditions Thomas Clark 07 Nov 2010 13:22:00
1d Thomas Clark 07 Nov 2010 13:22:00
2d Thomas Clark 07 Nov 2010 13:22:00
3d Thomas Clark 07 Nov 2010 13:22:00
eigenfunction Andrew Knyazev 02 Aug 2011 11:02:48
eigenvector Andrew Knyazev 02 Aug 2011 11:02:48
eigenvalue Andrew Knyazev 02 Aug 2011 11:02:48
1d Andrew Knyazev 02 Aug 2011 11:02:48
2d Andrew Knyazev 02 Aug 2011 11:02:48
3d Andrew Knyazev 02 Aug 2011 11:02:48
boundary condition Andrew Knyazev 02 Aug 2011 11:02:48
boundary conditions Andrew Knyazev 02 Aug 2011 11:02:48
laplacian Andrew Knyazev 02 Aug 2011 11:02:48
pde Andrew Knyazev 02 Aug 2011 11:02:48
poisson Andrew Knyazev 02 Aug 2011 11:02:48
finitedifference Andrew Knyazev 02 Aug 2011 11:02:48
tensor product Andrew Knyazev 02 Aug 2011 11:02:48
kronecker sum Andrew Knyazev 02 Aug 2011 11:02:48

Contact us at files@mathworks.com