Matrix Operations in MATLAB PDF
Matrix Operations in MATLAB PDF
Multiplication
The multiplication of two matrices is performed in a special manner. For a matrix , where , we define the product of and to be the matrix matrix and a
So,
The product of the matrices en can only be formed if the sizes of and are compatible: the number of columns of has to be equal to the number of rows of . If exists, does not need to exist. If as well as exists, we generally do not have that . Within MATLAB, the matrix product of and is always defined if either or is a number. Multiplication of a matrix by a number (scalar multiplication) boils down to multiplication of all matrix elements by that number. The symbol for matrix multiplication in MATLAB is * , i.e.,
> >A * B
www.imc.tue.nl/IMC-main/imc-main-node38.html
1/5
9/17/13
> >A + B
and subtraction:
> >A B
of two matrices and is performed by addition and subtraction of the separate elements of the matrix. In MATLAB, these operations are defined if the sizes of the matrices are the same or if one of the matrices is a scalar. In the latter case the scalar is added to or subtracted from every element of the matrix.
Raising to a power
The command
> >A ^ p
to the
power. If
is a positive integer,
of by itself. The matrix needs to be square (i.e., the number of rows is equal to the number of columns) in order to be able to perform this operation.
Transposition
Let be an with matrix. Then the transpose of . So: , denoted by , is the matrix
(4.2)
In MATLAB, the command t r a n s p o s e ( A )or A '(the latter only for real valued matrices) calculates the transpose of the matrix . To give an example:
> >[ 123 ] '
www.imc.tue.nl/IMC-main/imc-main-node38.html
2/5
9/17/13
If the matrix contains complex, non-real, elements, then the command A 'does not only reflect the matrix with respect to the diagonal, but it also takes the complex conjugate of every element. If you only want to calculate the reflection of with respect to the diagonal, you can do this with the command A . ' . We illustrate this by means of two examples.
> >A=[ 2 + 3 * i4 + 5 * i 2 3 ] A= 2 . 0 0 0 0 + 3 . 0 0 0 0 i4 . 0 0 0 0 + 5 . 0 0 0 0 i 2 . 0 0 0 0 3 . 0 0 0 0 > >A ' a n s= 2 . 0 0 0 0 3 . 0 0 0 0 i 4 . 0 0 0 0 5 . 0 0 0 0 i > >A . ' a n s= 2 . 0 0 0 0 + 3 . 0 0 0 0 i 4 . 0 0 0 0 + 5 . 0 0 0 0 i
2 . 0 0 0 0 3 . 0 0 0 0
2 . 0 0 0 0 3 . 0 0 0 0
You need to take this into account when dealing with symbolic matrix elements (or you have to define your symbolic elements as reals).
> >s y m sab > >A=[ ab 12 ] A= a ,b 1 ,2 > >A ' a n s= [c o n j ( a ) , [c o n j ( b ) , > >A . ' a n s= [a ,1 ] [b ,2 ]
1 ] 2 ]
No division
A division operator is not defined for matrices. However, sometimes one needs to find a matrix such that for given matrices and , where and are of appropriate dimensions. This is discussed in Section 4.4.
9/17/13
In this paragraph we mention some commands that have a matrix as their argument. The command:
> >i n v ( A )
if
such that
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.
> >i n v ( [ 11 ; 00 ] ) W a r n i n g :M a t r i xi ss i n g u l a rt ow o r k i n gp r e c i s i o n . a n s= I n f I n f
I n f I n f
Sometimes, an inverse with finite elements is found by MATLAB, which may be inaccurate. In that case, MATLAB will present the following warning:
> >i n v ( [ 1 e 80 ; 01 e 8 ] ) W a r n i n g :M a t r i xi sc l o s et os i n g u l a ro rb a d l ys c a l e d . R e s u l t sm a yb ei n a c c u r a t e .R C O N D=1 . 0 0 0 0 0 0 e 0 1 6 . a n s= 1 . 0 e + 0 0 8* 1 . 0 0 0 0 0 0 0 . 0 0 0 0
The command:
> >d e t ( A )
gives a vector containing the eigenvalues of the matrix often used in the form
www.imc.tue.nl/IMC-main/imc-main-node38.html
. The matrix
9/17/13
This results in matrices and , so that . Every column of is an eigenvector of , while is a diagonal matrix with diagonal elements equal to the eigenvalues of associated with the eigenvectors in the corresponding columns of . 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.
Previous
Next
Up
Contents
Esteur 2010-03-22
www.imc.tue.nl/IMC-main/imc-main-node38.html
5/5