Matrix operations in MATLAB

**Multiplication**

The multiplication of two matrices is performed in a special manner. For a

So,

The product of the matrices

`*`

, i.e.,
`>> A*B`

**Addition and subtraction**

Addition

`>> A+B`

and subtraction:

`>> A-B`

of two matrices

**Raising to a power**

The command

`>> A^p`

raises the matrix

**Transposition**

Let

(4.2) |

In MATLAB, the command

`transpose(A)`

or `A'`

(the latter only for real valued matrices) calculates the transpose of the matrix
`>> [1 2 3]'`

forms the column matrix:

>> 1 2 3

If the matrix
`A'`

does not only reflect the matrix
`A.'`

. We illustrate this by means of two examples.

>> A = [2+3*i 4+5*i 2 3] A = 2.0000+3.0000i 4.0000+5.0000i 2.0000 3.0000 >> A' ans = 2.0000-3.0000i 2.0000 4.0000-5.0000i 3.0000 >> A.' ans = 2.0000+3.0000i 2.0000 4.0000+5.0000i 3.0000You need to take this into account when dealing with symbolic matrix elements (or you have to define your symbolic elements as reals).

>> syms a b >> A = [a b 1 2] A = a, b 1, 2 >> A' ans = [ conj(a), 1] [ conj(b), 2] >> A.' ans = [ a, 1] [ b, 2]

**No division**

A division operator is not defined for matrices. However, sometimes one needs to find a matrix

**Matrix functions in MATLAB**

In this paragraph we mention some commands that have a matrix as their argument.

The command:

`>> inv(A)`

calculates the inverse of a square matrix

If no inverse exists, MATLAB will give a warning the matrix is singular. Possibly, it will present a matrix, with Inf as elements, e.g.

>> inv([1 1;0 0]) Warning: Matrix is singular to working precision. ans = Inf Inf Inf InfSometimes, an inverse with finite elements is found by MATLAB, which may be inaccurate. In that case, MATLAB will present the following warning:

>> inv([1e-8 0;0 1e8]) Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.000000e-016. ans = 1.0e+008 * 1.0000 0 0 0.0000

The command:

`>> det(A)`

calculates the determinant of

The command:

`>> rank(A)`

gives the rank of the matrix

The command:

`>> eig(A)`

gives a vector containing the eigenvalues of the matrix

`>> [S,D] = eig(A)`

This results in matrices

**Remark:** The commands above can also be used for symbolic matrices. However, you have to be aware of the fact that there are other matrix functions that cannot be used for symbolic matrices. Furthermore, there are also commands that can only be used for symbolic matrices.

Esteur 2010-03-22