Matrix Arithmetic for Use in the Biological Sciences I S

advertisement
Matrix Arithmetic for Use in the
Biological Sciences
Animal Science 500
Lecture No. 18 & 19
November 9, 2010
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Arithmetic and Algebra
 References
1.
2.
Matrix Algebra for the Biological Sciences – S. R.
Searle. 1966. John Wiley & Sons, New York, N.Y.
(This book is older and out of print. For those
interested in a copy, there are used copies available
from resellers from various internet sites.)
Linear Algebra for Dummies – M. J. Sterling. 2009.
John Wiley & Sons, New York, N.Y. (This book is
relatively new and can be purchased new or used from
numerous resellers found on the internet.)
ISBN number: 978-0-470-43090-3
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Arithmetic and Algebra – Why?

“The simulation of physiological systems requires a
mathematical base and in most cases a large
computer.” (W. J. Dixon, 1966)

Attempting to turn what we observe or what is
occurring physiologically or what is commonly
referred to as a “phenotype” into a mathematical
model.



Explain experimental results
Explain various environmental factor
Today biological sciences are very much quantitative
whereas years ago it was more descriptive
IOWA STATE UNIVERSITY
Department of Animal Science
What is Matrix Algebra

Is in a way a shorthand notation for the language of
mathematics

Provides the ability to deal with many numbers and / or
equations simultaneously

A matrix is simply a rectangular array of numbers set
out in rows and columns.


Is frequently used in organizing the presentation of numerical data
that will be handled in some way mathematically.
Common examples



Animal breeding – solving equations to estimate variance components
and breeding values
Solving simultaneous equations – nutritional nutrient balancing
Data analysis – any procedure that involves linear equations involves
the use of matricies.
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix and Regression Analysis

An example that illustrates the wide spread use of
matrix and matrix algebra
y = b0 + b1 x1 + b2 x2 + … + bk xk
Where there are numerous observations on the variable y
and on each of the k variables x1, x2, …. xk.
b’s values can be obtained when X’Xb = X’y as b =
(X’X)-1 X’y is solved. Where X and y are both matrices
representing all of the observations in the x and y
variables respectively and b represent the series of b’s
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Algebra
 Is
a mathematical procedure for many
problems of any size (small and large) can be
described.

Hence, size does not affect the understanding of the
procedures just the amount of calculating or computer
time required to solve the equations.
IOWA STATE UNIVERSITY
Department of Animal Science
General description of a Matrix
A
matrix is an aid in organizing data.
Example: From Searle, 1966
Table 1. Percentage of sterile cultures among different populations
in successive generations.
Population
Generation
1
2
3
1
18
17
11
2
19
13
6
3
6
14
9
4
9
11
4
IOWA STATE UNIVERSITY
Department of Animal Science
General description of a Matrix
 Extract
the numbers within the results and
written into a matrix
•
•
•
18
17
11
19
13
6
6
14
9
9
11
4
This array of number is called a matrix.
Position of the entry within the array determines or
defines its meaning.
For example the third entry in the second row
represents the percentage of sterile cultures observed
in the second generation in population 3
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Algebra Notation
 Algebra
is arithmetic with letters of the
alphabet representing numbers. The first two
rows of the previous matrix would be:
18 17 11
19 13 6
Could be written as
A=
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Algebra Notation
 Since
using letters would limit us to 26 entries
A=
a1 a2 a3
b1 b2 b3
The individual entries a1, a2, a3, … b3 are called
elements of the array or matrix
The integers 1, 2, & 3 are called subscripts and
in this they represent the column where each
element is located.
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Algebra Notation

This notation can be carried further:
A=
a11 a12 a13
b21 b22 b23
Again the individual entries a11, a12, a13, … b23 are called
elements of the array or matrix
This time two integers 11, 12, 13, … 23 are called
subscripts and in this they represent the row and
column where each element is located.
The first number represents the row and the second
represents the column
IOWA STATE UNIVERSITY
Department of Animal Science
Summation Notation

