MuPAD Pro Computing Essentials, 2nd Edition

Example 5.5 To produce a matrix of any dimension

 
diagMatrix := proc(n)
 local row, column;
begin
   A := matrix(n,n);
   for row from 1 to n do
      for column from 1 to n do
         if row=column then 
            A[row,column] := 1 
         end;
         if row>column then
            A[row,column] := 1/(row*column)
         end;
         if row<column then 
            A[row,column] := 0
         end
      end;
   end;
   return(A)
end:
 
diagMatrix(10)

 

© Miroslaw Majewski, Abu Dhabi,  Update  26-10-2004