Exercise 6.2: Relaxation Function

Given: a two-dimensional array, A, of real values
Compose: a function of A that performs one relaxation step, returning the new array whose values at each position [i, j] are the average of the values from A of that position and that position's eight nearest neighbors, [i+/-1, j+/-1].
Note: Keep the edges of the input system constant, relax only the elements of the system having eight neighbors, and return only the relaxed subsystem. the portion that has been relaxed.
type OneDim = array [ real ];
type TwoDim = array [ OneDim ];
 
function main( A : TwoDim returns TwoDim )
 
for i in array_liml(A)   +1, array_limh(A)   -1 cross
    j in array_liml(A[i])+1, array_limh(A[i])-1
   avg := (A[i,j]      + A[i, j-1] + A[i, j+1] +
           A[i+1, j-1] + A[i+1, j] + A[i+1, j+1] +
           A[i-1, j-1] + A[i-1, j] + A[i-1, j+1]) / 9.0
returns array of avg
end for
 
end function



Previous Section


If you have any questions about this page, or want more information about the Sisal Language Project, contact:
John Feo at (510) 422-6389 or feo@diego.llnl.gov, or Tom DeBoni at (510) 423-3793 or deboni@llnl.gov.

The Sisal Language Project has been approved as a Designated Unclassified Subject Area (DUSA) K19222, as of 07 August, 1991.

LLNL Disclaimer
UCRL-MI-122601