Professional Documents
Culture Documents
Lab 4
Lab 4
LAB 4
Mathematical Array Operations
Student Name
Student ID
Student Score
1
The operations + (addition) and – (subtraction) can be used to add (subtract)
arrays of identical size (the same number of rows and columns), and to add
(subtract) a scalar to an array.
And
2
When a scalar and an array are involved in the addition (subtraction) operation,
the scalar is added to (or subtracted from) all the elements in the matrix. Examples
are:
ARRAY MULTIPLICATION
3
The multiplication of matrices is not commutative. This means that if A
and B are both n x n , then A*B ≠ B*A.
The multiplication of a column vector times a row vector, both with n
elements gives an n x n matrix.
4
5
When an array is multiplied by a number (actually a number is a array), each
element in the array is multiplied by the number.
For example:
6
Array Division
The division operation is also associated with the rules of linear algebra. This
operation is more complex and only a brief explanation is given below. A full
explanation can be found in books on 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 1’s, and
the rest of the elements are 0’s. When the identity matrix multiplies another
matrix (or vector), that matrix (or vector) is unchanged.
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.
7
The inverse of a matrix A is 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, multiplying the matrices above with MATLAB
is shown below:
Determinants
8
Array division
MATLAB has two types of array division, which are the right division and the
left division.
Left division \ :
The left division is used to solve the matrix equation AX=B. In this equation X
and B are column vectors.
In MATLAB the last equation can be written by using the left division
character:
X = A\B
Right Division / :
The right division is used to solve the matrix equation XC=D . In this equation
X and D are row vectors.
In MATLAB the last equation can be written by using the right division
character:
X = D/C
9
Practice
10
ELEMENT-BY-ELEMENT OPERATIONS
Element-by-element multiplication, division, and exponentiation of two vectors
or matrices is entered in MATLAB by typing a period in front of the arithmetic
operator.
11
BUILT-IN FUNCTIONS FOR ANALYZING ARRAYS
MATLAB has many built-in functions for analyzing arrays. Table 3-1 lists some of these functions.
12
Homework
Q1- find the solution of the following:
x1+3x2=-2
2x1+4x2=1
2x+y+z=2
−x+y−z=3
x+2y+3z=−10
Q3
13