chapter 3 mathematical operations with arrays

41
Chapter 3 Mathematical Operations with Arrays Computer Programming ECIV 2303 Civil Engineering Department Prof. Mohammed Arafa

Upload: others

Post on 15-Jun-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 3 Mathematical Operations with Arrays

Chapter 3Mathematical Operations with Arrays

Computer ProgrammingECIV 2303

Civil Engineering DepartmentProf. Mohammed Arafa

Page 2: Chapter 3 Mathematical Operations with Arrays

Addition And Subtraction

Page 3: Chapter 3 Mathematical Operations with Arrays

Addition And Subtraction

Page 4: Chapter 3 Mathematical Operations with Arrays

Addition And Subtraction

Page 5: Chapter 3 Mathematical Operations with Arrays

Array Multiplication

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

Page 6: Chapter 3 Mathematical Operations with Arrays

Array Multiplication

Page 7: Chapter 3 Mathematical Operations with Arrays

Array Multiplication

Page 8: Chapter 3 Mathematical Operations with Arrays

Array Multiplication

Page 9: Chapter 3 Mathematical Operations with Arrays

Array Multiplication

Page 10: Chapter 3 Mathematical Operations with Arrays

Array Multiplication

Page 11: Chapter 3 Mathematical Operations with Arrays

Array Multiplication

Page 12: Chapter 3 Mathematical Operations with Arrays

Array Multiplication

Page 13: Chapter 3 Mathematical Operations with Arrays

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

Page 14: Chapter 3 Mathematical Operations with Arrays

Array Division

Page 15: Chapter 3 Mathematical Operations with Arrays

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

Page 16: Chapter 3 Mathematical Operations with Arrays

Array Division

Page 17: Chapter 3 Mathematical Operations with Arrays

Array Division

Page 18: Chapter 3 Mathematical Operations with Arrays

Determinants:

Array Division

Page 19: Chapter 3 Mathematical Operations with Arrays

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

Page 20: Chapter 3 Mathematical Operations with Arrays

Right division, I :

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

Array Division

Page 21: Chapter 3 Mathematical Operations with Arrays

Sample Problem 3-1:

Solving three linear equations (array division)

Page 22: Chapter 3 Mathematical Operations with Arrays

Sample Problem 3-1:

Solving three linear equations (array division)

Page 23: Chapter 3 Mathematical Operations with Arrays

Sample Problem 3-1:

Solving three linear equations (array division)

Page 24: Chapter 3 Mathematical Operations with Arrays

Element-by-Element Operations

Page 25: Chapter 3 Mathematical Operations with Arrays

Element-by-Element Operations

Page 26: Chapter 3 Mathematical Operations with Arrays

Element-by-Element Operations

Page 27: Chapter 3 Mathematical Operations with Arrays

Element-by-Element Operations

Page 28: Chapter 3 Mathematical Operations with Arrays

Element-by-Element Operations

Page 29: Chapter 3 Mathematical Operations with Arrays

Element-by-Element Operations

Page 30: Chapter 3 Mathematical Operations with Arrays

Element-by-Element Operations

Page 31: Chapter 3 Mathematical Operations with Arrays

Element-by-Element Operations

Page 32: Chapter 3 Mathematical Operations with Arrays

Using Arrays in Matlab Built-in Math Functions

Page 33: Chapter 3 Mathematical Operations with Arrays

BUILT-IN FUNCTIONS FOR ANALYZING ARRAYS

Using Arrays in Matlab Built-in Math Functions

Page 34: Chapter 3 Mathematical Operations with Arrays

Built-in Functions for Analyzing Arrays

Page 35: Chapter 3 Mathematical Operations with Arrays

Built-in Functions for Analyzing Arrays

Page 36: Chapter 3 Mathematical Operations with Arrays

Built-in Functions for Analyzing Arrays

Page 37: Chapter 3 Mathematical Operations with 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 =

+ + =

Page 38: Chapter 3 Mathematical Operations with Arrays

Generation Of Random Numbers

The rand Command

Page 39: Chapter 3 Mathematical Operations with Arrays

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:

Page 40: Chapter 3 Mathematical Operations with Arrays

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.

Page 41: Chapter 3 Mathematical Operations with Arrays

Sample Problem 3-2: