Chapter 3 Mathematical Operations with Arrays

Preview:

Citation preview

Chapter 3Mathematical Operations with Arrays

Computer ProgrammingECIV 2303

Civil Engineering DepartmentProf. Mohammed Arafa

Addition And Subtraction

Addition And Subtraction

Addition And Subtraction

Array Multiplication

The matrix that is obtained with the operation A*B has dimensions with the elements:

Array Multiplication

Array Multiplication

Array Multiplication

Array Multiplication

Array Multiplication

Array Multiplication

Array Multiplication

Array Division

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. ✓ an identity matrix can be created in MATLAB with the eye command. ✓ When the identity matrix multiplies another matrix (or vector), that

matrix (or vector) is unchanged

Array Division

Inverse of a matrix

The matrix B is the inverse of the matrix A if, when thetwo

matrices are multiplied, the product is the identity matrix. Both

matrices must be square.

Array Division

Array Division

Array Division

Determinants:

Array Division

MATLAB has two types of array division, right division and left division

Left division, \ :

Left division is used to solve the matrix equation AX = B.

The solution X is obtained numerically using a method that is based on

Gauss elimination

Array Division

Right division, I :

The right division is used to solve the matrix equation XC = D.

Array Division

Sample Problem 3-1:

Solving three linear equations (array division)

Sample Problem 3-1:

Solving three linear equations (array division)

Sample Problem 3-1:

Solving three linear equations (array division)

Element-by-Element Operations

Element-by-Element Operations

Element-by-Element Operations

Element-by-Element Operations

Element-by-Element Operations

Element-by-Element Operations

Element-by-Element Operations

Element-by-Element Operations

Using Arrays in Matlab Built-in Math Functions

BUILT-IN FUNCTIONS FOR ANALYZING ARRAYS

Using Arrays in Matlab Built-in Math Functions

Built-in Functions for Analyzing Arrays

Built-in Functions for Analyzing Arrays

Built-in Functions for Analyzing Arrays

Built-in Functions for Analyzing Arrays

1 3 2

2 4 1

a b

i j k

1 3 2 4 3 5 26

a b =

+ + =

Generation Of Random Numbers

The rand Command

Generation Of Random Numbers

The randi Command

The range of the random integers can be set

to be between any two integers by typing

[imin imax] instead of imax. For example, a

matrix with random integers between 50 and

90 is created by:

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.

Sample Problem 3-2:

Recommended