






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document from the cs112 scientific computation course at wellesley college introduces matrices, their uses, and basic operations such as addition and multiplication. Matrices are useful for storing two-dimensional data, like the brightness measurements in medical imaging. Creating matrices, determining their dimensions, and performing element-wise operations.
Typology: Study notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Matrices 6-
MannyRamirez 24 200 483 20 .296 17,016,381 88 84 0
DavidOrtiz 34 230 549 35 .332 13,250,000 117 116 3
MikeLowell 25 210 589 21 .324 9,000,000 120 79 3
JasonVaritek 33 230 435 17 .255 11,000,000 68 57 1
Stolen RBIs Runs Bases Batting Salary 2006 Average
At HomeRuns Weight Bat Player NumberPlayer Name
Matrices 6-
Matrices 6-
>> flowers = [1 3 2 7; 6 4 5 1; 2 8 3 7] flowers = 1 3 2 7 6 4 5 1 2 8 3 7^1 3 2 6 4 5 1 2 8 3 7
flowers
Matrices 6-
Element-by-element matrix addition
sumFlowers = flowers + addOns
3 7 5 15 13 9 11 3 5 17 7 15
flowers
+ addOns
=
How do you perform element-by-element multiplication?
Matrices 6-
Why isn’t this surprising?
You just learned that similar operations can be performed on matrices and vectors…
… because vectors are really just matrices that have only one row (row vector) or one column (column vector)
Matrices 6-
Indeed…
rowNums = [1 2 3] rowNumsSize = size(rowNums) colNums = [1; 2; 3] colNumsSize = size(colNums) In fact, a single number is stored in a 1 x 1 matrix
length function returns the maximum dimension of the matrix
rowNums 1 2 3
rowNumsSize 1 3
colNums 2 3
colNumsSize 3 1
Matrices 6-
Now I know what you’re thinking…
You probably think that we can use functions like sum, prod, min , max and mean in the same way they were used with vectors: numbers = [1 3 2 4; 4 1 2 3] totalSum = sum(numbers) totalProd = prod(numbers) minVal = min(numbers) maxVal = max(numbers) meanVal = mean(numbers)
numbers
Matrices 6-
Creating a tiny image
tinyImage
>> imshow(tinyImage)
(not to scale)
Matrices 6-
A mystery: Who am I?
This very corrupted image was received by anonymous courier late last night
Let’s figure out what’s in it using the Image Processing Toolbox >> imtool(image)
Matrices 6-
Whodunit??
Suspect Scott
Randy Sohie
Matrices 6-
Our strategy
Step 1. Calculate the difference between two images
Step 2. Use the abs function to calculate the magnitude of the difference between two images
Step 3. Calculate the average difference across the entire image
Matrices 6-
Time-out exercise
Starting with a fresh copy of nums nums = [1 3 7 4; 8 5 2 6]
what would the contents of nums and val be after executing the following statements? nums(2,3) = nums(1,2) + nums(2,4) nums(1,3) = nums(1,4) + nums(2,1) val = nums(4,3)
nums
Matrices 6-
Auto expansion of matrices
>> nums = [1 3 7 4; 8 5 2 6]
>> nums(4, 7) = 3
nums
nums 0 0