------------------------------------------------------------------------------- Statements + instructions to MATLAB + end statements by hitting Return or Enter + may also use a semicolon to end and suppress output + sometimes a comma (,) separates statements + MATLAB works top-down, left-right (1) empty + MATLAB automatically succeeds + shows up now and then ; (2) expression + MATLAB evaluates all operations + MATLAB reports result as output + result automatically stored in variable $ans$ if you do not specify something else + operator precedence and associativity like Java + can suppress output with semicolon (;) 1+1 1/2; (3) declaration + in other languages, need to tell MATLAB about the data types + MATLAB is weakly typed! + everything is an array (4) assignment + want to reuse values + store results of expressions in variables + syntax: $var=value$ + think in terms of "variable gets value" or pseudocode: variable<-value + to see a variable's value, enter variable at the prompt + cannot use a variable until it's assigned + variables assigned in the command window are GLOBAL (known until you reassign or clear) clear % removes all assignments x % causes an error because x is not assigned yet y+1 % same problem: y isn't assigned yet! x = 1 % x gets the value 1 x+2 % MATLAB knows that x means 1, so x+1 produces 3 clear x % remove the value in x x % uh oh: cannot use x now because value is removed (5) function call + exectute a programmed procedure + either builtin or defined by user sqrt(4) rand + some functions generate values + replace the function's value in the expression x = 1 + sqrt(4) % produces 3 -------------------------------------------------------------------------------