Add construct() and its tests.
[octave.git] / construct.m
1 function A = construct(m, n, f)
2 %
3 % Construct an m-by-n matrix with entries a_ij = f(i,j).
4 %
5 if ((m < 0) || (n < 0))
6 A = NA;
7 return;
8 elseif ((m == 0) || (n == 0))
9 A = NA;
10 return;
11 end
12
13 A = zeros(m,n);
14
15 for i = [ 1 : m ]
16 for j = [ 1 : n ]
17 A(i,j) = f(i,j);
18 end
19 end
20 end