Download MuPAD from SciFace

MuPAD Pro Computing Essentials - Examples 

Example 5.5 To produce a matrix of any dimension

Suppose that we wish to produce a square matrix of given dimensions nxn where all the elements on the diagonal are equal to 1, elements above the diagonal are equal to 0 and elements under the diagonal are equal to (1/(nm)), where n and m are row and column numbers respectively. Developing such a procedure is very straightforward. Check the enclosed example:

  • 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(9)

  

TOP