0
$\begingroup$

I'd like to have a function that returns elements of a matrix:

MATR = Table[i + j, {i, 0, 3}, {j, 0, 3}];
ff[a_,b_] := MATR[[a,b]];

I can make second definition with no arguments. In this case function returns entire matrix in MatrixForm:

ff[] := MatrixForm[MATR];

I wonder if it possible to make a definition that makes no use of square brackets at all and does the same thing. I know this will go into OwnValues rather than DownValues. So if I just make

ff := MatrixForm[MATR];

then ff returns MatrixForm[MATR], but ff[1,1] does not work any more, it returns entire matrix in MatrixForm followed by [1,1]. Is there a workaround?

$\endgroup$
  • $\begingroup$ Might be a problem. A definition like ff[a_, b_] := (* stuff *) stores to DownValues[ff], while a definition like ff := (* stuff *) stores to OwnValues[ff]. $\endgroup$ – J. M. will be back soon Nov 12 '17 at 10:05
  • $\begingroup$ I don't think it is a good idea to try something like that, even if it was possible. Better assign key short cuts for [[ and ]]. Have a look for KeyEventTranslations.tr. $\endgroup$ – Henrik Schumacher Nov 12 '17 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.