0

I make a list of 5 empty $3 \times 3$ matrices via

 Table[m[i]=IdentityMatrix[3]-IdentityMatrix[3],{i,1,5}]

However when I want to change an entry via

 m[2][[3,4]]=5

I get an error which reads:

Set::setps: m[2] in the part assignment is not a symbol. >>

Any ideas? Thanks

Mike
  • 585
  • 3
  • 14
  • 2
    Why not do something like m = ConstantArray[0, {5, 3, 3}] and then do m[[2, 3, 4]] = 1? – J. M.'s missing motivation Mar 30 '17 at 05:37
  • You mean instead of explicitly indexing the matrices, placing them in a list and identifying them there. That does make the way I call the matrices a little more intuitive, I don't have the single brackets and then the double brackets. However, I'm curious why indexing the matrices directly messes with the assignment I make. – Mike Mar 30 '17 at 05:40
  • 1
    The docs for the error message just says "Part assignments are implemented only for parts of the value of a symbol." So since m[2] is not a symbol itself, but a reference to one of the DownValues of the symbol m, this is what you get. – Marius Ladegård Meyer Mar 30 '17 at 05:42
  • Also, note the difference between Do and Table, we don't use Table just for side effects ;) – Marius Ladegård Meyer Mar 30 '17 at 05:43
  • 2
    You can do e.g. m[2] = ReplacePart[m[2], {3, 4} -> 5] but that copies the whole of m[2] so I would prefer @J.M. 's suggestion. – Marius Ladegård Meyer Mar 30 '17 at 05:49
  • Related, perhaps duplicate: http://mathematica.stackexchange.com/q/7214/121 – Mr.Wizard Mar 30 '17 at 06:02

1 Answers1

2

As the comments read, the problem is that m[2] is not a symbol but a reference to a value of the symbol m, so to change the value there I have to actually replace it via:

 m[2]=ReplacePart[m[2],{4,5}->5].

Which copies the entirety of m[2] and doesn't look all that pretty.

J.M.'s suggestion is to just make a list of the matrices and refer to them from there.

Mike
  • 585
  • 3
  • 14