PGE 310 - HW4 - Solution

PGE 310 - HW4 - Solution - The University of Texas at...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
The University of Texas at Austin PGE 310: Formulation and Solution in Geosystems Engineering Homework #4: (If…else) Structure, Functions and Loops in MATLAB Due Date: Thursday September 30rd 2010 1. Consider the following Matlab code written in a script file and determine the value of “ ires ” and/or “ jres ” at the end of each of the loops, and also the number of times each loop executes. Clearly show your intermediate calculation steps for each time that the loop runs. a. ires=0; for i=-6:2:4 ires=ires+i-1; end 16 1 ) 0 ( ) 15 ( 0 15 1 ) 2 ( ) 12 ( 2 12 1 ) 4 ( ) 7 ( 4 7 1 ) 6 ( 0 6 ! " ! # ! " " ! " ! ! # ! " ! " ! " ! ! # ! " ! " ! " ! ! # " ! " ires i ires i ires i ires i 12 6 , 12 1 ) 4 ( ) 15 ( 4 15 1 ) 2 ( ) 16 ( 2 ! " ! " ! # ! " " ! " ! # ! " " ires Final times runs loop the Totally ires i ires i b. ires=0; for i=7:-2:-1 if i == 0 break; end ires=2*ires+i end 41 3 19 * 2 0 3 19 5 7 * 2 0 5 7 7 0 * 2 0 7 " # " $ " " # " $ " " # " $ " ires i i ires i i ires i i 165 5 , 165 ) 1 ( 83 * 2 0 1 83 1 41 * 2 0 1 " " ! # " $ ! " " # " $ " ires Final times runs loop the Totally ires i i ires i i c. ires=4; while ires <=600 ires=(ires^2)/2; end 512 2 / ) 2 ^ 32 ( 600 32 2 / ) 2 ^ 8 ( 600 8 2 / ) 2 ^ 4 ( 600 4 " " %" " " %" " " %" " ires ires ires ires ires ires ires 131072 4 , 600 131072 2 / ) 2 ^ 512 ( 600 " " " %" ires Final times runs loop the Totally iires ires ires
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2. Hin a b R d. Wri AT ) the Use Prin nts: . . esu ir w en ite a ), w ope e the nt ou Yo the Wo of nee ults res= hile ir jr nd a MA hich erati e co ut y ou ca e nu ork how ed to =2; j e ire es= es= ATL h are on a mm our an u mbe out w the o us jres es < =jres =ires LAB e th and and fun use t er of a pr e alg se “n =3 <50 s^2; s^2; Fin Tot ires ires ires ires B fu he el can d wi nctio the “ f row robl gori nest 0 or ; ; 5 5 5 2 % % % " i nal ally uncti leme nnot ndo on fi
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/12/2011 for the course PGE 310 taught by Professor Klaus during the Spring '06 term at University of Texas at Austin.

Page1 / 5

PGE 310 - HW4 - Solution - The University of Texas at...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online