CMPSC 200 Summarized Notes- Midterm

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/100

encourage image

There's no tags or description

Looks like no tags are added yet.

101 Terms

1
New cards

Computer

A programmable electronic device that can store, retrieve, and process data

2
New cards

MATLAB Stands for

Matrix Laboratory

3
New cards

Syntax error

Output when the computer does not understand the instruction

4
New cards

Logic error

Program input by the user is read properly by the computer but is not the intended output desired

5
New cards

CPU

Central processing unit

6
New cards

Arithmetic and Logic Unit (ALU)

Performs mathematical functions

7
New cards

Control Unit

Fetches the next instruction, decodes the instruction, and then executes the instruction as appropriate

8
New cards

Volatile memory

Temporary storage that is faster; examples include RAM and DRAM

9
New cards

Non-Volatile Memory

Permanent storage that is slower; examples include read-only memory (ROM), compact discs (CDs), and magnetic tape

10
New cards

Operating System (OS)

Software that allocates computer resources and allows communication between the user and the computer

11
New cards

Programming Language

A structured language that exists to communicate information to a computer in the form of a program

12
New cards

High-Level Languages

Easy for humans to understand, but too difficult for a computer to understand directly (e.g., C = A + B)

13
New cards

Low-Level Languages

Harder for humans to understand, but easier for a computer to convert to usable instructions (e.g., ADD A B C)

14
New cards

Machine Language

Binary digits (0s and 1s) containing instructions understood directly by the computer

15
New cards

Compiled Language

Code is reduced to machine-specific instructions prior to runtime and saved as an executable file; generally runs faster

16
New cards

Interpreted Language

Code written by the programmer is saved in the same format as it was originally written in, which is converted to machine-specific instructions at runtime. (e.g., MATLAB, Python)

17
New cards

Variable

Container for some information; must begin with a letter and can contain up to 63 characters

18
New cards

Assignment rule in MATLAB

Whatever happens on the right-hand side is stored into the variable on the left-hand side of the equals sign

19
New cards

Case sensitivity in MATLAB

MATLAB is case-sensitive, meaning uppercase and lowercase letters matter

20
New cards

clc

Clears the command window where outputs are displayed

21
New cards

clear

Clears the workspace and removes variables

22
New cards

Comments in MATLAB

Started with the % symbol and appear green; block comments use %{ and %}

23
New cards

Section break (Cell)

Created using %% to allow sections of code to be run independently

24
New cards

Order of operations

Parentheses, Exponents, Multiplication and Division, Addition and Subtraction

25
New cards

Element-by-element operation

Performed using a dot operator (e.g., .*) to multiply corresponding elements of matrices

26
New cards

Default values in MATLAB

pi, i, and j

27
New cards

Creating matrices/arrays

Rows are separated by semicolons (;) and columns are separated by spaces or commas (,)

28
New cards

Colon operator (1:5)

Stores values from a lower bound to an upper bound in steps of one (lower:step:upper)

29
New cards

abs()

Finds the absolute value of data or each item in an array

30
New cards

sqrt()

Calculates the square root for real and imaginary numbers

31
New cards

sign()

Finds if a number is positive, negative, or zero, displaying -1, 0, or 1

32
New cards

rem()

Finds the remainder of a division operation

33
New cards

log vs log10

log is the natural logarithm, while log10 is log base 10

34
New cards

Floor and Ceiling

floor rounds down and ceiling rounds up to the nearest integer

35
New cards

factor()

Lists the factors of a number

36
New cards

gcd() & lcm()

Finds the greatest common divisor and least common multiple of numbers

37
New cards

isprime()

Determines if a number is prime (returns 1 for true, 0 for false)

38
New cards

rats()

Converts the input to a fraction format

39
New cards

linspace(n,m,p)

MATLAB function that generates a row vector of linearly spaced points with a specified start, end, and number of points

40
New cards

subplot(m, n, p)

Splits the figure window into m rows and n columns, and selects the p-th slot counting row-by-row from top-left (this is ONLY for subplots other wise counting matrices is top to bottom, left to right)

41
New cards

Array storage order in MATLAB

MATLAB stores and reads matrices from top to bottom, then left to right (column dominant)

42
New cards

plot()

Plots y-data versus x-data

43
New cards

legend()

Creates a legend for a plot

44
New cards

comet()

Creates an animated plot

45
New cards

title()

Adds a title to a plot

46
New cards

figure()

Calls a figure window, needed to make a graph

47
New cards

clf

Clears the content of a figure window without deleting the window itself

48
New cards

close

Deletes one or more figure windows

49
New cards

axis()

Used to control the axes of a plot

50
New cards

semilogy() & loglog()

