Experiment
Experiment
University of Mosul
College of Electronic Engineering
Communication Engineering Department
Experiment [4]
Mathematical Operations using MATLAB
Introduction:
MATLAB has three different types of arithmetic operations: column oriented
operations, array oriented operations and matrix arithmetic operations.
1) Column Oriented Operation
This type of operation deal with each colunm, for example
Sum(a), max(a), min(a)
2) Array Arithmetic Operation
Array arithmetic operations are carried out element by element, and can be used with
multidimensional arrays. Arithmetic operations are (addition, subtraction, multiplication,
division and power).
Addition (A+B): Adds A and B. Both of A and B must have the same size, unless one of
them is a scalar. A scalar can be added to a matrix of any size.
Subtraction (A-B): Subtracts B from A. Both of A and B must have the same size, unless
one is a scalar. A scalar can be subtracted from a matrix of any size.
.* Array multiplication (A.*B): is element by element product of the arrays A and B. A
and B must have the same size, unless one of them is a scalar.
./ Array right division (A./B): is the matrix with elements A(i,j)/B(i,j). A and B must have
the same size. Unless one of them is a scalar.
.\ Array left division (A.\B): is the matrix with elements A(i,j)\B(i,j). A and B must have
the same size. Unless one of them is a scalar.
.^ Array power (A.^B): is the matrix with elements A(ij) to the B(ij) power. A and B
must have the same size. Unless one of them is a scalar.
.' Array transpose (A.' ): is the array transpose of A. For complex matrices, this does not
involve conjugation.
3) Matrix operations
Matrix arithmetic operations are defined by the rules of linear algebra, the matrix and
array operations are same for addition and subtraction.
1
SIGNAL AND SYSTEMS LABORATORY
Matrix multiplication (A*B): is the linear algebraic product of the matrices A and B.
More precisely
( ) ∑ ( ) ( )
For nonscalar A and B, the number of columns of A must equal the number of rows of
B. A scalar can multiply a matrix of any size.
Slash or matrix right division(A/B): is roughly the same as: B*inv(A). more precisely:
B/A=(A'/B')'
Backslash or matrix right division(A/B): If A is a square matrix B\A is roughly the same
as: inv(B)*A. more precisely: B/A=(A'/B')'
^ Matrix power(X^p): is X to the power p, if p is a scalar. If p is an integer, the power is
computed by repeated squaring. If the integer is negative, X is inverted first.
General Mathematical Functions:
MATLAB offers many predefined mathematical functions for technical computing which
contains a large set of mathematical functions. There is a long list of mathematical
functions that are built into MATLAB. These functions are called built-ins. Many
standard mathematical functions, such as sin(x), cos(x), tan(x), ln(x) are evaluated by the
functions sin, cos, tan, exp, and log respectively in MATLAB. Table. 1 lists some
commonly used functions, where variables x and y can be numbers, vectors, or matrices.
Table 1: Elementary functions
cos (x) Cosine abs(x) Absolute value
sin(x) Sine sign(x) Signum function
tan(x) Tangent max(x) Maximum value
acos(x) Arc cosine min(x) Minimum value
asin(x): Arc sine ceil(x) Round towards +∞
atan(x) Arc tangent floor(x) Round towards -∞
exp(x) Exponential round(x) Round to nearest integer
sqrt(x) Square root rem(x) Remainder after division
log(x) Natural logarithm angle(x) Phase angle
log10(x) Common logarithm conj(x) Complex conjugate
2
SIGNAL AND SYSTEMS LABORATORY
3
SIGNAL AND SYSTEMS LABORATORY
4
SIGNAL AND SYSTEMS LABORATORY
where there are as many equations as unknowns. A is a given square matrix of order n, b
is a given column vector of n components, and x is an unknown column vector of n
components.
In linear algebra we learn that the solution to Ax=b can be written as x=A-1 b where A-1
is the inverse of A. For example, consider the following system of linear equations:
x+2y+3z=1
4x+5y+6z=1
7x+8y =1
Using matrix notation, a system of simultaneous linear equations is written as: Ax=B ,
where:
[ ] , [ ]
This equation can be solved for x using linear algebra. There are two ways to solve for
x using MATLAB:
1. The first way is to use the matrix inverse:
>> A=[ 1 2 3; 4 5 6; 7 8 0];
> >B=[ 1 ; 1 ; 1];
>> x=inv(A) *B
x=
-1
1
0
2. The second way is to use the backslash operation. The numerical algorithm behind
this operator is computationally efficient. This is numerically reliable way of solving
a system of linear equations by using a well-known process of Gaussian elimination:
>> A =[1 2 3; 4 5 6; 7 8 0];
>>B = [1; 1; 1];
>>x=A\B
x=
-1
1
0
5
SIGNAL AND SYSTEMS LABORATORY
Experiment:
1- What are the results of the following instructions:
>> a=[5 2 3 5 8];
>> b=[9 2 5 0 8];
>> a'
>>a-1
>>a.*b
>> a*b
>>a.^3
3-Find the matrix a - bc2 + 2d' when the matrices a, b, c and d are:
[ ] [ ]
[ ] [ ]
4-For the matrix x=[3+4i 1-i] , find the result of the following:
conj(x)
imag(x)
real(x)
abs(x)