Consider the following two codes: Code 1:
restart:
with(LinearAlgebra):
M1,M2 := Vector(2,fill=Matrix(4,4))$2:
M1[1] := M1[1] + IdentityMatrix(4):
M2[1] := M2[1] + IdentityMatrix(4):
M1[1];
Code 2:
restart:
with(LinearAlgebra):
M1,M2 := Vector(2,fill=Matrix(4,4)),Vector(2,fill=Matrix(4,4)):
M1[1] := M1[1] + IdentityMatrix(4):
M2[1] := M2[1] + IdentityMatrix(4):
M1[1];
According to my knowledge they ought to give identical output: the 4-dimensional identity matrix. But they don't. The first code gives twice that, as if M1[1] and M2[1] reference the same object in memory. The second code gives the correct answer. Can anyone please explain this to me? Am I fundamentally misunderstanding something?

Please Wait...