Is there a more efficient way of evaluating a function of two variables on a rectangular grid the the following nested Do loops?
fonGrid[x_, y_, f_] := Module[{n, m, fvals},
(* x is an n-by-1 vector *)
(* y is an n-by-1 vector *)
(* f is a scalar function of two variables *)
(* fvals is an m-by-
n matirx where fVals[[i,j]]=f[ x[[j]], y[[i]] ] *)
n = Length[x];
m = Length[y];
fvals = Table[0, {m}, {n}]; (* preallocate fvals *)
Do[
Do[
fvals[[i, j]] = f[x[[j]], y[[i]]];,
{i, 1, m}];,
{j, 1, n}];
fvals]
{1,2,3}instead of a matrix such as{{1,2,3}}or{{1},{2},{3}}. – Szabolcs Mar 07 '14 at 00:02Array[f, {4, 3}]– Kuba Mar 07 '14 at 00:07