Goals for today Learn to create, combine, and index arrays Learn to multiply arrays in MATLAB Use matrix multiplication to simulate a real-world problem Thursday, June 30 th, 2016
Last time: assignment addition/subtraction multiplication/division exponentiation expression target = expression a + b a - b a*b a/b a^b a b result order of operations: PEMDAS () ^ * / + -
Vectors, matrices, and multi-dimensional arrays columns rows pages
Creating arrays A = [5, 2, 1; 3, 2, 7] separate elements on a row with a comma separate rows with a semicolon
Special commands for creating arrays eye(n) ones(n, m) zeros(n, m) start:step:end
Transpose arrays with the ‘ operator F = A’ AF G = B’ B G
Join arrays together with square brackets ABC A D E
Think-Pair-Share: Can these arrays be joined? (1) (2)(3)
Retrieving parts of an array: “indexing” A(1, 2) row(s) column(s)
Retrieving parts of an array: “indexing” A(2, 3)
Multiple indices A([1, 2, 3], [2, 3]) rows columns
Multiple indices A(:, [2, 3]) shorthand for “all rows”
practice… (a) (d) (f) (e) (c) (b)
Matrix multiplication
Visualizing matrix multiplication
3 rows 3 columns 3x3 matrix
Multiplying arrays
Will they multiply? N
Properties of Matrix Multiplication Yes or no?
Multiplying rabbits
Can you help the rabbits survive longer without becoming overpopulated? What happens to the population over time? What happens when you change the birth rate? What happens when you change the survival rates?