ENG EK 127 Midterm: EK127 EXAM 2 REF SHEET

139 views2 pages

Document Summary

Calc a prod=to 1. for loop: if a vector is to be created in a loop, preallocate 1st. Counted for loops use i/loop var to specify # times to repeat. Loop var(s) are used to index into the els of vecs/mats. running sum: Rreallocating vecs:function numvec = forinput(cid:523)n(cid:524)///numvec=zeros(cid:523)(cid:883),n(cid:524);///for iv = (cid:883):n///inputnum = input(cid:523)(cid:494)enter a number:(cid:495)(cid:524);///numvec(cid:523)iv(cid:524) = inputnum;///end///end vec = zeros(1,n);///for i = 1:n///vec(cid:523)i(cid:524) = input(cid:523)(cid:494)enter a number:(cid:495)(cid:524);///% do something with it///end. Nested loops & mats: loops can be used to iterate through the els of a mat. Conditional (while) loops: count how many times the action of a while loop is repeated. Important application: error checking - loop until the user enters a value in the correct range. Conditional for t/f, action is repeated as long as condition is t. Counting in a while loop: counter = 0;///while condition///%action///counter = counter + 1///end///%use counter (do something w/ it)

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers

Related Documents