Suppose we want to add five numbers representing a1,
a2, a3, a4, a5.
Easily this can be written
a1 + a2 + a3 + a4 + a5.
It can also be expressed in words as ‘the sum of all values
of ai for i = 1, 2, …., 5.
The phrase “the sum of all values of” is typically written by
the capital form of the Greek letter sigma ∑
IOWA STATE UNIVERSITY
Department of Animal Science
Summation Notation

Accordingly the sum of the a’s is written

∑ ai for I = 1, 2, …..,5.

A further abbreviation is
i 5
a
i 1
1
= a1 + a2 + a3 + a4 + a5.
Many variations to this
i 3
a
i 1
1
= a1 + a2 + a3.
IOWA STATE UNIVERSITY
Department of Animal Science
Summation Notation

and still more variations
3
x
i
= x1 + x 2 + x3
i
= x1 + x2 + x3………xn-2 + xn-1 + xn
i 1
and
n
x
i 1
IOWA STATE UNIVERSITY
Department of Animal Science
Summation Notation

and still more variations

4
1
yi = y1 + y2 + y3 + y4
7
y =y
and
7
y
i 3
i4
i
i 3
i
3
+ y 4 + y 5 + y 6 + y7
= y3 + y 5 + y6 + y 7
IOWA STATE UNIVERSITY
Department of Animal Science
Summation Notation

and still more variations
3
a
1j=
j 1
a11 + a12 + a13
and
2
a
i 1
ij
= a1j + a2j
IOWA STATE UNIVERSITY
Department of Animal Science
Definition of a Matrix
A
matrix is a rectangular (or square) array of
numbers arranged in rows and columns.




The rows are equal length
The columns are equal length
Let aij represent denote the element in the ith row and
the jth column of matrix A.
A has r rows and c columns and can be written as
follows:
IOWA STATE UNIVERSITY
Department of Animal Science
Definition of a Matrix
A=
a11
a12
a13
…
a1j
…
a1c
a21
a22
a23
…
a2j
…
a2c
.
.
.
.
.
.
.
.
.
ai1
ai2
ai3
…
aij
…
.
.
.
.
.
.
.
.
.
ar1
ar2
ar3
IOWA STATE UNIVERSITY
Department of Animal Science
…
arj
…
aic
arc
Definition of a Matrix
A
= { Aij } for I = 1, 2, …, r, and j = 1, 2, …, c,
 The
curly brackets indicating that aij is a typical
element the limits i and j being r and c
respectively
element aij is sometimes called the ijth
element.
 The
IOWA STATE UNIVERSITY
Department of Animal Science
Definition of a Matrix
 Thus
a23 is the element in the second row and
the third column.
 The
size of the matrix is called its order (or
sometimes its dimensions)
 The
matrix called A with r rows and c columns
has an order r x c (read “r” by “c”)
 When
the number of rows equals the number
of columns, A is square and is called a “square
matrix” and is described have the order r
IOWA STATE UNIVERSITY
Department of Animal Science
Definition of a Matrix
the square matrix, elements a11, a22, a33…arr
are referred to as the diagonal elements.
 In
 The
sum of the diagonal elements is called the
trace of the matrix.
 In
every case the first term in the first row of a
matrix, a11 is called the leading term.
IOWA STATE UNIVERSITY
Department of Animal Science
Definition of a Matrix
 Again
a simple example of a matrix, one of
order 2 x 3 is as follows:
A 2x3 =
4
0
-3
-7
2.73
1
 When
all of the non-diagonal elements are zero
the matrix is called a diagonal matrix.
A=
IOWA STATE UNIVERSITY
Department of Animal Science
3
0
0
0
-17
0
0
0
99
Definition of a Matrix
 If
