## Special matrices

Besides by direct input, some special matrices can also be formed directly with MATLAB commands. These matrices are:
• An zero matrix, i.e., a matrix in which all elements have the value zero, is formed with the command zeros(m,n).
• An matrix whose elements all equal one is formed with the command ones(m,n).
• An matrix with random numbers, uniformly distributed between 0 and 1, is formed with the command rand(m,n).
• An diagonal matrix, i.e., a matrix in which only the diagonal elements (the elements with equal row and column indices) have a non-zero value, is formed with the command diag(v), where is a vector containing the diagonal elements.
• An unit matrix, i.e., a diagonal matrix for which all diagonal elements equal one, is formed with the command eye(n).
If you want to give a matrix the same size as a given matrix , then you can do this by using the command size. For example, the command

>> zeros(size(A))

forms a zero matrix with the same size as the matrix . Of the above commands, only the command diag accepts a matrix as its argument. The result of the command diag(A), where is a matrix, is a column vector consisting of the diagonal elements of .

Esteur 2010-03-22