14-440-127 Lecture 9 Presentation

14-440-127 Lecture 9 Presentation - 14:440:127 Introduction...

Info icon This preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
14:440:127 Introduction to Computers for Engineers Lecture 9 Lecturer: Blase E. Ur Recitation Instructor: Tianming Li Recitation Instructor: Ke Xu Recitation Instructor: Brian Viezbicke Recitation Instructor: Mingliang Wang PLEASE TAKE LECTURE 9 NOTES AS YOU ENTER THE ROOM …Yup, shoulder’s still recovering
Image of page 1

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

View Full Document Right Arrow Icon
Rutgers University SOE 14:440:127 Lecture 9 Reminders / Updates Exam 1- “Hakuna Matata” (<=8% if you do better on Exam 3) Exam 2- Next Week, beginning on Wednesday (Study Recitation Problems) Project 2- Yikes, sorry for the delay.
Image of page 2
Rutgers University SOE 14:440:127 Lecture 9 For Loop for VARIABLE = VECTOR STATEMENTS end for x = 1 : 100 disp(x) end First time through the loop, x=1 Then, go back to the top; x=2 The last time through the loop, x=100
Image of page 3

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

View Full Document Right Arrow Icon
Rutgers University SOE 14:440:127 Lecture 9 When Writing…. Find Pattern v(1)=1; %fibonacci v(2)=1; v(3)=v(2)+v(1); v(4)=v(3)+v(2); v(5)=v(4)+v(3); % What is the pattern? v(1)=1; v(2)=1; for x=3:100 v(x)=v(x-1)+v(x-2); end disp(v)
Image of page 4
Rutgers University SOE 14:440:127 Lecture 9 Sum 1 to 100 with a for loop s = 0; for z = 1:100 s = s+z; end disp(s) % error in notes!
Image of page 5

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

View Full Document Right Arrow Icon
Rutgers University SOE 14:440:127 Lecture 9 Sum the odd numbers s = 0; for z = 1: 2 :99 % note the error in your notes s = s+z; end disp(z)
Image of page 6
Rutgers University SOE 14:440:127 Lecture 9 Sum primes from 1 to 1000 s = 0; for x = 1:1000 if(isprime(x)) s = s+x; end end disp(s)
Image of page 7

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

View Full Document Right Arrow Icon
Rutgers University SOE 14:440:127 Lecture 9 While while(CONDITION) % replace capitalized parts STATEMENTS % replace capitalized parts end n=rand(1); while(n<0.5 | n>0.7) n=rand(1); end
Image of page 8
Rutgers University SOE 14:440:127 Lecture 9 While n=rand(1); count=1; while(n<0.5 | n>0.7) n=rand(1); count=count+1; end disp(n) disp(count)
Image of page 9

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

View Full Document Right Arrow Icon
Rutgers University SOE 14:440:127 Lecture 9 While Example: If you sum the integers 1 through n, what is the smallest n for which the sum is a 3 digit number? s = 0; n=1; while(s<100) s = s+n; n=n+1; end fprintf('The smallest n is %.0f',n-1)
Image of page 10
Rutgers University SOE 14:440:127 Lecture 9 Write a For Loop as a While Loop for x = 1001:2:9997 if(isprime(x) & isprime(x+2)) fprintf('%.0f and %.0f are both prime\n',x,x+2) end end ------------------------------------------------------ x=1001; %STEP 1: Set x while(x<=9997) %STEP 2: Write loop if(isprime(x) & isprime(x+2)) fprintf('%.0f and %.0f are both prime\n',x,x+2) end x = x+2; %STEP 3: Last line of loop = increment end
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern