0

I am trying to select a matrix element using Part or [[ ]] but somehow it doesn't work.

d = MatrixForm[
  Table[If[k == n, 
    0, ((k*n)/(k^2 - n^2))*Exp[I*Pi^2*(k^2 - n^2)*f]], {k, 4}, 
       {n, 4}]]
d[[1, 2]]

Output:

{(2/3)*E^(3*I*f*Pi^2), 0, -(6/5)/E^(5*I*f*Pi^2), -(2/3)/
  E^(12*I*f*Pi^2)}

What shows up is the 2nd row instead. I tried copying the output of d in matrix form and writing [[1,2]] following it and it did work, outputting the element of the first row and second collumn.

MatrixForm[{{0, -(2/(3*E^(3*I*f*Pi^2))), -(3/(8*E^(8*I*f*Pi^2))), 
         -(4/(15*E^(15*I*f*Pi^2)))}, {(2/3)*E^(3*I*f*Pi^2), 0, 
         -(6/(5*E^(5*I*f*Pi^2))), -(2/(3*E^(12*I*f*Pi^2)))}, 
       {(3/8)*E^(8*I*f*Pi^2), (6/5)*E^(5*I*f*Pi^2), 
    0, -(12/(7*E^(7*I*f*Pi^2)))}, 
       {(4/15)*E^(15*I*f*Pi^2), (2/3)*E^(12*I*f*Pi^2), (12/7)*
     E^(7*I*f*Pi^2), 0}}] [[1, 2]]

Output:-(2/3) E^(-3 I f \[Pi]^2)

But I don't understand why d[[1,2]] doesn't work.

  • 1
    If[k == n, 0, ((k*n)/(k^2 - n^2))*Exp[I*Pi^2*(k^2 - n^2)*f]], {k, 4}, {n, 4}]) // MatrixForm d[[1, 2]]``` : The reason is that MatrixForm output have Head equal to MatrixForm. These are not lists any more, so the `Part` does not work. – Syed Oct 02 '21 at 15:26
  • 1
    N.B.: MatrixForm (like other *Form functions) is for formatting only! It doesn't turn something into a matrix. a list of equal-length lists is, by itself, already considered a matrix in mathematica. – thorimur Oct 03 '21 at 00:14
  • Thanks for letting me know. I am fairly new in mathematica and didnt know about it. It has now worked once I delete //MatrixForm – ForacleFunacle Oct 03 '21 at 15:33

0 Answers0