Question: Tracking Matrix changes in a procedure

I have written a procedure in which I create a matrix and then manipulate (change) the matrix until certain conditions are met (a while loop).  I would like to know when an iteration of my loop does not make any changes to my matrix (but the stopping conditions are not yet met) so that I do not enter into an infinite loop.

The matricies I plan to deal with shouldn't be too large (25x25 is the largest I've seen in practice, I doubt I'd ever let it go over 100x100), so I'm willing to sacrifice a little memory to create a second matrix every iteration of the loop before the original matrix is operated upon.  A sketch of my procedure is as follows:

P:=proc(A,n)
local M,N,z;

M,N:=Matrix(n,n,1)$2:
z:=otherproc(A);

while has(M,1) do
  N:=M;
  #modify M based on information in z
  #update z
  if N=M then return "Iteration failed to update M.",M;fi;
od:
return M;
end proc:

 

The problem is that each time N is assigned in the loop, Maple seems to simply point N to the object M, and so N=M evaluates to true every time.

Is there a (simple) way to get Maple to actually dupilcate the matrix M at each iteration of the loop so that its state before and after manipulation can be compared? 

Please Wait...