# MATLAB TUTORIAL, part 2.1: Matrices

How to define Matrices

"Matrix" is the Latin word for womb. The origin of mathematical matrices has a long history. The term "matrix" in combinatorics was introduced in 1850 by the British mathematician James Joseph Sylvester (1814--1897), who also coined many mathematical terms or used them in "new or unusual ways" mathematically, such as graphs, discriminants, annihilators, canonical forms, minor, nullity, and many others.

When defining a whole matrix, vectors can be combined: try for example

			[1:2:9; 2:2:10] 

A useful functonality in matlab is the easy definition of some special matrices. A zero matrix of size $$m \times n$$ can be defined by typing zeros(m,n):

			zeros(5,2)

An identity matrix (which de denote by I) of size m can defined by typing eye(m) . The following command generates a $$4 \times 4$$ identity matrix:

			eye(4)

Matrices can easily be put together, horizontally and vertically:

	 [eye(4) zeros(4)]

	[zeros(3); 3*eye(3)]
You can make your life easier by knowing a few simple tricks that can be applied when working with matrices. Elements of matrices in matlab can be referred to very easily: matrix(x,y) refers to the element in row x column y. matrix(z) refers to the element in position z, when counting is done columns first. So for example in the matrix
	 A=[1 2; 3 4]
typing the command
	 A(2)
refers to 3. When you want to refer to a whole row of a matrix, say to the second row of the matrix
	twenty=[1:10;11:20]
you can do so by typing
	first_row=twenty(1,:)
which means, choose row 1 and all columns. Equivalently,
	third_column=twenty(:,3)

chooses the third column. matlab can also easily calculate things like the trace(A), which is sum of the diagonal elements:

		trace(A)

The norm of a matrix may be thought of as its size because it is a nonnegative number. Matrix norms are directly related to vector norms. The definitions are summarized below for an $$m \times n$$ matrix A.

${\bf A} = \left[ \begin{array}{cccc} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{array} \right] .$
The operator norm corresponding to the p-norm for vectors, p ≥ 1, is:
$\| {\bf A} \|_p = \sup_{{\bf x} \ne 0} \, \frac{\| {\bf A}\,{\bf x} \|_p}{\| {\bf x} \|_p} ,$
where $$\| {\bf x} \|_p = \left( x_1^p + x_2^p + \cdots + x_n^p \right)^{1/p} .$$ The most important norms are

1-norm (is commonly known as the maximum column sum norm) of a matrix A may be computed as

$\| {\bf A} \|_1 = \max_{1 \le j \le n} \,\sum_{i=1}^n | a_{i,j} | .$
The infinity norm, $$\infty -$$ norm of matrix A may be computed as
$\| {\bf A} \|_{\infty} = \max_{1 \le i \le n} \,\sum_{j=1}^n | a_{i,j} | ,$
which is simply the maximum absolute row sum of the matrix.
In the special case of p = 2 we get the Euclidean norm (which is equal to the largest singular value of a matrix)
$\| {\bf A} \|_2 = \sup_{\bf x} \left\{ \| {\bf A}\, {\bf x} \|_2 \, : \quad \mbox{with} \quad \| {\bf x} \|_2 =1 \right\} .$
The Frobenius norm:
$\| {\bf A} \|_F = \left( \sum_{i=1}^m \sum_{j=1}^n |a_{i.j} |^2 \right)^{1/2} = \left( \mbox{tr}\, {\bf A} \,{\bf A}^{\ast} \right)^{1/2} .$

Some properties of the matrix norms are presented in the following

Theorem: Let A and B be $$m \times n$$ matrices and let $$k$$ be a scalar.

• $$\| {\bf A} \| \ge 0$$ for any square matrix A.
• $$\| {\bf A} \| =0$$ if and only if the matrix A is zero: $${\bf A} = {\bf 0}.$$
• $$\| k\,{\bf A} \| = |k| \, \| {\bf A} \|$$ for any scalar $$k.$$
• $$\| {\bf A} + {\bf B}\| \le \| {\bf A} \| + \| {\bf B} \| .$$
• $$\| {\bf A} \, {\bf B}\| \le \| {\bf A} \| \, \| {\bf B} \|$$

matlab has special commands for evaluating norms:
norm(A,1) for evaluating 1-norm of the matrix A;
norm(A,inf) for evaluating $$infty -$$norm of the matrix A;
norm(A,2) for evaluating 2-norm (Euclidean) of the matrix A;

Example. Evaluate the norms of the matrix $${\bf A} = \left[ \begin{array}{cc} 1 & -7 \\ -2 & -3 \end{array} \right] .$$

The absolute column sums of A are $$1 + | -2 | =3$$ and $$|-7| + | -3 | =10 .$$ The larger of these is 10 and therefore $$\| {\bf A} \|_1 = 10 .$$

The absolute row sums of A are $$1 + | -7 | =8$$ and $$| -2 | + |-3| = 5 ,$$ therefore, $$\| {\bf A} \|_{\infty} = 8 .$$

The Euclidean norm of A is

$\| {\bf A} \|_2 = \sup_{\bf x} \left\{ \, \sqrt{(x_1 - 7\,x_2 )^2 + (2\,x_1 + 3\,x_2 )^2} \, : \quad \mbox{with} \quad x_1^2 + x_2^2 =1 \right\} .$
To find its exact value, we evaluate the product
${\bf A}\,{\bf A}^{\ast} = \left[ \begin{array}{cc} 1 & -7 \\ -2 & -3 \end{array} \right] \, \left[ \begin{array}{cc} 1 & -2 \\ -7 & -3 \end{array} \right] = \left[ \begin{array}{cc} 50 & 19 \\ 19 & 13 \end{array} \right] .$

This matrix$${\bf A}\,{\bf A}^{\ast}$$ has two eigenvalues $$\frac{1}{2} \left( 63 \pm \sqrt{2813} \right) .$$ Hence, the Euclidean norm of the matrix A is $$\sqrt{\frac{1}{2} \left( 63 + \sqrt{2813} \right)} .$$

The Frobenius norm:

$\| {\bf A} \|_F = \left( \sum_{i=1}^m \sum_{j=1}^n |a_{i.j} |^2 \right)^{1/2} = \left( 1+49+4+9 \right)^{1/2} = \sqrt{63} = \left( \mbox{tr}\, {\bf A} \,{\bf A}^{\ast} \right)^{1/2} .$