\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{Ishan324} \pdfinfo{ /Title (cmpsc-200-exam-2.pdf) /Creator (Cheatography) /Author (Ishan324) /Subject (CMPSC 200 Exam 2 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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 2 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Ishan324} via \textcolor{DarkBackground}{\uline{cheatography.com/20950/cs/3806/}}} \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}Ishan324 \\ \uline{cheatography.com/ishan324} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 1st April, 2015.\\ Updated 12th 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}{Three Categories of Code}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Sequences}} - lines of code executed one after another \newline % Row Count 2 (+ 2) {\bf{Selection Structures}} - executes some piece of code if some known condition is true, otherwise executes some alternative. \newline % Row Count 5 (+ 3) {\bf{Repetition Structures}} - (loops) causes a group of statements to be executed multiple times.% Row Count 7 (+ 2) } \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 and Continue}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Break}} statements cause the termination of the smallest enclosing while or for loop. \newline % Row Count 2 (+ 2) {\bf{Continue}} statements skip to the rest of loop, advancing to the next loop pass.% Row Count 4 (+ 2) } \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}{Time}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{clock}} gives you the current time \newline % Row Count 1 (+ 1) {\bf{etime}} compares between a start and end time \newline % Row Count 2 (+ 1) {\bf{cputime}} returns cpu time since you started matlab \newline % Row Count 4 (+ 2) {\bf{tic/toc}} works like a stopwatch% Row Count 5 (+ 1) } \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}{Array vs Matrices}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Array}} holds stuff: can hold numeric info, char data, or symbolic data. Is "an orderly grouping of information". No special properties by virtue of its existence. \newline % Row Count 4 (+ 4) {\bf{Matrix}} is a 2D numeric array used in linear algebra. Used extensively in STEM fields and has special properties.% Row Count 7 (+ 3) } \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}{To solve Ax = b}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Inverse method}} solution = inv(A)*b \newline % Row Count 1 (+ 1) {\bf{rref command}} A\_augmented = {[}A b{]} \newline % Row Count 2 (+ 1) RREF\_result = rref(A\_augmented); \newline % Row Count 3 (+ 1) solution = RREF\_result(:,end) \newline % Row Count 4 (+ 1) {\bf{backslash}} solution = A\textbackslash{}b% Row Count 5 (+ 1) } \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}{Structure Arrays}} \tn \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\{3\} \{\{fa-arrow-right\}\} displays 'Penn State' \newline E\{1\}(1,2) \%1st row, 2nd col of cell 1 w/ multilayer indexing \{\{fa-arrow-right\}\} displays e \newline E\{2\}(:) \%concatenates cell 2 into column vector \newline \newline N.first = 'Hello'; \newline N.second = 'World'; \newline disp('N is: ') \newline disp(N) \{\{fa-arrow-right\}\} N is: first:'Hello'; second:'World' \newline \newline orderfields(N) \%orders fields in ASCII dictionary \newline orderfields(N,O) \%orders N field like O is ordered \newline \newline T = 'myphrase1'; \newline L = rmfield(L,T) \% removes 'myphrase1' field from L} \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}{Short Answer}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{41. {\bf{What is the difference between a matrix and 2D array?}} \newline % Row Count 2 (+ 2) A matrix is 2D, has special mathematical properties. An array need not be 2D, \newline % Row Count 4 (+ 2) and has no special mathematical properties, and is merely a "holder" for data. \newline % Row Count 6 (+ 2) 42. {\bf{Why is it a good idea to create a flowchart and pseudocode before you attempt to create a computer program?}} \newline % Row Count 9 (+ 3) Creating a flowchart and pseduocode before attempting to create a computer \newline % Row Count 11 (+ 2) program is a good idea because it gives you an opportunity to think your way \newline % Row Count 13 (+ 2) through the program. A builder wouldn't start building a house without a \newline % Row Count 15 (+ 2) blueprint; it is advisable to think through your programs as well. \newline % Row Count 17 (+ 2) 43. {\bf{Briefly describe how one would mathematically check if a square matrix is singular. What practical implementation issues arise when implementing that into MATLAB code?}} \newline % Row Count 21 (+ 4) Mathematically, a matrix is invertible if detA \textasciitilde{}= 0. In terms of \newline % Row Count 23 (+ 2) implementation, if the determinate is ≈ 0 it can be viewed as effectively singular. \newline % Row Count 25 (+ 2) You could check the determinant against some sort of tolerance to see if your \newline % Row Count 27 (+ 2) determinant is close enough to 0 to make your matrix numerically act as singular.% Row Count 29 (+ 2) } \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}{3D array whose values count down}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{nrows = 3; \newline ncols = 2; \newline npages = 4; \newline B = zeros(nrows,ncols,npages); \newline counter = 25; \newline \newline for k = 1:npages; \newline for i = 1:nrows; \newline for j = 1:ncols; \newline counter = counter - 1; \newline B(i,j,k) = counter; \newline end \newline end \newline end \newline \newline fprintf('The first page of B is:\textbackslash{}n') \newline disp(B(:,:,1)) \newline etc} \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}{Short Answer}} \tn \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{44. {\bf{What is the benefit of using cell arrays to store chars instead of using character arrays?}} \newline % Row Count 2 (+ 2) Character arrays have to have the same number of columns in each row. Cell \newline % Row Count 4 (+ 2) arrays of chars, however, has no such restriction. \newline % Row Count 6 (+ 2) 45. {\bf{Briefly discuss the difference between cell arrays and structure arrays in MATLAB.}} \newline % Row Count 8 (+ 2) One of the more prominent differences between cell arrays and structure arrays in \newline % Row Count 10 (+ 2) MATLAB is content indexing for cells, and the use of fields for structure arrays.% Row Count 12 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}