0% found this document useful (0 votes)
3 views6 pages

Experiment

The document outlines the use of MATLAB for mathematical operations, detailing three types of arithmetic operations: column oriented, array arithmetic, and matrix operations. It explains various functions and predefined constants available in MATLAB, as well as methods for solving systems of linear equations. Additionally, it includes a series of experiments to apply these concepts using MATLAB commands.

Uploaded by

rasha waleed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Experiment

The document outlines the use of MATLAB for mathematical operations, detailing three types of arithmetic operations: column oriented, array arithmetic, and matrix operations. It explains various functions and predefined constants available in MATLAB, as well as methods for solving systems of linear equations. Additionally, it includes a series of experiments to apply these concepts using MATLAB commands.

Uploaded by

rasha waleed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SIGNAL AND SYSTEMS LABORATORY

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

In addition to elementary functions, MATLAB includes a number of predefined


constant values. A list of most common values is given in table 2.
Table 2.2: Predefined constant values
pi The π number, π=3.14159…
i, j The imaginary unit i, √
inf The infinity, ∞
NaN not a number
For example:
>> a=5; x=2; y=8;
>>y=exp(-a) * sin(x)+10* sqrt(y)
y=
28.2904
>> log(142)
ans=
4.9558
>> log10(142)
ans=
2.1523

Matrix operations vs. array operations


Here are two vectors, and the results of various matrix and array operations on them.

3
SIGNAL AND SYSTEMS LABORATORY

Solving linear equations:


One of the problems encountered most frequently in scientific computation is the
solution of systems of simultaneous linear equations. With matrix notation, a system of
simultaneous linear equations is written: Ax = b

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

2-What is the result of each the following command?


>>B=magic(4)
>>A=B(: , [1 3 2 4])
Delete the 3rd row

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)

5- Try the three functions: round, floor and ceil on z, where:


z=[-3.6 , -2.5 , -1.4 , -1 , 0 , 1.4 , 2.5 , 3.6]

6- Given the following array:


A= [1 2 5 3 ; 1 5 3 0 ; 0 1 5 2 ; 0 6 4 7]
What is the command used to obtain the following array:
1 2 5 3 6 7 10 8
1 5 3 0 6 10 8 5
0 1 5 2 5 6 10 7
0 6 4 7 5 11 9 12
44 84 83 83 -2 -1 2 0
93 52 1 50 -2 2 0 -3
46 20 68 70 -3 -2 2 -1
41 67 37 42 -3 3 1 4

You might also like