Class Learning Objectives o Achieve Comprehension LOL of using Loops in programming. C 12 -1 Spring 2012 2
Session Agenda o Contact before work o Nested For statements C 12 -1 Spring 2012 5 min. 70 min. 3
Contact before work o. Burning Questions C 12 -1 Spring 2012 4
Nested for loop o What does the following program do? C 12 -1 Spring 2012 5
Flow chart start x y y J=1 i=1 J+1 i+1 T T j<=y i<=x z( i. j)=0 F F end z C 12 -1 Spring 2012 6
Output: C 12 -1 Spring 2012 7
Example: o Consider the array A A= Write a MATLAB program that computes the array B by computing the square roots of all the elements of A whose values is no less than 0, and adding 50 to each element that is negative. C 12 -1 Spring 2012 8
Solution: C 12 -1 Spring 2012 9
C 12 -1 Spring 2012 10
Example : o Suppose we want to create a special square matrix that has ones in the first row and first column , and whose remaining elements are the sum of two elements, the element above and the element to the left, if the sum is less than 20 , Otherwise, the element is the maximum of those two element values. C 12 -1 Spring 2012 11
let row=column=5 C 12 -1 Spring 2012 12
C 12 -1 Spring 2012 13
C 12 -1 Spring 2012 14
o Final Exam o Day: Saturday, 26/05/201205/07/1433 o Time: : 4. 30 PM - : 6. 30 PM o Location: building ? ? ? ? ? C 12 -1 Spring 2012 15