Lecture 07 Presentation

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

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

View Full Document Right Arrow Icon
14:440:127 Introduction to Computers for Engineers Lecture 7 LEASE TAKE LECTURE 7 NOTES PLEASE TAKE LECTURE 7 NOTES AS YOU ENTER THE ROOM! Lecturer: Blase E. Ur Recitation Instructor: Bo Jin Recitation Instructor: Cyrus Gerami Recitation Instructor: Vishnu Vijayakumar Recitation Instructor: Wen Yueh
Background image of page 1

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

View Full DocumentRight Arrow Icon
14:440:127 Lecture 7 For Loops Sum 1, 2, and 3 digit primes total = 0; for k = 1:999 if(isprime(k)) Rutgers University BuffaLOL total = total + k; end end disp(total)
Background image of page 2
14:440:127 Lecture 7 For Loops Sum 1, 2, and 3 digit primes total = 0; for k = primes(999) total = total + k; Rutgers University BuffaLOL end disp(total)
Background image of page 3

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

View Full DocumentRight Arrow Icon
14:440:127 Lecture 7 For Loops Find Maximum Value in Vector % assume the vector V has already been defined % set maxvalue to be -inf % loop through each element of V Rutgers University BuffaLOL % if the current element is bigger than maxvalue % replace maxvalue with the current element % end % end % display the maximum value
Background image of page 4
14:440:127 Lecture 7 For Loops Find Maximum Value in Vector % assume the vector V has already been defined maxvalue = -inf; for j = 1:length(V) Rutgers University BuffaLOL if( V(j) > maxvalue ) maxvalue = V(j); end end disp(maxvalue)
Background image of page 5

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

View Full DocumentRight Arrow Icon
14:440:127 Lecture 7 For Loops Duplicate elements V = 1:5; % sample vector %%% method 1 for j = 1:length(V) V2((2*j-1):(2*j)) = V(j); Rutgers University BuffaLOL end disp(V2)
Background image of page 6
14:440:127 Lecture 7 For Loops Duplicate elements V = 1:5; % sample vector %%% method 2 for j = 1:(2*length(V)) V2(j) = V(ceil(j/2)); Rutgers University BuffaLOL end disp(V2)
Background image of page 7

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

View Full DocumentRight Arrow Icon
14:440:127 Lecture 7 For Loops Duplicate elements V = 1:5; % sample vector %%% method 3 counter = 0.5; for j = 1:(2*length(V)) Rutgers University BuffaLOL V2(j) = V(ceil(counter)); counter = counter + 0.5; end disp(V2)
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

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

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

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