Lecture 07 Presentation

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

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

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

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

View Full Document
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)
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)

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

View Full Document
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
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)

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

View Full Document
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)
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)

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

View Full Document
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)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/11/2010 for the course 440 127 taught by Professor Blase during the Fall '09 term at Rutgers.

### 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
Ask a homework question - tutors are online