/* Jacobi */
program jacobi;
config var n : integer = 5; -- Declarations
delta : float = 0.0001;
region R = [1..n, 1..n];
direction north = [-1, 0]; south = [ 1, 0];
east = [ 0, 1]; west = [ 0,-1];
procedure jacobi(); -- Entry point
var A, Temp : [R] float;
err : float;
begin
[R] A := 0.0; -- Initialization
[north of R] A := 0.0;
[east of R] A := 0.0;
[west of R] A := 0.0;
[south of R] A := 1.0;
[R] repeat -- Main body
Temp := (A@north+A@east+A@west+A@south) / 4.0;
err := max<< abs(A-Temp);
A := Temp;
until err < delta;
[R] writeln(A); -- Output result
end;
|