T2 topics coverage is cumulative, but with more emphasis on recent material: + 3/06 and earlier lectures and lecture sketches + T1 + P4 and earlier projects + E9 and earlier exercises + newsgroup posts topics *NOT* required on T2: + plotting + 3/08 and later lectures: + performance + big-oh notation + 2-dimensional arrays the list below is not necessarily exhaustive. if you have a question about whether a topic is part of the material covered by T2, please post to the newsgroup. =============================================================================== pre-defined functions + we will provide you a list of names of potentially useful functions + you should be familiar enough with them to recognize them by name + we may omit some functions we don't expect you to use because + they are too useful -- they make the question too easy + they are not useful -- waste of your time to think about them + they are too complicated + we didn't know about them + we will not necessarily provide you with the list of return variables and parameters of pre-defined functions + we will not necessarily provide you with descriptions/explanations of pre-defined functions + this is roughly a super-set of the list we will provide length and, or, xor, not, any, all nan, inf abs, max, min diff, sum, cumsum prod, cumprod zeros, ones, rand floor, ceil, round, fix [3/13] typo: $fix$ was originally $trunc$ sort, fliplr, flipud find isempty, isnan, isinf, isspace, isletter upper, lower findstr char, double, logical, struct ischar, islogical, isstruct conv, deconv, polyval + if you think there is a function that should be on the list above, please let us know. =============================================================================== terminology and definitions and concepts + simulations + (not on T2: birthday problem and solution -- darts and buckets) + trial + fair die + fixed point + motion in 1 time step $dt$ + acceleration = function of position and mass and other variables + velocity = velocity + acceleration * dt + position = position + velocity * dt + numbers + bounded, unbounded + negative, zero, positive, non-negative, non-zero, non-positive + sequences + leftmost, rightmost + averages: mode, median, mean + $n$-terminated input sequence + strictly ascending/increasing + strictly descending/decreasing + non-descending/non-decreasing + non-ascending/non-increasing + arithmetic sequence + subsequence: consecutive elements in the same order as original sequence + run + number theory + divisor, multiple + even, odd + 0 is not positive; 0 is even; 0 is a multiple of all integers + prime, composite; 1 is neither prime nor composite =============================================================================== style + $-notation: quote program elements using $-symbols, instead of quotes + meaningful variable names + named constants instead of magic numbers + major variables clearly defined in a comment + group of statements performing a task preceded by a *statement comment* above, not off to the side, with code indented underneath + loop invariant at same level as $while$ + function, loop, and conditional bodies are indented + a function has a comment clearly explaining what it does in terms of its parameters and return variables + do not use $break$ to terminate loops =============================================================================== program development and testing + use and memorize patterns/templates + run code on small examples + run actual code + trace by hand: trace *actual code does*, not what you think code is doing + include degenerate cases, aka boundary conditions + introspection: pay attention to the steps *you* use + decompose big problem into simpler problems: + place a comment for each simpler problem + place-holder to remind you tasks you still have to do + documentation to explain what the code does + use good style: explain to yourself and others what code is doing! + define variables + statement comments + loop invariants + error-checking + compare two versions for agreement + test that inverses undo each other =============================================================================== datatypes and values + $double$ + $char$ + $logical$ + $struct$ + $nan$ + $inf$ $input$ arithmetic operations + scalar versus elementwise on vectors + simple operators: $+$, $-$, $*$, $.*$, $/$, $./$, $rem$, $^$, $.^$ + simple functions: $abs$, $rem$ + precedence and associativity + finite machine precision + use something like $abs(x-y)=, $>$, $==$, $~=$ + and: $and$, $&$ + inclusive or: $or$, $|$ + exclusive or: $xor$ + not: $not$, $~$ + quantifiers: $any$, $all$ + DeMorgan's laws + use $sum$ to count + $logical$ + $ischar$, $islogical$, $isstruct$ + $isempty$, $isnan$, $isinf$, $isspace$, $isletter$ + logical array for indexing: as-is, $find$ + careful: in conditionals and $while$ loops + $nan$ is neither true nor false: runtime error! + use only scalar (single number) + empty and longer length logical arrays are unreliable/confusing =============================================================================== conditionals + conditional guards/tests/conditions, conditional bodies + $if$-$elseif$-$else$-syntax: fill in the blanks and boxes guard if _______________ <-- (logical scalar) +------------------------------------------------+ | | indent |-> | | <-- body | | (code) +------------------------------------------------+ guard elseif _______________ <-- (logical scalar) +------------------------------------------------+ | | indent |-> | | <-- body | | (code) +------------------------------------------------+ guard elseif _______________ <-- (logical scalar) +------------------------------------------------+ | | indent |-> | | <-- body | | (code) +------------------------------------------------+ else +------------------------------------------------+ | | indent |-> | | <-- body | | (code) +------------------------------------------------+ end + required: $if$ + optional: 0 or more $elseif$s + optional: 0 or 1 $else$ + required: $end$ =============================================================================== loops + loop variable, loop range, loop body, loop guard/test/condition + $for$-loop syntax -- fill in the blanks and box: loop loop range variable (vector) | | V V for ___ = _______________ +------------------------------------------------+ | | loop indent |-> | | <-- body | | (code) +------------------------------------------------+ end + $while$-loop syntax -- fill in the blank and box: loop invariant loop guard | (logical scalar) V | same | % __________________________________________________ | indent ->| | level | while _______________ <--+ +------------------------------------------------+ | | loop indent |-> | | <-- body | | (code) +------------------------------------------------+ end + patterns/templates for: + accumulation + processing an input sequence terminated by a stopping value + loop invariants and techniques for processing sequences + "maintain variable definitions above" + "processed" and "unprocessed" segments + "answer so far" + "(information about) previous value" =============================================================================== scripts and functions: named pieces of code *invoked*/*called* by name + script call: as if code were pasted in + function + *parametrized* piece of code + function call: see tracing + syntax for defining a function -- fill in the blanks and box: 0 or more return 0 or more variables, function parameters, separated by commas name separated by commas | | | V V V function [ ______________ ] = _________ ( ___________ ) comment % ____________________________________________________ <-- explaining what the +------------------------------------------------+ function does | | indent |-> | | <-- function body | | (code) +------------------------------------------------+ =============================================================================== tracing + tabular method + memory model, aka box scope diagrams + variable: a named box containing a value + value + $[]$: draw as $[]$ + scalar: + vector: sequentially numbered (implicit or explicit) values + struct: box with variables inside it + scope + big box containing variables where code is run + scopes can be nested + BIG enclosing scope contains all functions + command window scope: where code in command window runs + scope/visibility rules + look inside current + if not found, repeat at immediately enclosing + shadowing + script call: + do *not* create new scope + run code in *current* activation record + function call: + may be helpful to write code/note inside current activation record to help keep track of things, e.g. where to put return values + caller, callee + draw activation record + draw parameters + evaluate arguments + place arguments into parameters by sequential order + run function body inside activation record + copy out return values by sequential order + kill activation record -- note: when tracing by hand + cross out with clean line + do not erase or scribble out + resume execution at caller