1
$\begingroup$

Newbie here. I want to define a (user-defined)function to return symmetric matrices, as I need to define quite a few tensors. I am able to do this using strings. But I need the matrix entries to be variables and not strings.

I have this function now.

matF[fn_, size_] := Module[{mat}, 
mat = Table[ToString[fn]<>ToString[j]<>ToString[i],{i, 1,size},{j,1,i}];
MapThread[Join, {mat, Rest /@ Flatten[mat, {{2}, {1}}]}]];
A = matF[A, 3];

which returns the following matrix:

enter image description here

Is there a way to accomplish something similar, where the entries are variables and not strings? Any help is much appreciated!!

$\endgroup$
4
  • $\begingroup$ So instead of "A11" you want A11? You can use ToExpression but A[1,1] will be more convenient. $\endgroup$ – Kuba Feb 20 '18 at 9:08
  • $\begingroup$ You could use Symbol["A" <> "11"] $\endgroup$ – José Antonio Díaz Navas Feb 20 '18 at 14:11
  • $\begingroup$ How about: Array[a, {3, 3}] this defines a 3 by 3 array of variables. $\endgroup$ – bill s Feb 20 '18 at 15:01
  • $\begingroup$ Table[Subscript[A, i, j], {i, 3}, {j, 3}] // MatrixForm with subscript $\endgroup$ – user49047 Oct 10 '18 at 9:08

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.