Engineering 101 MATLAB Exam With Complete
Solutions Latest Update
program - ANSWER a sequence of statements that instruct the computer to do
something.
interactive program - ANSWER Write statements in the terminal. Hitting Return executes
them immediately
script - ANSWER Write a series of statements ahead of time. Execute those statements
sometime later
suppress an output - ANSWER ;;
display - ANSWER produces an output
variables - ANSWER used to store data. refers to some chunk of memory where the
program stores a value. may contain letters of '_'. Case sensitive
ex: x, y, z
expressions - ANSWER used to compute new data
ex: x = 10+5, y = x .* 7.
consist of literals (3, 7.5), variables (a,b,c), and function calls (sin(3), sqrt(x))
assignment - ANSWER used to store a value into a variable
LHS = RHS, work right to left, takes the value of the RHS and stores it into the LHS.
ex: x .* 7 is assigned to y. variable may be re-assigned many times in code
,operators - ANSWER form compound expressions (+, *, -, etc)
whos - ANSWER used to get information about a variable, including the type of data it
currently stores
orange line around = - ANSWER warning, code will still run
comments - ANSWER use the % symbol. anything after the % until the end of the line is a
comment, comments are ignored by the program but are more for the human reader of
the code to help manage complexity
scalar - ANSWER single number or element
vector - 1 dimensional sequence of numbers or elements, numbers or elements can be
separated with spaces or commas
matrix - 2 dimensional grid of numbers or elements, you separate rows using ; or a new
line. you can use smaller matrices as components, if things doesn't line up, you get an
error
[] creates a vector or a matrix
(:) creates evenly spaced vectors. first:step:last
ex: 1:3:12 outputs [1,4,7,10], if the step is omitted it defaults to one
(') - ANSWER transpose operation takes a matrix and produces a copy with the rows
turned into columns
flipud - ANSWER flips the rows up/down
, fliplr - ANSWER flips columns left or right
array - ANSWER everything in matlab is an array. scalar = 1x1, vector = mx1 or 1xn,
matrix is mxn
zeros(m,n) - ANSWER returns an m x n matrix of zeros
zeros(m) - ANSWER returns a matrix of zeros using m for both rows and columns
ones(m,n) - ANSWER returns a m x n matrix of ones
ones(m) - ANSWER returns a matrix of ones using m for both rows and columns
magic(s) - ANSWER returns an s x s magic matrix. magic because each column sum =
each row sum = each diagonal sum.
repmat(A,xTimes,yTimes) - ANSWER makes a new matrix based on repeating matrix A a
certain number of times in the x direction and y direction
reshape(A,numRows,numCols) - ANSWER creates a new matrix with the same elements
as A, but the requested number of rows and columns. The dimensions must match up
with the original number of elements in A.
numel(x) - ANSWER gives the number of elements in x
length(x) - ANSWER gives the number of elements along the longest dimension of x
size(x) - ANSWER returns a vector with the number of elements along each dimension of
Solutions Latest Update
program - ANSWER a sequence of statements that instruct the computer to do
something.
interactive program - ANSWER Write statements in the terminal. Hitting Return executes
them immediately
script - ANSWER Write a series of statements ahead of time. Execute those statements
sometime later
suppress an output - ANSWER ;;
display - ANSWER produces an output
variables - ANSWER used to store data. refers to some chunk of memory where the
program stores a value. may contain letters of '_'. Case sensitive
ex: x, y, z
expressions - ANSWER used to compute new data
ex: x = 10+5, y = x .* 7.
consist of literals (3, 7.5), variables (a,b,c), and function calls (sin(3), sqrt(x))
assignment - ANSWER used to store a value into a variable
LHS = RHS, work right to left, takes the value of the RHS and stores it into the LHS.
ex: x .* 7 is assigned to y. variable may be re-assigned many times in code
,operators - ANSWER form compound expressions (+, *, -, etc)
whos - ANSWER used to get information about a variable, including the type of data it
currently stores
orange line around = - ANSWER warning, code will still run
comments - ANSWER use the % symbol. anything after the % until the end of the line is a
comment, comments are ignored by the program but are more for the human reader of
the code to help manage complexity
scalar - ANSWER single number or element
vector - 1 dimensional sequence of numbers or elements, numbers or elements can be
separated with spaces or commas
matrix - 2 dimensional grid of numbers or elements, you separate rows using ; or a new
line. you can use smaller matrices as components, if things doesn't line up, you get an
error
[] creates a vector or a matrix
(:) creates evenly spaced vectors. first:step:last
ex: 1:3:12 outputs [1,4,7,10], if the step is omitted it defaults to one
(') - ANSWER transpose operation takes a matrix and produces a copy with the rows
turned into columns
flipud - ANSWER flips the rows up/down
, fliplr - ANSWER flips columns left or right
array - ANSWER everything in matlab is an array. scalar = 1x1, vector = mx1 or 1xn,
matrix is mxn
zeros(m,n) - ANSWER returns an m x n matrix of zeros
zeros(m) - ANSWER returns a matrix of zeros using m for both rows and columns
ones(m,n) - ANSWER returns a m x n matrix of ones
ones(m) - ANSWER returns a matrix of ones using m for both rows and columns
magic(s) - ANSWER returns an s x s magic matrix. magic because each column sum =
each row sum = each diagonal sum.
repmat(A,xTimes,yTimes) - ANSWER makes a new matrix based on repeating matrix A a
certain number of times in the x direction and y direction
reshape(A,numRows,numCols) - ANSWER creates a new matrix with the same elements
as A, but the requested number of rows and columns. The dimensions must match up
with the original number of elements in A.
numel(x) - ANSWER gives the number of elements in x
length(x) - ANSWER gives the number of elements along the longest dimension of x
size(x) - ANSWER returns a vector with the number of elements along each dimension of