{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture09-1

# lecture09-1 - CS107 Computing for Math and Science Lecture...

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

CS107, Prof. Steinberg, S12 1 Lecture 09 CS107: Computing for Math CS107: Computing for Math and Science and Science Lecture 09: Searching Sentinels

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

View Full Document
CS107, Prof. Steinberg, S12 2 Lecture 09 Announcements Announcements Exam 1 Tuesday, Feb 21, 5:00 pm, here See Sakai Resources > Exam Info No recitation that day No lecture Thursday, Feb 23 Yes recitation
CS107, Prof. Steinberg, S12 3 Lecture 09 Review Review Ifs in loops Nested loops While loops

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

View Full Document
CS107, Prof. Steinberg, S12 4 Lecture 09 Ifs in loops Ifs in loops An if inside a loop follows the same rules as it would outside the loop it does so each time we get to the if
CS107, Prof. Steinberg, S12 5 Lecture 09 Ifs in loops Ifs in loops for j = 1:4 if j<3 disp([num2str(j) ' is lt 3' ]) else disp([num2str(j) ' is not lt 3' ]) end end 1 is lt 3 2 is lt 3 3 is not lt 3 4 is not lt 3

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

View Full Document
CS107, Prof. Steinberg, S12 6 Lecture 09 Find smallest two numbers Find smallest two numbers Needs two summary variables: smallest number seen so far second smallest number seen so far See smallest2.m
CS107, Prof. Steinberg, S12 7 Lecture 09 Loops in loops Loops in loops for j = 1 : 3 for k = j : 3 disp( [j k] ) end end 1 1 1 2 1 3 2 2 2 3 3 3 1st repetition of outer loop 2nd repetition of outer loop 3rd repetition of outer loop

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

View Full Document
CS107, Prof. Steinberg, S12 8 Lecture 09 Loops in loops example Loops in loops example Given some vectors of test scores Find the largest score in each vector Return average of these largest scores E.g. vector largest score [92 78 88 95] 95 [70 63 97 91] 97 [85 96 93 89] 96 average: 96
CS107, Prof. Steinberg, S12 9 Lecture 09 What are the problems? What are the problems? Input some vectors Find the largest score in each vector Find the average of some numbers

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

View Full Document
CS107, Prof. Steinberg, S12 10 Lecture 09 Input some vectors Input some vectors numVectors = input('How many vectors? '); for j = 1 : numVectors numbers = input('Type a vector: '); %do something with the vector end
CS107, Prof. Steinberg, S12 11 Lecture 09 Find largest score in a vector Find largest score in a vector big = numbers(1); for k = 2 : length(numbers) if numbers(k) > big big = numbers(k); end end

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

View Full Document
CS107, Prof. Steinberg, S12 12 Lecture 09 Find the average of numbers
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 41

lecture09-1 - CS107 Computing for Math and Science Lecture...

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

View Full Document
Ask a homework question - tutors are online