File: poisson2d.m

package info (click to toggle)
python-scipy 0.5.2-0.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 33,888 kB
  • ctags: 44,231
  • sloc: ansic: 156,256; cpp: 90,347; python: 89,604; fortran: 73,083; sh: 1,318; objc: 424; makefile: 342
file content (18 lines) | stat: -rw-r--r-- 454 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
% Create sparse 2D Poisson matrix
%
% Used for benchmarking element-wise assignment to sparse matrices in Matlab.
%
% $Id: poisson2d.m,v 1.3 2003/11/17 13:22:58 geus Exp $

function L = poisson2d(n)
L = spalloc(n*n, n*n, 5*n*n);
  for i = 1:n
    for j = 1:n
      k = i + n*(j-1);
      L(k,k) = 4;
      if i > 1, L(k,k-1) = -1; end
      if i < n, L(k,k+1) = -1; end
      if j > 1, L(k,k-n) = -1; end
      if j < n, L(k,k+n) = -1; end
    end
  end