You are on page 1of 9

Lecture 4

Chapter 3 Mathematical Operations with Arrays


• Mathematical Operations
with arrays
Chapter 3 Addition and Subtraction
• Mathematical Operations
with arrays
• Addition and Subtraction

Addition and subtraction is performed by corresponding elements.


Scaler is added and subtracted in and from all elements respectively.
Chapter 3 Array Multiplication
• Mathematical Operations
with arrays
• Addition and Subtraction
• Array Multiplication

We use * operation for multiplication.


Chapter 3 Array Division
• Mathematical Operations
with arrays
• Addition and Subtraction
• Array Multiplication
• Array Division Inverse of a matrix A^-1 or inv(A)
Determinant of a matrix det(A) or |A|
Left Division (\) X=B as X=A\B
Right Division (/) X=B as X=B/A
Chapter 3 Element by Element Operations
• Mathematical Operations
with arrays
• Addition and Subtraction
• Array Multiplication
• Array Division
• Element by Element
Operations
Chapter 3 Built-in Functions
• Mathematical Operations
with arrays For Vector (All Elements) or Matrix (Row Vector for each Column)
• Addition and Subtraction mean(A) Returns mean value
• Array Multiplication max(A) Returns largest element
• Array Division [d,n]=max(A) Returns d largest element and n position of
• Element by Element that element
Operations min(A) same as max(A) but with smallest element
• Built-in Functions [d,n]=min(A) same as [d,n]=max(A) but smallest element
sum(A) Returns the sum of elements
sort(A) Returns the ascending order elements
sort(A,'descend’) Returns as sort(A) but in descending order
median(A) Returns the median value
std(A) Returns the standard deviation
dot(a,b) Returns the dot product of vectors
cross(a,b) Returns the cross product of vectors with
length must be 3
Chapter 3 Generation of Random Numbers
• Mathematical Operations
with arrays
• rand (Value between 0 to 1)
• Addition and Subtraction
• rand(1,n) (row vector with length n)
• Array Multiplication
• rand(n) (squire matrix with order n)
• Array Division
• rand(m,n) (matrix with order mxn)
• Element by Element
• randperm(n) (row vector with length n)
Operations
• (b-a)*rand+a (random number between a and b)
• Built-in Functions
• randn (random number with mean 0 and S.D 1)
• Random Numbers
• S.D*randn(m,n)+mean for useful prepose
• randi (random integer)
• randi(imax) (random number between 1 and imax)
• randi(imax,n) (squire matrix of order n)
• randi(imax,m,n) (matrix of order mxn)
• randi([imin imax],m,n) (matrix of order mxn with interval)
Chapter 3 Practice and Problems
• Mathematical Operations
with arrays
• Addition and Subtraction
• Array Multiplication
• Array Division
• Element by Element
Operations
• Built-in Functions
• Random Numbers Solve the practice and problems
• Practice and Problems

You might also like