Above: Mathematical Inversion of GPS data for strain in SoCal Above: Fault slip rates on the Sierra Madre fault in SoCal
• MATLAB is not free
• can become expensive if you use
toolboxes
• Can be slow for some operations
• Launching MATLAB is very slow
• Interpreted language (not formally
compiled)
• Language is converted into machine
language on the fly
• Good news: most commands are
highly optimized
• Awkward handling of non-
numeric data* Slip rate vectors on the Hollywood fault, CA
• int8, int16, int32, int64 (integer): Can save memory (in some
cases. See Ch1 of Attaway)
𝟏
𝑨= or 𝟏 𝟐 -Wind directions,
𝟐
-Stream flow direction
-Plate Motions
-Fault slip
𝟏
𝑩= or 𝟏 −𝟑 -Glacier motion
−𝟑 Etc…
• rowVect = 1 2 3
>> rowVect = [1 2 3]
>> rowVect = [1, 2, 3]
4
• columnVect = 7
9
>> columnVect = [4; 7; 9]
1
= 2x1 matrix (column vector)
2
1 3
= 2x2 matrix (square)
2 4
1 5
2 6
= 4x2 matrix (rectangular)
3 7
4 8 The matrix has you…
• Defining matrices in MATLAB is also straightforward
• Again, use square brackets
1 3
• Mat2x2 =
2 4
>> mat2x2 = [1 3; 2 4]
>> mat2x2 = [1, 3; 2, 4]
1 3 5
• mat2x3 =
2 4 6
>> mat2x3 = [1 3 5; 2 4 6]
>> mat2x3 = [1, 3, 5; 2, 4, 6]
1 4
• mat3x2 = 2 5
3 6
>> mat3x2 = [1 4; 2 5; 3 6]
>> mat3x2 = [1, 4; 2, 5; 3, 6]
• Matrix Addition/Subtraction
• Both must have same dimensions
• Add each corresponding element
• Result has same dimensions
• + is Commutative A + B = A + B
• - is not commutative A - B ≠ B - A
• Concatenating a matrix works the same way. (make sure dimensions are consistent)
• Row vector
>> stuff = [2 3 4]
>> otherStuff = [5 6 7]
>> allStuff = [stuff, otherStuff]
• Column vector
>> stuff = [1; 2; 3]
>> otherStuff = [4; 5; 6; 7]
>> allStuff = [stuff; otherStuff]
• Matrix
>> mat = [1 3; 2 4]
>> mat2 = [5 7; 6 8]
>> newMat = [mat, mat2] %what will size of newMat be?
>> newMat2 = [mat; mat2] %what will size of newMat2 be?
𝟗 𝟒 𝟐
𝟏𝟎 𝟒𝟏
𝟑 𝟕 𝟓
test = test2 = 𝟑 𝟖 𝟐 −𝟒 𝟔 𝟏 test3 = 𝟐𝟒 𝟐
𝟏𝟏 𝟏 𝟏𝟎
𝟓 𝟏𝟐
𝟖 𝟔 𝟏𝟐
>> sin(test) %takes the sine of all of the entries in test individually
>> sqrt(test2) %takes the sqrt of all entires in test2
>> log(test3)
• Most functions that generate values, can generate matrices!
>> rand(3,4)
>> round(rand(6,2)*20)