ENG1060 Lecture Notes - Lecture 5: Minimax, Iter

105 views5 pages
For
!"#$%&'$&%("$)"%(*(+$"'),,+-.#"/)%"+"#*('0/0(."-&,1(%)/"$0,(#
2(#$"34(-"5)&"6-)3"(7+'$85"4)3",+-5"$0,(#"5)&"3+-$"$)"8))*"$4%)&94"+"
#('$0)-")/"').(
:
;4)%$(-#"').("<<<"9))."*%)9%+,,0-9"*%+'$0'(
;5-$+7
for <counter> = <vector>
<commands>
end
fprintf('counter is %d\n',counter);
end
=)&-$(%"#$(*#"$4%)&94"(+'4">+8&("0-#0.("$4(">('$)%
=+-"1("&#(."/)%"'+8'#"?@"0-.(7"/)%",+$%0'(#
:
While
A4(-"-&,1(%")/"0$(%+$0)-#"0#"&-6-)3-B"1&$"5)&"4+>("+"')-.0$0)- 5)&"
3+-$"$)",(($
:
;5-$+7
while <condition>
<commands>
end
x = 1;
iter = 0;
while x^2 < 12345
iter = iter + 1
x = 8*x
fprintf('iteration=%i,x=%i,x^2=%i\n',iter,x,x^2)
(nd
C+6("#&%("5)&%"')-.0$0)-"1('),(#"/+8#("+$"#),("*)0-$B")$4(%30#("
0-/0-0$("8)*"'%(+$(.
:
;0-'("'),,+-.#"+%("%(*(+$(."+#"8)-9"+#"')-.0$0)-"0#"$%&(:
Nested
D#(/&8"$)"#$)%( >+8&(#"0-"+",+$%07"0-#$(+.")/"*%0-$0-9
E)"$(%,0-+$("8))*B"&#("break
=),,+-.#"+/$(%3+%.#"3088"-)$"%&-:
?-85"1%(+6#")&%")/"+"#0-98("8))*B"#)"3088"-)$"#$)*"-(#$(."8))*#"0/")-85"
&#(.")-"0--(%"8))*
:
?-85"$)"4+-.8("&-(7*('$(."#0$&+$0)-#:
FFG/"*%)9"').(."3(88B"-)$"%(H&0%(."+$"+88:
E)"#60*"0$(%+$0)-B"&#("continue
=),,+-.#"+/$(%3+%.#"3)-I$"%&-:
Switch
J06("0/K#$+$(,(-$B"'4('6#"L">+%0+18("+9+0-#$".0//"'+#(#"M'+-"')-$+0-",&8$0*8("
>+8&(#N
O"1($$(%"%(+.+1080$5 0-"#),("'+#(#
K'+-I$"0-'8&.("%(8+$0)-+8")*(%+$)%# 806("P")%"<"/)%"'),*+%0#)-"+9+0-#$"
Q#30$'4Q"(7*%(##0)-
R+>("$)"&#("0/K#$+$(,(-$#"$)"$(#$"/)%"0-(H&+80$5S
K'+-")-85"')-$+0-".0#'%($( >+8&(#
K'+-I$ &#("break
;5-$+7
switch <variable>
case { val1 val2 val3 val4 }
<commands1>
case { val5 val6 val7 val8 }
<commands2>
otherwise
<commands3>
end
Find
!"%($&%-#"0-.0'(#")/"34(%("$4("')-.0$0)-"0#"$%&(
FF"/)%"/0-.0-9",+7T,0-">+8&(#")/"+",+$%07
;5-$+7
indices = find(<condition>)
E)"%($&%-"U")&$*&$#"M&#(/&8"34(-"+..%(##0-9"+",+$%07NV
[row_index, col_index] = find(<condition>)
W9S"/0-.0-9",+7">+8&("0-"(-$0%(",+$%07
Week$5:$Loops
;+$&%.+5B"LX"Y&9&#$"UZL[
L\VZX
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
For
!"#$%&'$&%("$)"%(*(+$"'),,+-.#"/)%"+"#*('0/0(."-&,1(%)/"$0,(#
2(#$"34(-"5)&"6-)3"(7+'$85"4)3",+-5"$0,(#"5)&"3+-$"$)"8))*"$4%)&94"+"
#('$0)-")/"').(
:
;4)%$(-#"').("<<<"9))."*%)9%+,,0-9"*%+'$0'(
;5-$+7
for <counter> = <vector>
<commands>
end
for counter = 1:2:11
fprintf('counter is %d\n',counter);
end
=)&-$(%"#$(*#"$4%)&94"(+'4">+8&("0-#0.("$4(">('$)%
=+-"1("&#(."/)%"'+8'#"?@"0-.(7"/)%",+$%0'(#
:
While
A4(-"-&,1(%")/"0$(%+$0)-#"0#"&-6-)3-B"1&$"5)&"4+>("+"')-.0$0)- 5)&"
3+-$"$)",(($
:
;5-$+7
while <condition>
<commands>
end
x = 1;
iter = 0;
while x^2 < 12345
iter = iter + 1
x = 8*x
fprintf('iteration=%i,x=%i,x^2=%i\n',iter,x,x^2)
(nd
C+6("#&%("5)&%"')-.0$0)-"1('),(#"/+8#("+$"#),("*)0-$B")$4(%30#("
0-/0-0$("8)*"'%(+$(.
:
;0-'("'),,+-.#"+%("%(*(+$(."+#"8)-9"+#"')-.0$0)-"0#"$%&(
:
Nested
D#(/&8"$)"#$)%( >+8&(#"0-"+",+$%07"0-#$(+.")/"*%0-$0-9
E)"$(%,0-+$("8))*B"&#("break
=),,+-.#"+/$(%3+%.#"3088"-)$"%&-:
?-85"1%(+6#")&%")/"+"#0-98("8))*B"#)"3088"-)$"#$)*"-(#$(."8))*#"0/")-85"
&#(.")-"0--(%"8))*
:
?-85"$)"4+-.8("&-(7*('$(."#0$&+$0)-#:
FFG/"*%)9"').(."3(88B"-)$"%(H&0%(."+$"+88:
E)"#60*"0$(%+$0)-B"&#("continue
=),,+-.#"+/$(%3+%.#"3)-I$"%&-:
Switch
J06("0/K#$+$(,(-$B"'4('6#"L">+%0+18("+9+0-#$".0//"'+#(#"M'+-"')-$+0-",&8$0*8("
>+8&(#N
O"1($$(%"%(+.+1080$5 0-"#),("'+#(#
K'+-I$"0-'8&.("%(8+$0)-+8")*(%+$)%# 806("P")%"<"/)%"'),*+%0#)-"+9+0-#$"
Q#30$'4Q"(7*%(##0)-
R+>("$)"&#("0/K#$+$(,(-$#"$)"$(#$"/)%"0-(H&+80$5S
K'+-")-85"')-$+0-".0#'%($( >+8&(#
K'+-I$ &#("break
;5-$+7
switch <variable>
case { val1 val2 val3 val4 }
<commands1>
case { val5 val6 val7 val8 }
<commands2>
otherwise
<commands3>
end
Find
!"%($&%-#"0-.0'(#")/"34(%("$4("')-.0$0)-"0#"$%&(
FF"/)%"/0-.0-9",+7T,0-">+8&(#")/"+",+$%07
;5-$+7
indices = find(<condition>)
E)"%($&%-"U")&$*&$#"M&#(/&8"34(-"+..%(##0-9"+",+$%07NV
[row_index, col_index] = find(<condition>)
W9S"/0-.0-9",+7">+8&("0-"(-$0%(",+$%07
Week$5:$Loops
;+$&%.+5B"LX"Y&9&#$"UZL[ L\VZX
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Document Summary

= structure to repeat commands for a specified number of times. Best when you know exactly how many times you want to loop through a section of code. end for counter = 1:2:11 fprintf("counter is %d\n",counter); end. Counter steps through each value inside the vector. Can be used for calcs or index for matrices. When number of iterations is unknown, but you have a condition you want to meet. end x = 1; iter = 0; while x^2 < 12345 while x^2 < 12345 iter = iter + 1 x = 8*x fprintf("iteration=%i,x=%i,x^2=%i\n",iter,x,x^2) end. Make sure your condition becomes false at some point, otherwise infinite lop created. Since commands are repeated as long as condition is true. Useful to store values in a matrix instead of printing. Only breaks our of a single loop, so will not stop nested loops if only used on inner loop. **if prog coded well, not required at all.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents