Lecture+07+Presentation

# Lecture+07+Presentation - 14:440:127 Introduction to...

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

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

View Full Document

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

View Full Document

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

View Full Document

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.

Unformatted text preview: 14:440:127 Introduction to Computers for Engineers Lecture 7 Lecturer: Brenda Cortez Recitation Instructors: Yun, Bo, Karthik, Muhammad 1 Rutgers School of Engineering LEC07 14:440:127 General Announcements • HW02- DONE and GRADED • PROJ02- DUE ON MONDAY • PROJ02 TUTORING- TODAY & TOMORROW from 6:30-8ish in DSV • HW01/PROJ01 - Any questions must be addressed by no later than this Friday, October 22nd • EXAM01/HW02 - Any question must be addressed by no later than next Friday, October 29 2 14:440:127 Rutgers School of Engineering LEC07 14:440:127 Last week ʼ s topics: • For Loops & While Loops • each pass through a loop is called an iteration • infnite loops can be broken by clicking CTRL + C • avoid them, unless they are completely necessary and/or required ¡or the answer • when increasing a counter, the correct way is: counter = counter + 1; 3 14:440:127 Lets recap... Rutgers School of Engineering LEC07 14:440:127 Last week ʼ s topics: • For Loops & While Loops • each pass through a loop is called an iteration • infnite loops can be broken by clicking CTRL + C • avoid them, unless they are completely necessary and/or required ¡or the answer • when increasing a counter, the correct way is: counter = counter + 1; 3 14:440:127 Lets recap... Rutgers School of Engineering LEC07 14:440:127 For Loops for VARIABLE_NAME = VECTOR_OF_VALUES STATEMENTS .... end 4 vector of values variable name Example: for k = [1,3,5] k end k =1; k is displayed to the command window 1st iteration k = 3; k is displayed to the command window 2nd iteration k = 5; k is displayed to the command window 3rd iteration notice how it is not suppressed Rutgers School of Engineering LEC07 14:440:127 For Loops for VARIABLE_NAME = VECTOR_OF_VALUES STATEMENTS .... end 5 vector of values variable name Example: for k = 1:3 a = 5^ k end k = 1; a = 5^ k = 5^ 1 a = 5 1st iteration k = 2; a = 5^ k = 5^ 2 a = 25 2nd iteration k = 3; a = 5^ k = 5^ 3 a = 125 3rd iteration notice how it is not suppressed Rutgers School of Engineering LEC07 14:440:127 For Loops for VARIABLE_NAME = VECTOR_OF_VALUES STATEMENTS .... end 6 Example: for k = 1:3 a (k) = k ^2 end k = 1; a (1) = k ^2 = 1 ^2 a = 1 1st iteration k = 2; a (2) = k ^2 = 2 ^2 a = 1 4 2nd iteration k = 3; a (3) = k ^2 = 3 ^2 a = 1 4 9 3rd iteration notice how a new vector was created Rutgers School of Engineering LEC07 14:440:127 For Loops for VARIABLE_NAME = VECTOR_OF_VALUES STATEMENTS .... end 7 Example: scores = [76, 45, 98, 97]; count = 0; for k = 1: length (scores) if (scores( k )>90) count = count+1; end end disp(count) k = 1; scores (1) = 76 > 90? No, so count not incremented 1st iteration k = 2; scores (2) = 45 > 90?...
View Full Document

{[ snackBarMessage ]}

### Page1 / 34

Lecture+07+Presentation - 14:440:127 Introduction to...

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

View Full Document
Ask a homework question - tutors are online