lecture09-1

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

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

View Full Document Right Arrow Icon
CS107, Prof. Steinberg, S12 1 Lecture 09 CS107: Computing for Math CS107: Computing for Math and Science and Science Lecture 09: Searching Sentinels
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
CS107, Prof. Steinberg, S12 3 Lecture 09 Review Review Ifs in loops Nested loops While loops
Background image of page 3

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

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

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

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

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

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

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

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

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

View Full DocumentRight Arrow Icon
CS107, Prof. Steinberg, S12 12 Lecture 09 Find the average of numbers
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online