0
$\begingroup$

I want to create a matrix of functions. As explained in this question, I can create a matrix of variables:

labels = {"A", "B", "C"};
M = Table[Symbol["f" <> i <> j], {i, labels}, {j, labels}];
M // MatrixForm

enter image description here

But I want to create a matrix with functions fAA[t] etc. The motivation is that I am generating a matrix of differential equations that I will solve with DSolve. I tried the following simple modification but it does not work

M = Table[Symbol["f" <> i <> j <> "[t]"], {i, labels}, {j, labels}];
$\endgroup$
  • 2
    $\begingroup$ Table[Symbol["f" <> i <> j][t], {i, labels}, {j, labels}] ? $\endgroup$ – andre314 Aug 13 at 13:33
  • $\begingroup$ Oh yeah. I think that does the job. Will post if there are any issues. Thanks! $\endgroup$ – Tom Aug 13 at 13:35
3
$\begingroup$

Recommend that you consider using an indexed variable.

labels = {"A", "B", "C"};

If f[x, y] is distinct from f[y, x]

ClearAll[f]

Format[f[x_, y_]] := Subscript[f, ToString[x] <> ToString[y]]

(m = Outer[f[##][t] &, labels, labels]) // MatrixForm

enter image description here

If f[x, y] is equal to f[y, x]

ClearAll[f]

Format[f[x_, y_]] := Subscript[f, ToString[x] <> ToString[y]]

(m = Outer[(f @@ Sort[{##}])[t] &, labels, labels]) // MatrixForm

enter image description here

$\endgroup$
  • $\begingroup$ Why do you recommend indexed versus not indexed? For some reason I thought we recommended against indexes with subscripts? Regardless, lovely code!! $\endgroup$ – CA Trevillian Aug 21 at 3:59
  • $\begingroup$ @CATrevillian - subscripts/superscripts can case problems with some functions/commands. Rather than try to remember which ones, I always use indexed variables and format as desired. $\endgroup$ – Bob Hanlon Aug 21 at 19:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.