![]() ![]() 225) Extra Problem (see assignments web page)! Extra Credit (see assignments web page)!! Read Palm section 4.7. Due: Palm MATLAB Ĭhapter 4: #22 (use for-loop in part b), 28 (use a while-loop), T4.5-4 (p. ENGR 111A - Spring 2004Ģ8 Assignment 11.1 Individual assignment. ENGR 111A - Spring 2004Ģ7 EXAMPLE r = 1 N = 10 while r <= N c = 1 while c <= NĪ(r,c) = 1/(r + c -1) c = c + 1 end r = r + 1 end %- note use of r,c instead of i,j. while expression, statements, end evaluates an expression, and repeats the execution of a group of statements in a loop while the expression is true. break statements may be used to jump out of loops. Write an equivalent while loop for the implied loop shown: x = y = sin(x) disp (y) Save on the R:\ drive Name file after a city outside of Texas ENGR 111A - Spring 2004Ģ5 SOLUTION x = 0 while x <= 100 y = sin(x) x = x+5 disp(y) endĢ6 NESTED while LOOPS while loops can also be nested.Įach loop must be closed with an end. Make sure that you save your code before testing any while … end loop. ENGR 111A - Spring 2004Ģ3 while … end Loops (p.222) THE LOOP VARIABLE MUST HAVE A VALUE BEFORE THE while STATEMENT IS EXECUTED THE LOOP VARIABLE MUST BE CHANGED SOMEHOW BY THE STATEMENTS Note the usual mistakes toward the bottom of the page. ![]() Then exit the loop when x exceeds or equals 25. While x < 25 disp(x) x = 2*x-1 %-make sure x changes end Means: starting with x = 5, execute the statements between the while … end this displays x and calculates a new value of x and loops back. ENGR 111A - Spring 2004Ģ1 while LOOP FLOW CHART Loop structure ENGR 111A - Spring 2004Ģ2 while … end Loops Look at the examples on page 221. The number of passes is NOT known a priori SYNTAX: while logical expression statements end See p. ![]() ENGR 111A - Spring 2004Ģ0 while LOOPS The while loop terminates because a specified condition is satisfied. However, now that I am adding a few extra steps in between, and want it to stop, it is no longer viable. In my first drafts I simply let it run for a large number of steps. Step value may be negative (default is positive 1) For step > 0, loop does not execute if start > stop For step 0) See p. I am trying to make a loop until a certain event happens. Then exit the loop (k=? at this point) ENGR 111A - Spring 2004ĩ for … end Loops cont’d. What is the FINAL value assigned to y in the following segment of MATLAB code? x = 0 while x 35. 1 MatLab – Palm Chapter 4, Part 3 For and While LoopsĬlass 11.1 Palm Ch 4.5 ENGR 111A - Spring 2004Ģ RAT 11.1 As in INDIVIDUAL you have 2 minutes to answer the following question. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |