MATLAB GLOSSARY (as of August 31) ----------------- MATLAB "Things": integers: 1, 2, 3 real numbers: 1.23, -0.004, 5.67e8, 9.12E-4 complex numbers: mathematically, "a+bi". logical variables: have the value true or false strings: 'a', 'Baby', 'Cat in a hat.' Special Names: eps the smallest number you can add to 1; pi Inf the result of computations like 1/0 NaN the result of computations like 0/0 realmax the largest real number MATLAB can handle realmin the smallest positive real number MATLAB can handle Arithmetic: A + 1 B - 2.3 C * D E / F G^2 Math functions: y = abs ( x ) y = acos ( x ) y = asin ( x ) y = atan ( x ) y = ceil ( x ) round a real number up to an integer y = cos ( x ) y = exp ( x ) y = factorial ( n ) 1*2*3*...*n y = floor ( x ) round a real number down to an integer y = gcd ( m, n ) Greatest common divisor; gcd(30,24) is 6. tf = isprime ( n ) true if integer n is a prime number. y = lcm ( m, n ) Least common multiple; lcm(6,20) is 60. y = log ( x ) z = max ( x, y ) z = min ( x, y ) r = mod ( x, y ) remainder from division x/y mod(32,5) is 2 y = rand ( ) return a random number between 0 and 1. y = round ( x ) round a real number to the nearest integer y = sin ( x ) y = sqrt ( x ) y = tan ( x ) Assignment statements: sqrt(x) computes the value, stores it as "ans", displays it. y = sqrt(x) computes the value, stores it as "y", displays it. y = sqrt(x); computes the value, stores it as "y". Logical operators: x < y x <= y x > y x >= y x == y x is equal to y x ~= y x is not equal to y x < y && y < z x is less than y AND y is less than z x < y || y < z x is less than y OR y is less than z ~ ( x == 0 && y == 0 ) it's NOT the case that both x and y are zero. Logical control: if ( x < y ) fprintf ( ' X is smaller than Y!\n' ); end if ( x <= y && y <= z ) disp ( ' Y is between X and Z.' ) end if ( 0 <= x ) y = sqrt ( x ); else y = sqrt ( -x ); end if ( 0 <= x ) pos = pos + 1; elseif ( x == 0 ) zero = zero + 1; else neg = neg + 1; end Printing: x displays x (unformatted) x; no display y = x + 1 sets y, and displays y (unformatted) y = x + 1; sets y, no display fprintf ( ' The value of x is %f', x ); Prints fprintf ( ' The value of x is %f\n', x ); Prints, then starts new line. format long 16 digit real printout format short 6 digits real printout disp ( 'Can''t divide by zero!' ) Displays a string. fprintf ( 'Can''t divide by zero!\n' ); Also displays a string. disp ( '' ) Prints a blank line. fprintf ( '\n' ); Prints a blank line. Formats used in FPRINTF: %f print a real number with "fixed point" format. %10f print a real number, using 10 spaces %7.2f print a real number, using 7 spaces, with 2 decimal places %e print a real number with "exponential" format. %g print a real number with "general" format (fixed or exponential). %d print an integer; if real, only print integer part. %10d print an integer using 10 spaces Miscellaneous: x = input ( 'Enter a value for x:' ) asks user to input value (for scripts) error ( 'Message' ) print message, terminate script. clear clears MATLAB's memory; all variable values are lost. clc clears the command window. % used to begin a comment help sin brief help on "sin" function doc sin extensive help on "sin" function ... continue this text on a new line exit exits MATLAB completely. Ctrl-C force MATLAB to stop the current computation. pwd what is the full name of MATLAB's current directory? cd .. move MATLAB's current directory up one level cd dirname move MATLAB's current directory to "dirname" ls list the files in the current directory dir list the files in the current directory type filename type the contents of the file "filename" Parentheses: A + B * C ---------- must be written ( a + b * c ) / ( d + e ) D + E F + G ----- must be written ( f + g ) / ( 2 * h ) 2 H 2 1 - ( x - y ) - e must be written ( 1 / 2 ) * exp ( - ( ( x - y )^2 ) ) 2 2 sin pi x must be written ( sin ( pi * x ) ) ^ 2