



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Hydrology Program Quantitative Methods in Hydrology
Lab Notes. 2 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
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.
Diagonal matrix - a square matrix whose only non-zero entries are on the diagonal,
i.e. a ij = 0 for i ≠ j.
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
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.
Identity matrix ( I ) - a diagonal matrix with all ones on the diagonal.
Symmetric matrix - a square matrix with a ij = a ji.
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
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
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)