Revision history [back]

Defining functions acting on matrix elements?

Hi guys, how can I define a function able to act on the elements of a matrix, with the matrix being the input to the function? I would like the function to be a callable symbolic expression, which I hear can be differentiated and so on, whereas other entities cannot.

Here's a sample of what I mean:

f(M) = M[0,0]+M[1,1]


that is, the user will ensure that M is correctly defined as a matrix of size at least 2x2 before being passed to f(M), but at this stage the symbol M is intended just as a dummy variable, similar to z in a definition like g(z) = conjugate(z). Unfortunately, my code does not seem to work...