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

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

View Full Document Right Arrow Icon
± 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!
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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 .
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
Lecture 13 13 A= [1
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online