\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{xsgirl99} \pdfinfo{ /Title (cmpsc-200-exam-ii.pdf) /Creator (Cheatography) /Author (xsgirl99) /Subject (CMPSC 200 Exam II Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{BABABA} \definecolor{LightBackground}{HTML}{F6F6F6} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{CMPSC 200 Exam II Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{xsgirl99} via \textcolor{DarkBackground}{\uline{cheatography.com/26903/cs/7655/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}xsgirl99 \\ \uline{cheatography.com/xsgirl99} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 28th March, 2016.\\ Updated 13th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{3 Code Categories}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Sequences}} – lines of code are executed one after another.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{›Selection Structures}} – executes some piece of code if some known condition is true, otherwise executes some sort of alternative code. ›} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Repetition Structures (loops)}} – causes a group of statements to be executed multiple times (either a fixed number, or until some stated condition is met).} \tn % Row Count 9 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Relational Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`\textless{}` less than} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`\textless{}=` Less than or equal to} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`\textgreater{}` greater than} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`\textgreater{}=` greater than or equal to} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`==` equality check} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`\textasciitilde{}=` not equal to} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Logical Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`\&` and (used with vectors)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`|` or (used with vectors)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`\&\&` short cut and (used with scalars)} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`xor` exclusive or} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`\textasciitilde{}` not (used with vectors or scalars)} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`||` short cut or (used with scalars)} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Remember 0 is false, 1 is true} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Also called short circuit evaluation. Makes sure you don't evaluate additional terms if you don't need to do so.} \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Definitions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Pseudocode}}- ›Verbal description of code. ›Often is language independent. ›Intermediate step between everyday language and a programming language.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Flowchart}}- Exactly what it sounds like – a graphical representation of how code flows or progresses.} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Counter}}- A variable that keeps track of some parameter of interest} \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Array}}- ›Holds "stuff". It can hold numeric information, character data, symbolic data, etc. ›Is "an orderly grouping of information", ›has no special properties by virtue of its existence.} \tn % Row Count 14 (+ 5) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Matrix}}-A 2D numeric array used in linear algebra. Is used extensively in STEM fields. ›Has special mathematical properties!} \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Code Vectorization}}- A programming technique that uses vector operations instead of element by element loop-bases operations.} \tn % Row Count 20 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Sentinel Loop}}- A loop that terminates only when a specific condition(the sentinel condition) is met} \tn % Row Count 23 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Find Command}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{The command `find` searches a matrix, finding what elements meet the search criteria.› The command returns the index/indices of the valid results.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`index = find(x)`} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`index = find(x,k)` (first k elements)} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`index = find(x,k,'last')` (last k elements)} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{`if` Selection Structure}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`if comparison`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`{[}commands to do something{]}`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`end` ›} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{The simplest "classical" selection structure is the `if` statement. ›} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{If the comparison evaluates to be true, then the "do something" statements are executed. › If the comparison evaluates to be false, then the "do something" statements are ignored.} \tn % Row Count 9 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Matrix Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Raising a matrix to a power can be thought of as multiplying the matrix by itself however many times in the exponent ›} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Matrix must be square. ›Example: `A\textasciicircum{}4\textasciicircum{}= (A)(A)(A)(A)` ›} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Syntax: A\textasciicircum{}\textasciicircum{}\textasciicircum{}n (requires A to be square; compare against the element-by-element operation `A.\textasciicircum{}n`, where A doesn't have to be square )} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Matrix inverse: `(A)(A\textasciicircum{}-1\textasciicircum{})=1` (identity matrix)} \tn % Row Count 9 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{A matrix inverse does not exist if the determinant of the matrix is equal to 0; a matrix like this is known as a singular matrix} \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{If a matrix is {\bf{square}} and {\bf{singular}}, the operation M\textasciicircum{}-1\textasciicircum{}M would be hard to know {\emph{a priori}} but the result will be wrong.} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Bits \& Bytes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{The basic unit of information in computers is the bit("binary digit"). ›Can store exactly 1 logical variable} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Bits can only have one of two values: 0 or 1} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{There are 8 bits/byte ›} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Power of 2: allows values between 0 and 255 for 1 byte} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Solving Matricies}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{A = {[}a matrix{]} A's \#of rows=b's \#of columns \newline b = {[}another matrix{]} \newline solution = inv(A)*b \newline \newline A\_augmented = {[}A b{]} \newline RREF\_result = rref(A\_augmented); \newline solution = RREF\_result(:,end) \newline \newline solution = A\textbackslash{}b (ideal way)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{\seqsplit{Interpolation/Extrapolation}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Interpolation consists of "method{[}s{]} of constructing new data points within the range of a discrete set of known data points"} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{› Extrapolation consists of "the process of estimating, beyond the original observation range, the value of a variable on the basis of its relationship with another variable"} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Curve fitting is "the process of constructing a curve, or mathematical function, that has the best fit to a series of data points, possibly subject to constraints." Goal is to minimize the residuals: the difference between the actual and predicted values at a given point} \tn % Row Count 13 (+ 6) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`yi = interp1(x,Y,xi)`. Interpolates to find `yi`, the interpolated function values at the points in the vector or array `xi`. `x` contains your known data points (functions values are `Y`), which must be a vector, though xi can be a scalar, vector, or multidimensional array. `yi` will always be the same size as `xi`} \tn % Row Count 20 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`yi = interp1(Y,xi)`. Same as above, except the function will assume that `x = 1:N`, where N is `length(Y)` (for a vector) or `size(Y,1)` (for a matrix)} \tn % Row Count 24 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`yi = interp1(x,Y,xi,method)`. Same as above, except now using a method(ie cubic spline)} \tn % Row Count 26 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`yi = interp1(x,Y,xi,method,'extrap')`. Same as above, except used to extrapolate beyond the data set} \tn % Row Count 29 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Flowcharts \& Meaning}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Circle/Oval - Indicates the beginning or end of a section of code} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Parallelogram - Indicates input or output processes} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Diamond - Indicates a decision point} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Rectangle/Square - Indicates calculations} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{`if/else/elseif`}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`if comparison \% do something` ›} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`elseif comparison \% do something else`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`else \% do something else end`} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{If the first statement (the if statement) does not evaluate to true, it checks the elseif statement(s) › If nothing is true by the time one gets to else, the else commands are executed} \tn % Row Count 7 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{There can only be one `if`, there must be an `end`, and there can be no more than 1 `else`.} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{You can have an `else` without an `elseif`, and an `elseif` without an `else`. However, both `else` and `elseif` are dependent on having an `if`.} \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Switches}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Switches have a similar purpose to `if` statements.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{›Anything you can do with a switch can be done using `if/elseif/else`.} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Often personal preference, though you will often see switches when checking strings.} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Important}}: In MATLAB, once a "true" case has been found MATLAB will NOT check the other cases – make sure you plan accordingly.} \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Switch Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{location = 'lion shrine'; \newline switch location \newline case 'lion shrine' \newline disp('I''m at the lion shrine') \newline otherwise \newline disp('I''m lost') \newline end \newline Output: \newline I'm at the lion shrine} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Menus}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Instead of requesting input from the Command Window, you can have MATLAB collect input from a menu box. ›} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Syntax: `var = menu('title','option 1','option 2','...')`} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Use in conjunction with Switches.} \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`x=menu('S','x','y'...) if S==1-\textgreater{}fprintfx elseif S==2-\textgreater{}fprintfy`} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{`numel` vs `find`}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`numel` counts the number of elements. `find` only returns the indices where the element that meets that criteria is located, so we count the number of elements.} \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Matrix Terminology}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Zero matrix: matrix of zeros ›} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Identity matrix: a matrix of zeros, except it has 1's along the main diagonal} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{›Sparse Matrix: most of the elements of the matrix have zero elements} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Dense Matrix: most of the elements of the matrix have non-zero elements} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Banded Matrix: non-zero elements are confined to a diagonal band comprising the main diagonal and zeros or more diagonals on either size ›} \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Bidiagonal matrix: zero matrix except: for non- zero entries along the main diagonal and either the diagonal above or below the main diagonal ›} \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Tridigonal matrix: zero matrix except: for non-zero entries along the main diagonal and on the first diagonal above and below the main diagonal} \tn % Row Count 16 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Cell Arrays}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Unlike numeric, character or symbolic arrays, cell arrays can store different data types within the same array. Each element of the array is an array.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Syntax: `mycell = \{A, B, C, ...\}` (the curly braces are cell array constructors)} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`reshape` command reshapes the array › Syntax: `reshape(A, r,c ...)`,` reshape(A,r,{[}{]})`} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`horzcat`command concatenates horizontally (left-right) › Syntax: `horzcat(A1, A2, ... )`} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`vertcat` command concatenates vertically (up-down) › Syntax: `vertcat(A1, A2, A3, ...)`} \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{A = 'We are!' \newline B = {[}1 4; 3 2{]} \newline C = 'Penn State!' \newline D = single({[}1 2; 3 4{]}) \newline E = \{A,B,C,D\} \% default printing just shows sizes \newline celldisp(E) \% needed to generate display \newline \newline E\{end\}={[} {]} \%will delete the last cell of the cell array E} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Character Arrays}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Character arrays are arrays of characters ›} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Key idea: The number of elements in each row has to be the same, or MATLAB will throw a warning. › ›} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`char` will also accept as input the ASCII representation of a number, letter or symbol.} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Curve Fitting}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`y = polyval(p,x)`. Returns the value of the polynomial y of degree n evaluated at x. The input argument p is a vector of length n + 1 whose elements are the coefficients in descending powers of the polynomial y. This function accepts matrix or vector x.} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`p = polyfit(x,y,n)`. This finds the coefficients of the polynomial p(x) of degree n that fits the data. p is a row vector of length n + 1 that contains the coefficients of the polynomial} \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`{[}p,\textasciitilde{},mu{]} = polyfit(x,y,n)`. Same as above except that it also returns mu, a two element vector mu={[}u1, u2{]} where u1=mean(x) and u2=std(x)} \tn % Row Count 13 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`x = fzero(fun,x0)`. `fzero` tries to find a zero of the function fun near x0 if x0 is scalar} \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Miltivariate Interpolation}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Accomplished using the commands `interp2` (for 2D data) or `interp3` (for 3D data)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`ZI = interp2(X,Y,Z,XI,YI)`. ZI is a matrix containing elements corresponding to the elements of XI and YI, as determined by interpolation within the 2D function specified by the matrices X, Y and Z. X and Y must be monotonic and have the same format ("plaid") as if they were produced by meshgrid. Matrices X and Y specify the points at which the data Z is given. Out of range values are returned as `NaNs`} \tn % Row Count 11 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Loops}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Loops should not be your first choice›. Low performance (bad "clock times") ›} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Alternatives: ›Array operations, `›find` command, ›Code vectorization} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{1. `for` loop - Primarily used if you know {\emph{a priori}}(Before the fact) how many times the loop will need to run (or can calculate it)} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{2. `while` loop - A pre-test loop: it checks the condition before completing the iteration.The first time MATLAB sees the while loop, it checks to see if it should go into the while loop. ›If the condition is false, MATLAB will never go into the while loop. If the condition is true, MATLAB proceeds into the `while` loop.} \tn % Row Count 14 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{3. `do while loop` – unavailable in MATLAB. Guarantees one pass through the loop.} \tn % Row Count 16 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Every `for` loop can be made into a `while` loop, but not every `while` loop can be made into a `for` loop.} \tn % Row Count 19 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Valid `for` loop indexes include scalars, vectors, and matrices.} \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{For Loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{for some\_index\_variable = some\_matrix \newline some commands to be executed \newline end \newline Input: for k = {[}1 3 5 7{]} \newline k \newline end \newline Output: k=1 k=3 k=5 k=7} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Break \& Continue Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Can use a break statement to cause the termination of the smallest enclosing `for` or `while` loop} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Often considered bad form to use break without a good reason. It is much better to write "better" loop termination conditions.} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Can use a `continue` statement to skip the rest of the loop, advancing to the next loop pass.} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{They should not be "go- to" techniques.} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Timing Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`clock/etime` performs comparison between a start time and an end time} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`cputime` returns CPU time (in seconds) since you started MATLAB; can use differences to do timing} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`tic/toc` can be used as stopwatches; the time difference is in seconds (best way)} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Issues with trying to time runs: Run times can vary from run to run depending on available RAM. Also, the OS can make adjustments to the system clock, using it for timing purposes can cause errors.} \tn % Row Count 10 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Transpose Command}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Swaps rows/columns: `A(i,j)` becomes `A(j,i)`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Command (2 versions): `transpose(x)` or `x'`} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Dot Product}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`sum(A.*B)` (syntactically valid) ›} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`dot(A,B)` (preferred and easier to implement)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{In general, `A{\emph{B ≠ B}}A`} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Dot Product Example}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`A={[}a\textasciicircum{}11\textasciicircum{} a\textasciicircum{}12\textasciicircum{}; a\textasciicircum{}21\textasciicircum{} a\textasciicircum{}22\textasciicircum{}{]}`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`B={[}b\textasciicircum{}11\textasciicircum{} b\textasciicircum{}12\textasciicircum{}; b\textasciicircum{}21\textasciicircum{} b\textasciicircum{}22\textasciicircum{}{]}`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`A*B={[}(a\textasciicircum{}11\textasciicircum{}b\textasciicircum{}11\textasciicircum{} +a\textasciicircum{}12\textasciicircum{}b\textasciicircum{}21\textasciicircum{}),(a\textasciicircum{}11\textasciicircum{}b\textasciicircum{}12\textasciicircum{} +a\textasciicircum{}12\textasciicircum{}b\textasciicircum{}22\textasciicircum{});... (a\textasciicircum{}21\textasciicircum{}b\textasciicircum{}11\textasciicircum{} +a\textasciicircum{}22\textasciicircum{}b\textasciicircum{}21\textasciicircum{}), (a\textasciicircum{}21\textasciicircum{}b\textasciicircum{}12\textasciicircum{} +a\textasciicircum{}22\textasciicircum{}b\textasciicircum{}22\textasciicircum{})`} \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Cross Product}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Result is a vector, always at a right angle (normal, orthogonal) to the plane defined by the two input vectors. Mathematically is a special case of a determinant whose first row comprises unit vectors. ›Must contain three elements} \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Numeric Data Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Double-Precision Floating-Point Numbers (doubles)}}- ›MATLAB stores numeric data as doubles. Each value requires 8 bytes of space(64 bits). ›} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Single-Precision Floating-Point Numbers (singles)}}- Uses half the storage space of a double, implies that they have half the storage. Each value requires 4 bytes of space(32 bits). ›} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Complex Numbers}}- Can be doubles, singles, or integers. Requires twice the space of the base data types because one needs space for both the real-valued and complex- valued components.} \tn % Row Count 11 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Dingle\textless{}complex \# of singles=double} \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Structure Arrays}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Similar idea to cell arrays. Instead of using content indexing, however, each matrix is stored is assigned a location called a field (each field can be thought of like a property).} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Field names are stored in order of their creation.} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`L.myphrase1 = 'We are!' \newline L.nums = {[}1 4; 3 2{]} \newline L.myphrase2 = 'Penn State!'` \newline L= We Are! {[}2x2{]} Penn State!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Numerical Integration}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`q=quad(function,a,b)`. Takes a function between limits a and b and numerical integrates it to within a default error of 1e-6 using a recursive adaptive Simpson quadrature} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`q=quad(function,a,b,tol)`. Same as above, except you can specify the accuracy needed with `tol`.} \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`{[}q,NFE{]}=quad(...)`. Same choices available as above, except it also returns the number of function evaluations} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`Z = trapz(Y)`. Y is the vector representing the function whose integral you want to approximate.} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`Z = trapz(X,Y)`. Same as above, except that the integration will be done with respect a variable `X`} \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`cumtrapz` operates virtually the same as `trapz`, except that it will return the cumulative sums} \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Differential Equations}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{When specifying a derivative, use the symbol D (`Dy`). n\textasciicircum{}th\textasciicircum{} order derivative: specify n after the symbol D (4th order derivative for y: `D4y`)} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`dsolve(equation)` will result in the family of solutions to the DE with respect to the default variable} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`dsolve(equation,symvar)` will result in the family of solutions to the DE with respect to the symbolic variable `symvar`} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`dsolve(equation,condition1,condition2, …, conditionN, symvar)` will result in the family of solutions to the DE equation using the initial or boundary conditions `condition1, condition2, … conditionN` (conditions are written as equations), with respect to the `symvar` (if you just want the default, `t`, then omit the `symvar`)} \tn % Row Count 16 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`dsolve(equation1,equation2, … equationN, condition1, condition2, … conditionN, symvar)` will result in the family of solutions to the DEs `equation1, equation2, …, equationN` using initial or boundary conditions `condition1, condition2, … , conditionN` with respect to the symbolic variable} \tn % Row Count 22 (+ 6) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`ode45` solves ordinary differential equations} \tn % Row Count 23 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Short Response(Practice Exam)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{If the availability of memory is a concern, using the smallest necessary storage type is advantageous, enabling you to store more things in memory. An example discussed in class related to "classic" video games vs. modern phone apps (where it seems that apps and downloads are getting bigger(50 MB+) everyday.} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{A matrix is always 2D and has special mathematical properties. An array need not be 2D, has no special mathematical properties, and is merely a "holder" for data.} \tn % Row Count 11 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Character arrays must have the same number of rows in every column, and the same number of columns in every row. Cell arrays of `chars`, however, have no such restriction.} \tn % Row Count 15 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`elseif` is a case inside of an `if` selection structure; `else if` is a nested `if` selection structure inside of an `else` case of another `if` selection structure. MATLAB generally ignores white space, so `else if` is the same thing to the interpreter as the programmer had properly indented the code.} \tn % Row Count 22 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Creating a flowchart and pseduocode before attempting to create a computer program is a good idea because it gives you an opportunity to think your way through the program. A builder wouldn't start building a house without a blueprint; it is advisable to think through your programs as well.} \tn % Row Count 28 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{True/False(Practice Exam)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{In general, for performance reasons it is preferable to use built-in MATLAB features such as the `find` command instead of using MATLAB loops.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{If MATLAB finds a true case in a switch, it will {\bf{NOT}} continue checking the other cases.} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{An exclusive or(`xor`) evaluates as TRUE when either A or B (but not both) are non-zero.} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{The ' operator and the transpose command both compute transposes, but these two techniques do not behave identically under all circumstances.} \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{For personal computers (PCs) or laptops, chars in MATLAB are represented by their ASCII value when stored in memory.} \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{In MATLAB, what would be result of this expression: `FALSE || (TRUE \&\& FALSE)` Answer: False} \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{. The default numeric data type in MATLAB is the double.} \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Matrix multiplication is {\bf{NOT}} commutative for any square matrix.} \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{A matrix A is invertible if its determinant is not equal to {\bf{0}}.} \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Long Response Hints}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`det(A)` takes the determinant of matrix A.} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{See Linear Algebra Section}}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`if rem(k,2)==0` Checks to see if k is divisible by 2(even)} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Exam 1 Material}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`logspace(start,end,interval)` Allocates numbers from start to end in evenly logarithmically spaced intervals.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`linspace(start,end,interval)` Allocates numbers from start to end in evenly linearly spaced intervals.} \tn % Row Count 6 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Potentially Useful Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{num\_rows = 3; \newline num\_cols = 4; \newline num\_pages = 2; \newline value = 46; \newline A = zeros(num\_rows, num\_cols, num\_pages); \% Optional \newline for k = 1:num\_pages \% loop over \# of pages \newline for i = 1:num\_rows \% loop over \# of rows \newline for j = 1:num\_cols \% loop over \# of cols \newline A(i,j,k) = value; \newline value = value - 2; \newline end \% cols \newline end \% rows \newline end \% pages \newline disp(A)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{More Potentially Useful Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{grades = load('P50.csv'); \newline A\_find = numel(find(grades\textgreater{}=90)); \newline B\_find = numel(find(grades \textgreater{}= 80 \& grades \textless{} 90)); \newline C\_find = numel(find(grades \textgreater{}= 70 \& grades \textless{} 80)); \newline failing\_find = numel(find(grades \textless{} 70)); \newline {[}num\_rows, \textasciitilde{}{]} = size(grades); \newline count = 0; \newline A\_loop = 0; B\_loop = 0; C\_loop = 0; failing\_loop = 0; \newline while count \textless{} num\_rows \newline count = count + 1; \newline if grades(count) \textgreater{}= 90 \newline A\_loop = A\_loop + 1; \newline elseif grades(count) \textgreater{}= 80 \newline B\_loop = B\_loop + 1; \newline elseif grades(count) \textgreater{}= 70 \newline C\_loop = C\_loop + 1; \newline else \newline failing\_loop = failing\_loop + 1; \newline end \newline end \newline fprintf('\%i A''s\textbackslash{}n', A\_find) \newline fprintf('\%i B''s\textbackslash{}n', B\_find) \newline fprintf('\%i C''s\textbackslash{}n', C\_find) \newline fprintf('\%i D''s\textbackslash{}n', failing\_find)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Integration}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`int(f)` calculates the symbolic single integral of a symbolic function {\emph{F}} with respect to the default independent variable} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`int(f,symvar)` calculates the symbolic single integral of the symbolic function {\emph{F}} with respect to the symbolic variable symvar} \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`int(f,a,b)` evaluates the results of the integral over the symbolic or numeric range {[}a, b{]} of the independent variable} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`int(f,symvar,a,b)` calculates the symbolic single integral of a symbolic function {\emph{F}} with respect to the symbolic variable symvar; evaluates the results of the integral over the symbolic or numeric range {[}a, b{]} of the independent variable} \tn % Row Count 14 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{symvar has to be in single quotes if the variable does not already exist as a symbolic variable(same for differentials)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Differentials}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`diff(f)` calculates the symbolic first derivative of a symbolic function {\emph{F}} with respect to the default independent variable} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`diff(f,symvar)` calculates the symbolic first derivative of a symbolic function {\emph{F}} with respect to the symbolic variable symvar (symvar has to be in single quotes if the variable does not already exist as a symbolic variable)} \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`diff(f,n)` calculates the symbolic n\textasciicircum{}th\textasciicircum{} derivative of the symbolic function {\emph{F}} with respect to the default independent variable} \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`diff(f,symvar,n)` or `diff(f,n,symvar)` calculates the symbolic n\textasciicircum{}th\textasciicircum{} derivative of the symbolic function {\emph{F}} with respect to the symvar} \tn % Row Count 14 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Advanced Graphics}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`pcolor` command creates a pseudocolor checkerboard plot} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{MATLAB generally recognizes three different techniques for storing and representing images: ›1. Intensity Images ("gray scale") ›2. Indexed Images ›3. RGB ("true color") images} \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{intensity image can be created with the `imagesc` command} \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Can adjust the colormap of an image with the `colormap()` command} \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Can check image properties with the `imfinfo('image.jpg')` command} \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Can read in image data using `imread` and `imagesc`. ›Code: `X = imread('lighthouse.jpg') imagesc(X)`} \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`imwrite(arrayname, colormap, \seqsplit{'filename.format')`manually} saves an image. Four possible fields: ›`arrayname`: name of the MATLAB array in which the data is stored. `colormap`: the name of your colormap, if applicable. `filename`: the name you want to use to store the data›. `format` is the file extension} \tn % Row Count 22 (+ 7) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`set(h,'PropertyName',PropertyValue,...)` where `h=plot(x,y)`} \tn % Row Count 24 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{`drawnow` causes figure windows and their children to update, and flushes the system event queue} \tn % Row Count 26 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`h = animatedline()` creates an animated line without data, adding it to the current axis. Can use a loop to later add data points. Can also use the `addpoints` command.} \tn % Row Count 30 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}