MATLAB Programming/Vector and Matrices/Special Matrices

Matrix of ones
We can create matrix consists using the functions ones with m numbers of rows and n numbers of columns

Matrix of zeroes
We can create matrix consists using the functions zeros with m numbers of rows and n numbers of columns

Identity Matrices
An identity matrix is a square matrix in which each of the elements of its diagonal is a 1 and each of the other elements is a 0. An identity matrix is used for following purposes: (a) To verify whether any two given matrices are inverses of each other. A and B in examples below are inverse to one another (b) To find the inverse of a matrix Note 1: Not every inverse matrix can use have identity matrix Note 2: Command "eye(n)" can be used to create identity matrix in a flash, n is the size of matrix

(c) To find the eigenvalues and eigenvectors. Eigenvalue is defined as a scalar associated with a given linear transformation of a vector space and having the property that there is some non-zero vector which when multiplied by the scalar is equal to the vector obtained by letting the transformation operate on the vector.

Let say we have a matrix A as followed:

$$\mathbf{A} = \begin{bmatrix} 1 & 4 \\ 3 & 2 \\ \end{bmatrix}.$$

To find lambda, we need to know the equation for finding eigenvalue with following formula : $$ | A-\lambda I | = 0 $$ But MATLAB provided a simple way to find eigenvalue using command "eig"

Magic Square Matrices
A magic square is basically where the sum of the elements in each column and the sum of the elements in each row are the same and there are no repeating numbers. We can create a magic square use this command M=magic(n). The order n must be a scalar greater than or equal to 3 in order to create a valid magic square.

For more info, can refer to this well written Wikibooks on this topic: Puzzles/Luoshu Squares

For example, we can create a magic square with matrices 5 by 5