HW5_ENED1090_Autumn_2016(1).pdf

HW5_ENED1090_Autumn_2016(1).pdf - Homework#5 ENED 1090...

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

View Full Document Right Arrow Icon
Homework #5 1 ENED 1090: Engineering Models I Homework Assignment #5 Due: Friday, October 7, 2016 at 5:00pm Must be submitted as a .pdf file Problem 1: For the code below, complete the table showing the values for the variables as the loop progresses. Do this without MATLAB first then check your results using MATLAB. x = 3; y = 5; for k = 1:4 total = x + y; x = y; y = total; end total x y Before Loop Not Defined Before Loop 3 5 k = 1 8 5 8 k = 2 13 8 13 k = 3 21 13 21 k = 4 34 21 34 Problem 2: For the code below, complete the table showing the values for the variables as the loop progresses. Do this without MATLAB first then check your results using MATLAB. t = [0 -5 4 3 2 -1 ]; count = 0; for k = 1:length(t) if t(k) >= -1 && t(k) < 4 count = count + 1; location(count) = k; end end Count Location Before Loop 0 Not Defined Before Loop k = 1 1 1 k = 2 1 1 k = 3 1 1 k = 4 2 [1 4] k = 5 3 [1 4 5] k = 6 4 [1 4 5 6]
Image of page 1

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

View Full Document Right Arrow Icon