1/82
Final Exam
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
what is a scalar
single number
what is a character
letter or number
what is an array
multiple scalars
what is a string using ‘ ‘
character array
what is a string using “ “
string
what are the two requirements for variable names?
clear/descriptive, succinct
create a custom function heading
function[outputs] = FunName(inputs)
create an anonymous function
FunName = @(inputs) code
if an input needs to be a character/string what needs to be before the closing parenthesis
‘s’
what is fprintf %f
float
what is fprintf %i
integer
what is fprintf %c
character
what is fprintf %s
string
what is fprintf %e
scientific notation
what is \t for
indent(4 spaces)
what is \n for
new line
brute force defining rows for 1D array
[1 2 3 4];
brute force defining columns for 1D array
[1;2;3;4]; (or [1 2 3 4]’;)
colon operator for rows in 1D array
row = start:step size:stop
how does linspace work
row = linspace(start, stop, total elements)
index x to get all odd elements
x(1:2:end)
index x to get all even elements
x(2:2:end)
to multiply or divide scalar and vectors what is needed
.* or ./
what does the size function return
[rows, columns]
what does the length function return
longest dimension
what does numel return
number of elements
change the 3rd element of array x to 10
x(3) = 10;
what would be the output when x = [1 2 3] and then x(end + 2) = 5
[1 2 3 0 5];
how would you reverse the order of array x
x = x(end:1:-1); (or x = flip(x))
what does mod(a, b) return?
remainder of a/b
when and how does && work
only works with scalars and if 1 is false don’t evaluate 2
when to use for loops
number of reps is known
when to use while loops
number of reps is unknown but we have a stopping condition
how does a for loop start
for k = 1:length(x)
how does a while loop start
while condition true
write out euler method
yes
which direction do the rows count up in a 2D array
-y
which direction do the columns count up in a 2D array
+x
what does x(:, 2) produce in a 2D array
all rows, 2nd column
what does x(3, :) produce in a 2D array
3rd row, all columns
brute force create x, a 2D array with 123 as the top row and 456 as the bottom row
x = [1 2 3; 4 5 6];
store spreadsheet (FileName.ext) data into variable data
data = readmatrix(‘FileName.ext’)
create spreadsheet (named filenameNew.ext) using dataNew
writematrix(dataNew, ‘filenameNew.ext’)
create a text file (filename.dat) using fprintf
fid = fopen(‘filename.dat’, ‘w’)
fprintf(fid, ‘…’)
fclose(fid)
Create vector P using polyfit
P = polyfit(x, y, N)
What is the N in polyfit(x, y, N)
highest exponent in the polynomial
use sum function to sum along the columns of array x
[1 2 3]
sum(x, 1)
use sum function to sum along the rows of array x
[1
2]
sum(x, 2)
how does the max function work ** dim is either 1 for columns or 2 for rows
[max values, index/location] = max(data, [ ], dim)
how can you find the global max of x and store it in variable y
y = max(max(x));
take the average of x
mean(x)
store the standard deviation of x in the variable y *rms works the same way
y = std(x, dim)
create a scatter plot using plot
plot(x, y, ‘shape’)
create a scatter plot using scatter
scatter(x, y, marker size, ‘options’)
create a histogram with m sized bins
histogram(x, m)
create a box plot
boxplot(x)
create a bar graph with error bars
bar(x, y)
hold on
errorbar(x, y, error bar size, ‘options’)
hold off
how does machine learning work?
pattern recognition
how does fitctree work?
based on decision trees, binary choices
how does fitcnet work?
creates neural network, how your brain works, better for complicated systems
what does a confusion matrix show?
predictions and actual results in a grid
import image (img.ext) into variable img
img = imread(‘img.ext’)
display image (img)
imshow(img)
save image (imgNew) as filename.ext
imwrite(imgNew, ‘filename.ext’)
convert rgb image (img) to grayscale (imgGray)
imgGray = rgb2gray(img);
convert rgb image (img) to binary image (imgBin)
imgBin = im2bw(img, fraction)
crop image (img) and store in variable imgCrop
imgCrop = imcrop(img[xTopLeft, yTopLeft, xSize, ySize])
color thresholding for red from image (img)
red = img(:, :, 1)
color thresholding for green from image (img)
green = img(:, :, 2)
color thresholding for blue from image (img)
blue = img(:, :, 3)
info for diff functions
1D arrays, easy to do N derivatives, loses data points for each derivative
info for gradient function
2D arrays, harder to do N derivatives, handles nonconstant step sizes, may have weird endpoints
take the 2nd derivative of y using diff function
diff(y, 2)
take the first derivative of y using gradient, store in v with t as the spacing for dimensions
v = gradient(y, t)
take the integral using the trapezoid rule and store it in yInt
yInt = trapz(x, y) + initial value
how does a 3D plot function work
plot3(x, y, z, ‘options’)
how does the mesh function work for 3D plots
mesh(X, Y, Z), colors along grid, white between grid
how does the surf function work for 3D plots
surf(X, Y, Z), color between the grid, black grid lines
how does the colorbar function fit into the title label when making a graph
title(colorbar, ‘title’)
how does the quiver plot work?
quiver(X, Y, U, V, scale for vectors)
how does streamslice plot work?
streamslice(X, Y, U, V, number of streamlines)
what is the difference between quiver and streamslice plots?
quiver looks like a vector field, streamslice has the lines connected
what are the U and V in the streamslice and mesh functions?
x and y vector magnitudes