Question: How to update a matrix in a proc?

I expect this proc to return a matrix of all ones but it returns a matrix of all zeros.  Why does it do that?

doit := proc()  
  local i, j, M;                                     
  M := Matrix(3,3);                    
  for i from 1 to 3 do  
    for j from 1 to 3 do  
      M[i][j] := 1;                                      
    end do;                             
  end do;              
  return M;  
end proc:                                           

doit();                            
                                 [0    0    0]
                                 [           ]
                                 [0    0    0]
                                 [           ]
                                 [0    0    0]

 

Please Wait...