all elements above or below the diagonal are
zero, the matrix is called a triangular matrix.
B=
C=
1
5
13
0
-2
9
0
0
7
Upper triangular matrix
2
0
0
8
3
0
1
-1
2
IOWA STATE UNIVERSITY
Department of Animal Science
Lower triangular matrix
Matrix Vectors and Scalars
A
matrix consisting of a single column is
called a column vector.
x=
3
-2
0
1
•A vector is an ordered collection of numbers.
•Vectors containing two or three numbers are represented by rays, or a line segment
with an arrow on the end. A ray loses its effect or meaning when you deal
with larger vectors and numbers.
•Technically a vector is a column matrix so also called a column vector
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Vectors and Scalars
A
matrix consisting of a single row is called a
row vector.
y=
4
6 -7
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Vectors and Scalers

A single number such as 2, 6, 4, -4, or 0.2 is called a
scalar.

A scalar will generally be multiplied by all elements of
a larger matrix.

Matrices are usually denoted by upper case letters and
their elements by lower case letters with appropriate
subscripts.

Vectors are denoted by lower case letters, usually from
the end of the alphabet using the prime superscript to
distingush a row vector from a column vector.


X = a column vector
X’ = a row vector
IOWA STATE UNIVERSITY
Department of Animal Science
Matrix Vectors and Scalers
λ
is frequently used for denoting a scalar
 You
might see an array surrounded by
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Addition
A=
98
24
42
39
15
22
22
15
17
B=
55
19
44
43
53
38
11
40
20
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Addition
A+B=
A+B=
98 + 55
24 + 19
42 + 44
39 + 43
15 + 53
22 + 38
22 + 11
15 + 40
17 + 20
153
43
86
82
68
60
33
55
37
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Addition

Two matrices can be added together only if the two
matrices have the same order


Both matrices must have the same number of rows and
columns
If the two matrices can be added together they are said to be
conformable for addition
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Subtraction

The difference between two matrices is the difference
element by element
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Addition
A=
910
1275
1210
1304
860
967
1048
1048
If matrix b is ending wt. and matrix b is beginning wt. you would
Subract b from a or B- A
B=
2050
1340
1344
1384
1380
1058
1011
1189
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Addition
A=
1140
65
134
80
520
91
344
141
As was the case with adding matrices, only matrices with the same
order can be Subtracted. So it can be said that the two matrices are
conformable for subtraction. Hence, a matrix that is conformable for
addition is also conformable for subtraction and vise versa.
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Multiplying

by a scalar λ .
λA = {λaij}
λ = 3 and A =
B-A=
or A- (-B) =
1 -7
3 5
3 -21
9 15
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Equality
and the Null Matrix .
 Two
matrices are equal when they are identical
element by element
A
= B when {aij} = {bij} meaning that aij = bij
A
matrix that is made up entirely of zeros is
called a null matrix or a zero matrix

Not unique because for a matrix of any order there is a
corresponding null matrix of the same order.
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Multiplying
matrices.
 Multiplying
two vectors



Example
Suppose there number of lambs having 0, 1, and 2
lambs respectively are written as a row vector call a’
a‘ = [58 26 8]
The number of lambs per ewe are written as a column
vector call x
0
x=
IOWA STATE UNIVERSITY
Department of Animal Science
1
2
Basic Matrix Operations
 Multiplying
matrices.
 Multiplying
two vectors
Example
 Suppose there number of lambs having 0, 1, and 2
lambs respectively are written as a row vector call a’
 The number of lambs per ewe are written as a column
vector call x
The product of a’ x = [ 58 26 8 ]
0

1
2
a’x = 58(0) + 26(1) + 8(2) = 42
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Multiplying
matrices.
 Multiplying
two vectors




Example
Suppose there number of lambs having 0, 1, and 2
lambs respectively are written as a row vector call a’
The number of lambs per ewe are written as a column
vector call x
This example shows you the general procedure for
obtaining a’ x;

Multiply each element of the row vector a’ by the corresponding
element of the column vector x and add the products
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations

Multiplying matrices.

Multiplying two vectors

Thus the general for exists

a’ = [a1 + a2 + … + an]

X=
x1
x2
.
.
.
xn

The product of a’x = a1x1 + a2x2 + … anxn =
IOWA STATE UNIVERSITY
Department of Animal Science
n
a x
i 1
i i
Basic Matrix Operations
 Multiplying
