L13post

# L13post - Previous Lecture Examples on vectors(1-d arrays...

This preview shows pages 1–8. Sign up to view the full content.

± Previous Lecture: ± Examples on vectors (1-d arrays) ± Today’s Lecture: ± 2-d array—matrix ± Announcements: ± Prelim 1 tonight, 7:30-9pm ± A – G Æ Goldwin Smith 132 ± H – L Æ Goldwin Smith G76 ± M – S Æ Bradfield 101 ± T – Z Æ Goldwin Smith G64 ± Fall Break: We will post a discussion exercise for next week. On Wednesday section instructors will be in the classrooms as usual. Attendance is optional, but the content of the exercise is not!

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 8, 2009 Lecture 13 3 A Cost/Inventory Problem ± A company has 3 factories that make 5 different products ± The cost of making a product varies from factory to factory ± The inventory varies from factory to factory
October 8, 2009 Lecture 13 4 Cost Array C 10 36 22 15 12 35 20 12 13 37 21 16 66 62 59 The value of C(i,j) is what it costs factory i to make product j .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 8, 2009 Lecture 13 8 2-d array: matrix ± An array is a named collection of like data organized into rows and columns ± A 2-d array is a table, called a matrix ± Two indices identify the position of a value in a matrix, e.g., mat(r,c) refers to component in row r , column c of matrix mat ± Array index starts at 1 ± Rectangular : all rows have the same #of columns c r
October 8, 2009 Lecture 13 9 Creating a matrix ± Built-in functions: ones , zeros , rand ± E.g., zeros(2,3) gives a 2-by-3 matrix of 0s ± “Build” a matrix using square brackets, [ ] , but the dimension must match up: ± [x y] puts y to the right of x ± [x; y] puts y below x ± [4 0 3; 5 1 9] creates the matrix ± [4 0 3; ones(1,3)] gives ± [4 0 3; ones(3,1)] doesn’t work 4 0 3 5 1 9 4 0 3 1 1 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
October 8, 2009 Lecture 13 10 Function size returns the dimensions of a matrix ± [nr, nc]= size(M) % nr is #of rows, % nc is #of columns ± nr= size(M, 1) % # of rows ± nc= size(M, 2) % # of columns
Lecture 13 13 A= [1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/06/2010 for the course CS 9339 taught by Professor Gries during the Fall '09 term at Cornell.

### Page1 / 40

L13post - Previous Lecture Examples on vectors(1-d arrays...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online