To make a matrix to represent an arbitrary 2d scalar field f(x,y), apply evalformula to matrices that you first obtain with creatematrix "x" and creatematrix "y".
Be aware that evalformula can work only on arrays of real. This is why by default creatematrix returns an array of real, not a matrix, unless you explicitly specify creatematrix [...] as matrix. Thus:
-
you must be sure that you are manipulating arrays of real, not matrices,
-
once you get the desired array of real you must make it into a matrix: use ArrayToMatrix.
set xa to creatematrix "x" ncols 20 nrows 15 range {-1.0, 1.0}
set ya to creatematrix "y" ncols 20 nrows 15 range {-1.0, 1.0}
set za to evalformula "2*x+3*y" with {x:xa, y:ya}
set z to ArrayToMatrix(za, 20, 15)
Here the z matrix describes the following domain: {-1 < x < 1, -1 < y < 1, z=2x+3y}.
|