Plots normal y vs log x, and log y vs log x respectively

51
New cards

plot3() & surf()

Plots 3D line plots and 3D surface plots

52
New cards

Pass by value

The only way MATLAB passes data into functions

53
New cards

Function parts

  1. Name

  2. Inputs

  3. Outputs

  4. description comments

requires an end statement and must be saved in the active folder

54
New cards

Scope (Local vs Global)

Local variables exist only inside their function/workspace; global variables are visible and modifiable across multiple parts of code

55
New cards

Anonymous functions

Created using the @ symbol for quick, single-line functions without a separate .m file

56
New cards

input()

Requests input from the user; using 's' specifies a string input

57
New cards

disp()

Prints the contents of a variable to the screen without its label or formatting capabilities

58
New cards

num2str()

Converts a number input into a character array/string

59
New cards

fprintf()

Prints formatted output to the screen or a file using type fields

60
New cards

fprintf type field %f

Fixed-point notation

61
New cards

fprintf type field %e

Exponential notation

62
New cards

fprintf type field %d

Decimal notation; does not include trailing zeros if integer, or uses exponential notation if fractional

63
New cards

fprintf type field %i

Integer notation

64
New cards

fprintf type field %g

The shorter of %f or %e

65
New cards

fprintf type field %c

Character information (one character at a time)

66
New cards

fprintf type field %s

String of characters (displays entire string)

67
New cards

Formatting characters in fprintf

\n for a new line, \r for carriage return, \t for tab, and \b for backspace

68
New cards

ginput()

Used to get data points from a plot

69
New cards

dlmwrite()

Used to write delimited output

70
New cards

Sequence structure

Lines of code executed one after another

71
New cards

Selection structure

Enables branches within code based on conditions (true/false)

72
New cards

Repetition structure

Causes a group of statements to be executed multiple times (loops)

73
New cards

Pseudocode

Language-independent verbal description of computer code

74
New cards

Flowchart

Graphical representation of how code flows and progresses

75
New cards

find command

Finds the indices of elements in a matrix that meet a specific criteria

76
New cards

Relational Operators (==, ~=, ~)

Equality check, not equal to, and logical NOT

77
New cards

Logical Operators (&, |, &&, ||)

AND/OR for vectors, double opporators for scalars

78
New cards

xor()

Exclusive or logical operation

79
New cards

for loop

Used when you know exactly how many times you want to repeat an action

80
New cards

while loop

A pretest loop that executes as long as a specified condition remains true

81
New cards

For loop execution count

Runs a fixed number of times equal to the number of elements in the index matrix; can run 0 times if the index vector is empty

82
New cards

While loop execution count

Runs conditionally; can run 0 times (if the condition is initially false), a specific number of times, or infinitely (if the condition never becomes false)

83
New cards

break statement

Terminates the smallest enclosing for or while loop prematurely

84
New cards

continue statement

Skips the rest of the current loop iteration and advances to the next pass

85
New cards

Counter

A variable that keeps track of a parameter of interest (e.g., counting occurrences or accumulating sums)

86
New cards

Infinite loop

A loop that never terminates and runs continuously

87
New cards

Keyboard shortcut to stop infinite loops

Windows: Control-C; Mac: Command-Period

88
New cards

tic / toc

Stopwatch feature used to measure elapsed execution time in seconds

89
New cards

etime()

Performs a comparison between a start time and an end time (clock-based)

90
New cards

Pre-allocation

Allocating space for a vector or matrix beforehand (using zeros, ones, etc.) to significantly boost loop performance

91
New cards

Output suppression

Using a semicolon (;) at the end of statements inside loops to prevent printing every iteration and greatly improve speed

92
New cards
2 ways to print in MATLAB
disp( ) and fprintf( )
93
New cards
Types of Computer Code:
sequences, selection structures, repetition structures
94
New cards
Loops should be your first choice in matlab
NOOO, use a built-in function if available
95
New cards
Types of Loops for all computer languages
for, while, do while
96
New cards
Types of loops in MATLAB
for and while
97
New cards
Nesting for loops
the inner loop must fully execute before running the outer loop a second time
98
New cards
2 types of counters
how many (numbers in a data set meet a specification), how much (e.g. what is the sum of the numbers that meet the specification/)
99
New cards
T or F: Every for loop can be made into a while loop, but not every while loop can be made into a for loop
True, this is done by adding a counter to keep track of how many times a while loop has executed, and terminate once it has reached the desired number of interactions
100
New cards

4 Performances “Guiding Principles”

  1. only print using print statements

  2. pre-allocating vectors

  3. use recommendations from MATLAB GUI

  4. run code multiple times for average times