matrices.
 Multiplying
matrix and a vector
A=
58
26
8
52
58
12
1
3
9
42
x is a column vector of
0
82
1
21
2
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Multiplying
matrices.
 Multiplying
matrix and a vector
 You
multiply each column by the
corresponding single row element from x.
A=
58 x 0
26 x 1
8x2
52 x 0
58 x 1
12 x 2
1x0
3x1
9x2
0
26 16
0
58 24
0
3 18
IOWA STATE UNIVERSITY
Department of Animal Science
=
=
42
82
21
Basic Matrix Operations
 Multiplying
matrices.
 Multiplying
matrix and a vector
 Notation
A=
form
a11
a12
a13
a12
a22
a23
a13
a23
a33
and x = x1
x2
x3
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations
 Multiplying
matrices.
 Multiplying
matrix and a vector
 Notation
form
3
a
Ax=
a11x1
a12x2
a13x3
a12x1
a22x2
a23x3
a13x1
a23x2
a33x3
k 1
1k
xk
3
= a
k 1
2k
xk
3
a
k 1
3k
xk
The product of Ax of a matrix A and a column vector x is a column vector whose ith term
Is the sum of products of the elements of the ith row of A each multiplied by the corresponding
element of x. From this definition and from the example it is easily seen that Ax is defined only
when the number of rows in A are equal to the number of elements in the rows of A (i.e. number of
columns) is the same as the number of elements in the column vector x.
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations

Multiplying matrices.

Multiplying matrix and a vector

The product of Ax of a matrix A and a column vector x is a column
vector whose ith term

Is the sum of products of the elements of the ith row of A each
multiplied by the corresponding element of x. From this definition
and from the example it is easily seen that Ax is defined only when
the number of rows in A are equal to the number of elements in the
rows of A (i.e. number of columns) is the same as the number of
elements in the column vector x.

Therefore when A has r rows and c columns and x is of the order c,
Ax is a column vector of order r
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations

Multiplying matrices.

Multiplying 2 matrices
A
B
=
=
1
0
2
3
1
1
1
2
1
-1
3
2
1
2
0
1
0
-1
IOWA STATE UNIVERSITY
Department of Animal Science
Basic Matrix Operations

Multiplying matrices.

Multiplying 2 matrices
A
=
A*B =
1
2
1
0
1
2
1
0
-1
3
2
1
0
2
3
1
1
-1
B=
(1*1) + (1*2)
(0*0) + (0*1)
(2*0) + (2*-1)
(3*1) + (3*2)
(1*0) + (1*1)
(1*0) + (1*-1)
(1*1) + (1*2)
(2*0) + (2*1)
(1*0) + (1*-1)
(-1*1) + (-1*2)
(3*0) + (3*1)
(2*0) + (2*-1)
IOWA STATE UNIVERSITY
Department of Animal Science
=
1
0
3
6
1
3
-1
-1
Basic Matrix Operations
 Multiplying
matrices.
 Multiplying
2 matrices
 In
order to multiply matrix A by matrix B, the
number of rows in matrix A must equal the
number of columns in B.
IOWA STATE UNIVERSITY
Department of Animal Science
Transposing a Matrix
 Transposing
can best be described by
showing an example
A
A
=
18
17
11
19
13
6
6
14
9
9
11
4
transpose
18
18
17
13
11
6
IOWA STATE UNIVERSITY
Department of Animal Science
6
9
14 11
9
4
Determinants
 The
determinant is a real number, it is not a
matrix.
 The
determinant can be a negative number.
 It
is not associated with absolute value at all
except that they both use vertical lines.
 The
determinant only exists for square matrices
(2×2, 3×3, ... n×n). The determinant of a 1×1
matrix is that single value in the determinant.
 The
inverse of a matrix will exist only if the
determinant is not zero.
IOWA STATE UNIVERSITY
Department of Animal Science
Determinants
 The
determinant of a 2×2 matrix is found much
like a pivot operation. It is the product of the
elements on the main diagonal minus the
product of the elements off the main diagonal.
 A=
