CS112 Scientific Computation Department of Computer Science Wellesley College Matrices Storing two-dimensional numerical data.

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

1 CS 162 Introduction to Computer Science Chapter 7 Matrix Manipulation Herbert G. Mayer, PSU Status 9/21/2014.
MATLAB Examples. CS 1112 MATLAB Examples Find the number of positive numbers in a vector x = input( 'Enter a vector: ' ); count = 0; for ii = 1:length(x),
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Maths for Computer Graphics
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
Insight Through Computing 18. Two-Dimensional Arrays Set-Up Rows and Columns Subscripting Operations Examples.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Lecture 7 Sept 19, 11 Goals: two-dimensional arrays (continued) matrix operations circuit analysis using Matlab image processing – simple examples Chapter.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
Matlab Intro. Outline Matlab introduction Matlab elements Types Variables Matrices.
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Matrix Definition A Matrix is an ordered set of numbers, variables or parameters. An example of a matrix can be represented by: The matrix is an ordered.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
College Algebra Fifth Edition James Stewart Lothar Redlin Saleem Watson.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Matrices Write and Augmented Matrix of a system of Linear Equations Write the system from the augmented matrix Solve Systems of Linear Equations using.
11 Chapter 8 ARRAYS Continued. 22 MULTI-DIMENSIONAL ARRAYS A one-dimensional array is useful for storing/processing a list of values. For example: –The.
CS112 Scientific Computation Department of Computer Science Wellesley College Cold Coffee Vectors and plotting.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
ARRAY REFERENCING 1 1. II. Array Referencing Assume an array has values. It is useful to “refer to” the elements contained within it – as smaller portions.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
1 Chapter 3 Arrays (2) 1. Array Referencing 2. Common Operations 1. Slicing 2. Diminution 3. Augmentation 3. List of Commonly Used Built-in Functions 1.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
1 Data Structures CSCI 132, Spring 2014 Lecture 32 Tables I.
CS112 Scientific Computation Department of Computer Science Wellesley College Numb3rs Number and image types.
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
Exposure C++ Chapter XXI C++ Data Structures, the 2D Array apmatrix Implementation.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
CS112 Scientific Computation Department of Computer Science Wellesley College Building your own Functions.
Working with Arrays in MATLAB
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
CS112 Scientific Computation Department of Computer Science Wellesley College Tables More matrix fun.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Array Accessing and Strings ENGR 1187 MATLAB 3. Today's Topics  Array Addressing (indexing)  Vector Addressing (indexing)  Matrix Addressing (indexing)
Arrays.
Arrays Chapter 7. Arrays Hold Multiple Values Array: variable that can store multiple values of the same type Values are stored in adjacent memory locations.
CS112 Scientific Computation Department of Computer Science Wellesley College Building your own Functions.
ECE 103 Engineering Programming Chapter 23 Multi-Dimensional Arrays Herbert G. Mayer, PSU CS Status 6/24/2014 Initial content copied verbatim from ECE.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
CS112 Scientific Computation Department of Computer Science Wellesley College Vectors and indexing Tools of the trade.
Arrays. Arrays are objects that help us organize large amounts of information.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
A rectangular array of numeric or algebraic quantities subject to mathematical operations. The regular formation of elements into columns and rows.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
13.4 Product of Two Matrices
12-1 Organizing Data Using Matrices
Matrix Operations SpringSemester 2017.
Storing two-dimensional numerical data
Storing two-dimensional numerical data
CSCI N207 Data Analysis Using Spreadsheet
Communication and Coding Theory Lab(CS491)
Dimensions matching Rows times Columns
EECS Introduction to Computing for the Physical Sciences
Matrix Operations SpringSemester 2017.
Matrix A matrix is a rectangular arrangement of numbers in rows and columns Each number in a matrix is called an Element. The dimensions of a matrix are.
Presentation transcript:

CS112 Scientific Computation Department of Computer Science Wellesley College Matrices Storing two-dimensional numerical data

Matrices6-2 Our boys of summer Player Name Player Number Weight At Bat Home Runs Batting Average 2006 Salary RBIsRuns Stolen Bases Jason Varitek ,000, Mike Lowell ,000, David Ortiz ,250, Manny Ramirez ,016,

Matrices6-3 Medical imaging Matrices are particularly good for storing data that is inherently two-dimensional For example, the illustrated MRI slice is obtained from a two-dimensional grid of brightness measurements registered by an array of light sensitive elements

Matrices6-4 Matrices: The basics ● A matrix is a rectangular array of numbers ● We create a matrix of specific values with an assignment statement: >> flowers = [ ; ; ] flowers = flowers

Matrices6-5 Dimensions ● Each row must contain the same number of values! nums = [1 4 2; 6 8] ● size function returns the number of rows and columns in a matrix: >> dims = size(flowers) dims = 3 4 >> rows = size(flowers, 1) rows = 3 >> cols = size(flowers, 2) cols = flowers How could you determine the total number of elements in a matrix?

Matrices6-6 Déjà vu all over again Many computations can be performed on an entire matrix all at once flowers = 2 * flowers flowers

Matrices6-7 Element-by-element matrix addition sumFlowers = flowers + addOns flowers addOns + = sumFlowers How do you perform element-by-element multiplication?

Matrices6-8 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)

Matrices6-9 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 123 rowNums 13 rowNumsSize 12 colNums 331 colNumsSize

Matrices6-10 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 = [ ; ] totalSum = sum(numbers) totalProd = prod(numbers) minVal = min(numbers) maxVal = max(numbers) meanVal = mean(numbers) numbers

Matrices6-11 Hmmm… that’s not what I expected… numbers = [ ; ] totalSum = sum(numbers) totalProd = prod(numbers) minVal = min(numbers) maxVal = max(numbers) meanVal = mean(numbers) numbers 5447 totalSum totalProd 1123 minVal 4324 maxVal meanVal

Matrices6-12 Processing and displaying images An image is a two-dimensional grid of measurements of brightness We will start with images with brightness ranging from black (0.0) to white (1.0) with shades of gray in between (0.0 < b < 1.0) 1887 Crew Team Wellesley College

Matrices6-13 Creating a tiny image >> tinyImage = [ ; … ; … ; … ; … ] tinyImage >> imshow(tinyImage) (not to scale)

Matrices6-14 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)

Matrices6-15 Whodunit?? SuspectScott RandySohie

Matrices6-16 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

Matrices6-17 Creating matrices with constant values To create a matrix of all ones: nums1 = ones(2,3) nums2 = ones(1,5) To create a matrix of all zeros: nums3 = zeros(3,1) nums4 = zeros(4,3) nums2 nums1 nums4 nums3

Matrices6-18 Indexing with matrices Each row and column in a matrix is specified by an index nums = [ ; ] We can use the indices to read or change the contents of a location val = nums(2,3) nums(1,4) = 9 nums(1,end) = nums Similar to vectors

Matrices6-19 Time-out exercise Starting with a fresh copy of nums nums = [ ; ] 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

Matrices6-20 Auto expansion of matrices >> nums = [ ; ] >> nums(4, 7) = nums

Matrices6-21 Credits MATLAB Help: Visualizing MRI data Flowers: