You simply don't want to do this:
f[a[1,3]_,a[5,2]_]:=a[1,3] + a[5,2]
I don't mean because it's not syntactically correct, I mean that it doesn't make any sense as a function definition. When you define a function with formal arguments, you don't want to add overly specific semantics to your variables. For example, you'd never define a function that computes the area of a circle like this:
circleArea[radius16_] := Pi * radius16^2
The "16" bit just has nothing to do with the radius or circles or area or anything. It's a distraction.
So, in
f[a[1,3]_,a[5,2]_]:=a[1,3] + a[5,2]
the indices 1,3
in a[1,3]
can't possibly mean anything. As they are used in the right hand side, a[1,3] + a[5,2]
, they are just formal arguments.
On the other hand, if what you're trying to do is really to index into something, then the indices do mean something. Let's say I have
a = {{1, 2}, {3, 4}}
and I want to define a function that adds the diagonal values. I could do this:
f[x_] := x[[1, 1]] + x[[2, 2]]
f[a]
(* 5 *)
Now those indices mean something, but the argument x
is still just a formal argument that is expected to represent a 2x2 matrix. (You could enforce and check that it is a matrix, but I haven't shown that.)
And now you can send your individual values to the Print
function like this:
Scan[Print, a, {2}]
a[1,1] a[1,2], ...
? Also you could use a list of lists (matrix)a = {{...}, {...}, {...}, ...}
? $\endgroup$a[1,1] a[1,2], ...
inside a function $\endgroup$