Class Notes (836,580)
Canada (509,856)
Computing (443)
CISC 101 (29)
Lecture

Class 3.docx

10 Pages
91 Views
Unlock Document

Department
Computing
Course
CISC 101
Professor
David Skillicorn
Semester
Fall

Description
Class 3.1 9/25/2012 10:27:00 AM Labs –location 155 Solutions Friday class before thanksgiving??? CANCELED!! _____________________________________________________________ For i=1:10 loop control variable / index  increase after each rotation Commands loop body –repeated final value End Ten iterations for 1=1:10 for i=3:12 for i=1:2:20 st 1 i=1 i=3 i=1 nd 2 i=2 i=4 1=3 rd 3 i=3 i=5 1=5 10th i=10 i=12 i=19 Flavors of loops: Programming – language Easiest For i=1:15 Disp(‘another iteration’);  display end for i=1:15 a(i)=0;  depends on I,but each iteration is independent end 0 0 0 0 0 0 0 0 0 0 add upthe numbersin a vector 1 7 3 2 5 7 1 3 1 running sum runningsum=1; default value required for i=1:7 come from array size directly runningsum = runningsum +a(i); end  works for empty arrays top = size (a); runningsum=0; Works for any vector for i=1:top runningsum=runningsum+a(i) General case: initialization For index variable & range End -find product of entries in a vector _____________________________________________________________ Matlab sum operation our own version: pseudocode for each column: calculate a running sum down that column _____________________________________________________________ for each column  initializerunning sum for each element down the column  add its value into the running sum [n,m]= size (a); for j =1:m %for each column runningsum=0; for i=1:n % down each column runningsum=runningsum + a(i,j) end end mysum(j)=rinningsum; end Class 3.2 9/25/2012 10:27:00 AM n=# of rows m=#columns [n,m]=size(a) for j=1:m Top-down design find the sum of each column runningsum=0; for i=1:n runningsum=runningsum+a(I,j) end tot(j)= runningsum end zeros command -creates a vector filled with zeros before t
More Less

Related notes for CISC 101

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit