Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Matlab Presentation

Mathematical operations can be performed on arrays in MATLAB. Addition and subtraction can be done on arrays of identical size, where the sum or difference of corresponding elements is calculated. Matrix multiplication follows rules of linear algebra, where the number of columns of the first matrix must equal the number of rows of the second. Element-by-element operations use a period before operators like * or / to apply the operation to each element individually. Built-in functions in MATLAB can also operate on array elements when the input is an array. Random numbers can be generated using the rand and randn commands to produce uniformly distributed and normally distributed random values respectively.

Uploaded by

AsadMalik
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Matlab Presentation

Mathematical operations can be performed on arrays in MATLAB. Addition and subtraction can be done on arrays of identical size, where the sum or difference of corresponding elements is calculated. Matrix multiplication follows rules of linear algebra, where the number of columns of the first matrix must equal the number of rows of the second. Element-by-element operations use a period before operators like * or / to apply the operation to each element individually. Built-in functions in MATLAB can also operate on array elements when the input is an array. Random numbers can be generated using the rand and randn commands to produce uniformly distributed and normally distributed random values respectively.

Uploaded by

AsadMalik
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

MATLAB

An Introduction With
Application
Mathematical Operation With Arrays

Once a variable are created in Matlab they can be used in a wide


variety of mathematical operations. In chapter 1 the variables that
were used in mathematical operations were all defined as scalers. This
means that they were all 1 X 1arrays ( arrays with one row and one
column they have only one element ) and the mathematical operations
were done with single numbers. Arras, however, can be one
dimensional (array with one row and one column), two dimensional
( arrays with rows and columns ), and even of higher of dimensions.
In these cases the mathematical operations are more complex. Matlab,
as its named indicates is deigned to carry out advanced arrays
operations that many have applications in science and engineering.
ADDITION AND SUBTRACTION

The operations + (addition) and – (subtraction) can be used with the


arrays of identical size (the same no. of rows and column ). The sum,
or the difference of two arrays is obtained by adding, or subtracting,
their corresponding elements.
In general, if A and B are two arrays ( for example 2 X 3
matrices),
Array Multiplication
 The operator * is executed in MATLAB according to the rules of
linear algebra. This means that if the two matrix A and B , the
operator A*B can be carried out only if the no. of one column of
A is equal to the no. rows of B. The result has the same no. of
rows and column
 For example;
 If A is a 4X3 and B is a 3X2 matrix;

 Then, the matrix that is obtained by the operation A*B has
the dimension of 4X2 with the elements:

 Two vectors can multiply each other only if both have the
same no. of elements and one is a row vector and the other
id column vector. The multiplication of a row vector times a
column vector. The multiplication of a column vector times
a row vector, both with n elements gives an n x n matrix.
 Array Division
 The division operation is also associated with the rules of
linear algebra. This operation is more complex and only
brief explanation is given below. A fulfil explanation can
be found in books on linear algebra.
 The division operation can be explained with the help of
identity matrix and the inverse operation .
Identity Matrix
 The identity matrix is a square matrix in which the diagonal
elements are 1`s, and the non diagonal elements are zero`s.
 Identity matrix can be created in MATLAB by eye command .
 When the identity matrix another matrix, that matrix is
unchanged.
 This is equivalent to multiplying a scaler.
 Foe example;
Inverse of a Matrix
 The matrix B is the inverse of the matrix A if when the two matrix are multiplied the
product is the identity matrix . Both metrices must be square and the multiplications
order can be BA or BA
 BA = Ab = I
 The inverse matrix A us typically written as In MATLAB the inverse of a matrix can
be obtained either by raising A to the power of -1, or with the INV (A) function.
 For Example;
 >>A= [ 2 1 4; 4 1 8; 2 -1 3]
 A=
 2 1 4
 4 1 8
 2 -1 3
ELEMENT-BY-ELEMENT OPERATIONS
When the regular symbols for multiplication and division are used
with arrays(* and /) the mathematical operations follow the rules of
linear algebra. Elements-by-elements operations can only be done
with arrays of the same size.
Elements-by–elements multiplication, division and exponential of

two matrices is entered in MATLAB by typing a period in front of


the arithmetic operator.
Symbols Description

* Multiplication
^ Exponential
./ Right division
.\ Left division
Element-by -elements
Element-by-element calculations are very useful for calculating the
value of a function at many times of its argument. This is done by
first defining a vector that contain value of the independent
variable, and then using this vector in elements-by-elements
computations to create a vector.
Create a vector z with eight elements

 Vector z is used in element-by-element calculations of the


element of vector y.
Using Arrays In Matlab Built-In Math Function
 The built-in function in MATLAB are written such that when the
argument(input) is an array , the operation that is defined by the
function is executed on each element of the array. For Example, if
a vector with seven elements is subsituted in the function (cosx) .
Built-In Functions For Analyzing Arrays
 Matlab has many built-in functions for analyzing arrays, some of these
functions are.
Generation of Random Numbers
 Simulations of many physical processes and engineering
applications frequently requires using a number (or a set of
numbers) that has a random value.
 MATLAB has two commands “rand” and “randn” used to
assign tandom numbers to variables.
The “randn” Command
 The rand command generates
uniformly distributed numbers
with values between 0 and 1.
 The command can be used to
assign these numbers to a
scalar, vector or matrix as shown
in fig.
Cont.
 Sometimes it is need to have random numbers distrubeted in
interval other than (0,1) or nos. that are only integers.
 To do so, Random nis, distributed in range (a,b) can be obtained
by multiplying rand by (b-a) and adding to product a:
(b-a)*rand+a
Cont.
 Random numbers that are all integers can be generated by using
one of the round function.
 Example: A 2-by-15 matrix with random integers with values
that range from 1 to 100 can be created by:
The “randn” Command:
 The “randn” command generates normally distributed numbers
with mean 0 and standard deviation of 1.
 The command can be used to generate a single number, a vector
or a matrix in the same way as the rand command.
 Example: A 3-by-4 matrix is obtained by:
Cont.
 The mean and standard deviation of the numbers can be
changed by mathematical operations to have any values.
 This is done by multiplying the number generated by the
“randn” function by desired stand deviation and adding the
desired mean.
 Example: A vector of 10 numbers (integers) with a mean of 50
and standard deviation of 5 is generated by:
Example 1:
Example 2
Example 3
Example 4

You might also like