I'm working a lot with nested lists of $(x,y)$ coordinates (of a FEM-like mesh, but that's not important), like so:
nodes = { {{0,0}, {0,1}, {0,2}}, {{1,0}, {1,1}, {1,2}} }
This has the nice convenient structure that nodes[[i,j]]
gives me the $(x,y)$ coordinates of my "$(i,j)$th" node, so that nodes[[i,j]][[1]]
is my $x$ coordinate and nodes[[i,j]][[2]]
is my $y$ coordinate. This works nicely for my purposes.
How would I construct a variable size array of this kind using array[]
et. al? If I use for instance
nodes = array[array[X,2],{4,4}]
I get a 4-by-4 array where nodes[[i,j]]
is of the form {X[1],X[2]}[1,1]
. This is close to what I want, and I could change a bunch of my code to work with this, but I'd rather not - I'd love to have something where nodes[[i,j]]
looks like this:
{X[i,j][1], X[i,j][2]}
The reason I'd like to do this is I have defined some functions that take an array of nodes as input and computes some quantity, i.e. F[nodes_]:= (*something*)
, and I'd like to compute derivatives of this function with respect to each of its variables, i.e. $F_{x_i}$ or $F_{y_j}$.
I've tried various things with no success, and I've also tried looking for a similar construct in the documentation and here on SE, but I didn't see anything. Any ideas?
Edit: I had too many square braces in some of my code before. Fixed.
Array[{x[##][1], x[##][2]} &, {4, 4}]
work for you? Also, shouldn'tarray
be upper case? $\endgroup$