-
Notifications
You must be signed in to change notification settings - Fork 0
/
lap2DPeriodic.m
63 lines (56 loc) · 1.37 KB
/
lap2DPeriodic.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function [L] = lap2DPeriodic(N, h);
%
% [L] = lap2DPeriodic(N, h)
%
% Constructs the 2D Laplacian for a periodic square mesh using
% the standard 5-point stencil.
%
% Returns:
% L = discrete Laplacian
%
% Input:
% N = number of mesh points in each direction
% h = mesh width
%
%
%
% License: This code is free to use for any purposes, provided
% any publications resulting from the use of this code
% reference the original code/author.
%
% Author: Samuel Isaacson ([email protected])
% Date: 11/2007
%
% Please notify the author of any bugs, and contribute any
% modifications or bug fixes back to the original author.
%
% Disclaimer:
% This code is provided as is. The author takes no responsibility
% for its results or effects.
M = N * N;
% Periodic 2D Laplace Operator on Square:
isPeriodic = 1;
e = ones(M,1);
ed = -4*e;
if( ~isPeriodic )
ed(N:N:M) = -3;
ed(1:N:M) = -3;
ed(1) = -2;
ed(N) = -2;
ed((N-1)*N+1) = -2;
ed(N*N) = -2;
end
eu1 = ones(M,1);
eu1((N+1):N:M) = 0;
ed1 = ones(M,1);
ed1(N:N:M) = 0;
L = spdiags([e ed1 ed eu1 e], [-N -1:1 N], M, M);
if( isPeriodic )
for(i = 1:N)
L( i, N*N-N+i ) = 1;
L( N*N-N+i, i ) = 1;
L( (i-1)*N+1, i*N ) = 1;
L( i*N, (i-1)*N+1 ) = 1;
end
end
L = L ./ (h*h);