a
b
3 1
c
d
5 2
 Determinant
= ad – bc = ad = 6 bc = 5
 Determinant
=6–5=1
IOWA STATE UNIVERSITY
Department of Animal Science
Rank of a Matrix

You can think of an r x c matrix as a set of r row
vectors, each having c elements; or you can think of it
as a set of c column vectors, each having r elements.

The rank of a matrix is defined as (a) the maximum
number of linear independent column vectors in the
matrix or (b) the maximum number of linearly
independent row vectors in the matrix. Both definitions
are equivalent.

For an r x c matrix,

If r is less than c, then the maximum rank of the matrix
is r.
IOWA STATE UNIVERSITY
Department of Animal Science
Rank of a Matrix

If r is greater than c, then the maximum rank of the
matrix is c.

The rank of a matrix would be zero only if the matrix
had no elements. If a matrix had even one element, its
minimum rank would be one.
IOWA STATE UNIVERSITY
Department of Animal Science
Rank of a Matrix

A set of vectors is linearly independent if no vector in the set is (a)
a scalar multiple of another vector in the set or (b) a linear
combination of other vectors in the set; conversely, a set of
vectors is linearly dependent if any vector in the set is (a) a scalar
multiple of another vector in the set or (b) a linear combination of
other vectors in the set.

Consider the row vectors below.
a= 123 d= 246
b= 456 e= 010
c= 579 f = 000
IOWA STATE UNIVERSITY
Department of Animal Science
Rank of a Matrix

Vectors a and b are linearly independent, because neither vector
is a scalar multiple of the other.

Vectors a and d are linearly dependent, because d is a scalar
multiple of a; i.e., b = 2a.

Vector c is a linear combination of vectors a and b, because c = a
+ b. Therefore, the set of vectors a, b, and c is linearly dependent.

Vectors d, e, and f are linearly independent, since no vector in the
set can be derived as a scalar multiple or a linear combination of
any other vectors in the set.
IOWA STATE UNIVERSITY
Department of Animal Science
Rank of a matrix

This method assumes familiarity with echelon matrices and
echelon transformations.

The maximum number of linearly independent vectors in a matrix
is equal to the number of non-zero rows in its row echelon matrix.

Therefore, to find the rank of a matrix, we simply transform the
matrix to its row echelon form and count the number of non-zero
rows.

Consider matrix A and its row echelon matrix, Aref.

012121278

Because the row echelon form Aref has two non-zero rows, we
know that matrix A has two independent row vectors; and we
know that the rank of matrix A is 2.
⇒
1 2 1 0 1 2 0 0 0 A Aref
You can verify that this is correct. Row 1 and Row 2 of matrix A
are linearly independent. However, Row 3 is a linear combination
of Rows
1 andU
2. NIVERSITY
Specifically, Row 3 = 3*( Row 1 ) + 2*( Row 2).
IOWA
STATE
Department
of Animal
Science
Therefore,
matrix
A has only two independent row vectors.

What is row echelon form?

Row Echelon Form

A matrix is in row echelon form when it satisfies the following
conditions.

The first non-zero element in each row, called the leading entry, is 1.

Each leading entry is in a column to the right of the leading entry in
the previous row.

Rows with all zero elements, if any, are below rows having a non-zero
element.

Each of the matrices shown below are examples of matrices in row
echelon form.
IOWA STATE UNIVERSITY
Department of Animal Science
What is row echelon form?
1234
0013
0001
1234
0013
0001
0000
example A
12
01
00
example B
IOWA STATE UNIVERSITY
Department of Animal Science
example C
The Inverse of a Matrix
a square matrix A, the inverse is written A-1.
When A is multiplied by A-1 the result is the
identity matrix I.
 For
 Non-square
matrices do not have inverses.
 Note:
Not all square matrices have inverses. A
square matrix which has an inverse is called
invertible or nonsingular, and a square matrix
without an inverse is called noninvertible or
singular.
IOWA STATE UNIVERSITY
Department of Animal Science
Download