home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / DATAFUN.DI$ / DEL2.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  915 b   |  35 lines

  1. function V = del2(U)
  2. %DEL2    Five-point discrete Laplacian.
  3. %    V = del2(U) is a matrix the same size as U with each element
  4. %    equal to the difference between an element of U and the average
  5. %    of its four neighbors.  For the "corners" and "edges", only two
  6. %    or three neighbors are used.
  7. %
  8. %    See also GRADIENT, DIFF.
  9.  
  10. %    C. Moler, 7-19-91, 2-1-92.
  11. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  12.  
  13. [p,q] = size(U);
  14. e = [2:q q];
  15. w = [1 1:q-1];
  16. n = [1 1:p-1]';
  17. s = [2:p p]';
  18.  
  19. % Interior
  20. V = 0.25*(U(n,:) + U(s,:) + U(:,e) + U(:,w)) - U;
  21.  
  22. % Edges
  23. V(1,:) = 0.5*(U(1,e) + U(1,w)) - U(1,:);
  24. V(p,:) = 0.5*(U(p,e) + U(p,w)) - U(p,:);
  25. V(:,1) = 0.5*(U(n,1) + U(s,1)) - U(:,1);
  26. V(:,q) = 0.5*(U(n,q) + U(s,q)) - U(:,q);
  27.  
  28. % Corners
  29. if p > 1 & q > 1
  30.    V(1,1) = 0.5*(V(1,2) + V(2,1));
  31.    V(1,q) = 0.5*(V(1,q-1) + V(2,q));
  32.    V(p,1) = 0.5*(V(p,2) + V(p-1,1));
  33.    V(p,q) = 0.5*(V(p,q-1) + V(p-1,q));
  34. end
  35.