Docsity

Lab Notes: Quantitative Methods in Hydrology - Matrices, Study notes of Geology

Toggle sidebar
bg1
New Mexico Tech Hyd 510
Hydrology Program Quantitative Methods in Hydrology
Lab Notes. 2 Matrices
Matrices
matrix - a rectangular array of number:
A matrix is usually identified by a boldface capital letter. The size of a matrix is m x n (read: “m by n”) where m is
the number of rows in the matrix and n is the number of columns. An entry in a matrix is denoted by a lowercase
letter with two subscripts indicating the row and column of the entry, e.g. aij is the entry in the ith row and jth column
of matrix A. Matrices are used to solve systems of linear equations.
General matrix:
=
mnmm
n
n
aaa
aaa
aaa
21
22221
11211
A
Example: A is a 2x3 matrix.
−
=
π
27
2.351
A a11=1; a12=5; a13=3.2; a21=-7; a22=
2
; a23=π
Special Matrices
Square matrix - a matrix that has the same number of rows and columns, i.e. n x n .
−=
−
=
543
221
014
54
12 BA
Diagonal matrix - a square matrix whose only non-zero entries are on the diagonal,
i.e. aij = 0 for i
≠
j.
−
=
7000
0100
0020
0003
A
Tri-diagonal matrix - a square matrix whose only non-zero entries are on the diagonal, and just above and just below
the diagonal.
pf3
pf4
pf5

Partial preview of the text

Download Lab Notes: Quantitative Methods in Hydrology - Matrices and more Study notes Geology in PDF only on Docsity!

Hydrology Program Quantitative Methods in Hydrology

Lab Notes. 2 Matrices

Matrices

matrix - a rectangular array of number:

A matrix is usually identified by a boldface capital letter. The size of a matrix is m x n (read: “ m by n ”) where m is

the number of rows in the matrix and n is the number of columns. An entry in a matrix is denoted by a lowercase

letter with two subscripts indicating the row and column of the entry, e.g. a ij is the entry in the i th row and j th column

of matrix A. Matrices are used to solve systems of linear equations.

General matrix:

m m mn

n

n

a a a

a a a

a a a

1 2

21 22 2

11 12 1

A

Example : A is a 2x3 matrix.

A a 11 =1; a 12 =5; a 13 =3.2; a 21 =-7; a 22 = 2 ; a 23 =π

Special Matrices

Square matrix - a matrix that has the same number of rows and columns, i.e. n x n.

A B

Diagonal matrix - a square matrix whose only non-zero entries are on the diagonal,

i.e. a ij = 0 for i ≠ j.

A

Tri-diagonal matrix - a square matrix whose only non-zero entries are on the diagonal, and just above and just below

the diagonal.

Hydrology Program Quantitative Methods in Hydrology

Lab Notes. 2 Matrices

A

Upper Triangular Matrix ( U ) - a square matrix that has all zeroes below the diagonal.

Lower Triangular Matrix ( L ) - a square matrix that has all zeroes above the diagonal.

U L

Identity matrix ( I ) - a diagonal matrix with all ones on the diagonal.

I

Symmetric matrix - a square matrix with a ij = a ji.

A

Matrix Operations

Let:

21 22

11 12

31 32

21 22

11 12

21 22 23

11 12 13

21 22 23

11 12 13

d d

d d

c c

c c

c c

b b b

b b b

a a a

a a a

C D

A B

Matrix addition - two matrices of the same size (dimensions) can be added by adding the entries in the same

positions. If Z = A + B , then zij = a ij+ b ij.

( ) ( ) ( )

( ) ( ) ( )

21 21 22 22 23 23

11 11 12 12 13 13

a b a b a b

a b a b a b Z A B

Matrix subtraction - two matrices of the same size can be subtracted by subtracting the entries in the same

positions. If Z = A - B , then z ij = a ij- b ij.

Hydrology Program Quantitative Methods in Hydrology

Lab Notes. 2 Matrices

[ ]

a b

T

Hydrology Program Quantitative Methods in Hydrology

Lab Notes. 2 Matrices

Matrix Operations with MATLAB

In MATLAB matrices can be entered manually, or by using some pre-defined MATLAB functions. Here are some

examples.

Examples :

A=[1, 2, 3; 1, 4, 7; 2, 6, 1; 4, 5, 0]; % This creates a 4 x 3 matrix; each row is

% separated by a semi-colon; entries within % a row are separated by a comma (like % vectors)

B=zeros(4); % This creates a 4 x 4 matrix of all zeroes

C=ones(3,4); % This creates a 3 x 4 matrix of all ones

D=eye(5); % This creates a 5 x 5 identity matrix

E=diag([1,2,3]); % This creates a 3 x 3 diagonal matrix with

% 1, 2, and 3 on the first, second, and third % rows, respectively

F=5*C; % scalar multiplication

G=[3, 4, 5; 1, 6, 3; 2, 2, 9; -1, 0, 17];

H=G+A; % matrix addition

J=G-A; % matrix subtraction

K=G.*A % multiplies the i-j th entry of each matrix

L=A’; % transpose of A

M=G*L; % matrix multiplication

N=L*G; % matrix multiplication

O=[1, 2, 3; -1, 6, 0; 6, 2, 14];

P=inv(O); % inverse of O

P*O % does it equal the identity matrix?

A=det(P); % determinant of P

Other MATLAB commands:

contour - makes a contour plot of a 2-dimensional array (matrix)

b=0:5:50; - makes a vector from 0 to 50 in increments of 5 (0,5,10,…,50)