Lab 6 focuses on Chapter 6 of Gilat. This... programming (primarily conditional statements and loops, so it is IMPERATIVE...

advertisement

Lab 6 focuses on Chapter 6 of Gilat. This is probably the most difficult lab since it involves programming (primarily conditional statements and loops, so it is IMPERATIVE that students plan this out as much as possible-waiting until the night before just about GUARANTEES that the team will

NOT finish the lab in time!

g5c6p212x07: (for/end loops and nested loops) Students should use 2 for/end loops: one nested inside the other. The basic structure of a for/end loop is on pp192-194 of Gilat. There is a useful example on pp200-202 of using nested loops to create a matrix-students just have to replace the conditional statements with the formula. Regarding the formula, note that A(i,j) is the sum of the first j elements of the previous row (meaning the : notation from pp44-45 may be useful) g5c6p212x08: (logical operators) Enter the temperatures as two vectors. Use the sum and length commands to find the averages first. The rest can be done very quickly using MATLAB's ability to test vector conditions element by element (see pp177-178 and especially Sample Problem 6-1 on pp183-184 for examples).

g5c6p214x19: (nested loops and conditional statements) A good tip here is to start with c=1:50, then b=1:c (since c is the largest side), then a=1:b (to avoid duplicates a,b,c and b,a,c). Once the condition is satisfied, either display a, b, and c immediately (as a vector) or add a new row to a matrix A consisting of the triples (by creating a new variable n which indicates which row is to be built next and increasing it each time the condition is met).

g5x6p215x24: (loops and nested conditional statements) After starting the loop at n=1, use conditional statements to determine IF sum(1:n) is less than 100 AND greater than 1000. If so, the easiest way I found to check the digits is to extract the hundreds digit (see "fix" on p15) and test whether the sum -

111*hundreds_digit is 0. If all of these are true, break the loop and display the required statements and values; otherwise, continue the loop to the next value of n. Refer to pp184-186 for if statements

(***pay particular attention to the use of the double-equals (==) for testing equality!), and p179 for the

"AND" syntax (which should also be doubled (&&) within an "if" statement).

g5c6p216x26: (if/elseif/else statements) Ignore the "ask user to enter" part of the directions; instead, copy or run the program twice, defining the variables for part a) and b) each time. Calculuate the BMI, then use if/elseif/else statement to print the BMI with the correct classification (use the fprintf command again to do this).

I encourage you to read over the chapter. Also, remind you that the e-book gives the students access to several videos from its website to help them with this material.

Download