0% found this document useful (0 votes)
16 views13 pages

Chapter 3

The document discusses various mathematical operations that can be performed on arrays in MATLAB. Some key points: 1) Addition and subtraction can be used to operate on arrays of the same size or add/subtract a scalar from each element of an array. 2) Matrix multiplication requires the number of columns in the first matrix to equal the number of rows in the second. 3) Left and right division are used to solve systems of linear equations by multiplying the matrices by their inverses. 4) Element-by-element operations use a period before the operator and can only be done on arrays of the same size. 5) Built-in functions like sum, sqrt, flipud, fl

Uploaded by

kawibep229
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)
16 views13 pages

Chapter 3

The document discusses various mathematical operations that can be performed on arrays in MATLAB. Some key points: 1) Addition and subtraction can be used to operate on arrays of the same size or add/subtract a scalar from each element of an array. 2) Matrix multiplication requires the number of columns in the first matrix to equal the number of rows in the second. 3) Left and right division are used to solve systems of linear equations by multiplying the matrices by their inverses. 4) Element-by-element operations use a period before the operator and can only be done on arrays of the same size. 5) Built-in functions like sum, sqrt, flipud, fl

Uploaded by

kawibep229
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/ 13

Mathematical

Operations with Arrays


ADDITION AND
SUBTRACTION

 The operations + (addition) and –


(subtraction) can be used to add
(subtract) arrays of identical size (the
same numbers of rows and columns) and
to add (subtract) a scalar to an array.
 When a scalar (number) is added to (or subtracted from) an array, the scalar is added
to (or subtracted from) all the elements of the array.
Examples are:
ARRAY MULTIPLICATION
 The multiplication operation * is executed by MATLAB according to the rules of linear
algebra.
 This means that if A and B are two matrices, the operation A*B can be carried out only if the
number of columns in matrix A is equal to the number of rows in matrix B.
A is a 4x3 matrix and B is a 3x2 matrix
 The result is a matrix that has the same number of rows as A and the same number of
columns as B Result of the matrix is a 4x2
ARRAY DIVISION
 The division operation is also associated with the rules of linear algebra.
 The division operation can be explained with the help of the identity matrix and the
inverse operation.
Identity matrix: The identity matrix is a square matrix in which the diagonal elements are 1s, and
the rest of the elements are 0s. (eye command)

If a matrix A is square, it can be multiplied by the identity matrix, I, from the left or from the right:
AI = IA = A

Determinants: A determinant is a function associated with square matrices.

det(A)

The determinant of a square matrix can be calculated with the det command
 Inverse of a matrix: The matrix B is the inverse of the matrix A if, when the
two matrices are multiplied, the product is the identity matrix.
 Both matrices must be square and the multiplication order can be BA or AB:
BA = AB = I
Left division, \ :
 Left division is used to solve the matrix equation AX = B. In this equation X and B are
column vectors. This equation can be solved by multiplying, on the left, both sides by the
inverse of A: X =A–1 B In MATLAB the last equation can be written by using the left
division character: X = A\B
 The left division method is recommended for solving a set of linear equations
Solving three linear equations (array division) Use matrix operations to solve the following
system of linear equations
4x – 2y + 6z = 8
2x + 8y + 2z = 4
6x + 10y + 3z = 0
Equations can be written in the matrix
form AX=B
Right division, / :
 The right division is used to solve the matrix equation XC = D In this equation X and D are
row vectors. This equation can be solved by multiplying, on the right, both sides by the
inverse of C: X .CC–1= D.C–1 which gives X=D.C-1 or X = D/C
Solving three linear equations (array division) Use matrix operations to solve the following system of
linear equations
4x – 2y + 6z = 8
Equations can be written in
2x + 8y + 2z = 4
the matrix form XC=D
6x + 10y + 3z = 0
ELEMENT-BY-ELEMENT OPERATIONS
 Element-by-element multiplication, division, or exponentiation of two vectors or matrices
is entered in MATLAB by typing a period in front of the arithmetic operator.
 Element-by-element operations can be done only with arrays of the same size.
BUILT-IN FUNCTIONS FOR ANALYZING ARRAYS
GENERATION OF RANDOM NUMBERS

Simulations of many physical processes and engineering applications frequently require


using a number (or a set of numbers) with a random value. MATLAB has three commands
rand, randn, and randi that can be used to assign
random numbers to variables.
GENERATION OF RANDOM NUMBERS

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. For example, a 3 x 4
matrix is created by:
 Given the array A = 2 4 1 5
6726
3592

1) Compute the sum over A in one step?

2) Compute the square-root of each element of A?

3) flipud(A)

4) fliplr(A)

5) Convert A into a 2-by-6 array?

You might also like