36 Questions
What does the command 'clear' do in MATLAB?
Deletes all current variables
What is the purpose of the '%' symbol in MATLAB?
To denote a non-executable line or portion of a line
What is the difference between 'who' and 'whos' commands in MATLAB?
'who' requests a list of variables, while 'whos' requests a list of variables plus their size and type
What is the purpose of the comma in MATLAB?
To separate several MATLAB commands on one line
How does MATLAB automatically set the format of numerical values in the command window?
To have 4 values to follow the decimal
What is the purpose of the ellipsis in MATLAB?
To continue a MATLAB command onto the following line
What is the default variable name in MATLAB if no location is specified?
ans
What is the purpose of the 'd' in MATLAB functions such as tand(x) and cosd(x)?
To specify the degree measure
What is the limitation on the length of a variable name in MATLAB for the purposes of this class?
33 characters
What is the recommended format type to use when dealing with complex numbers in MATLAB?
short
What is the purpose of the 'format long' command in MATLAB?
To display the number with a total of 16 numerical digits
What is the result of the MATLAB command '0.25+0.5' if no variable name is specified?
ans = 0.7500
What is the difference between the MATLAB commands 'tan(x)' and 'tand(x)'?
tan(x) is for radian measures, tand(x) is for degree measures
What is the significance of the variable 'i' in MATLAB?
It is a reserved variable for complex numbers
What is the output of the command A = [1 2 3; 4 5 6; 7 8 9]; A^2?
[30 36 42; 66 81 96; 102 126 150]
How can you get the transpose of a matrix A?
Using the ' operator
What is the command to compute the inverse of a matrix A?
inv(A)
What is the command to compute the determinant of a matrix A?
det(A)
What is the output of the command A = [1 2 3; 4 5 6; 7 8 9]; A(:,3)?
[3; 6; 9]
What is the difference between A^2 and A.^2?
A^2 is matrix multiplication, A.^2 is element-wise multiplication
How can you solve the equation [A]{x} = {b}?
x = inv(A)*b
What is the command to create an identity matrix of size 3?
I = [1 0 0; 0 1 0; 0 0 1]
What is the purpose of the if structure in MATLAB?
To make decisions based on conditions
What is the purpose of the roots function in MATLAB?
To find all the roots of a polynomial equation
What is the syntax to find the LU factorization of a matrix X in MATLAB?
[L,U] = lu(X)
What is the purpose of the chol function in MATLAB?
To find the Cholesky factorization of a matrix
What is the purpose of the fzero function in MATLAB?
To find the zero of a function
What is the purpose of the polyval function in MATLAB?
To evaluate a polynomial at a specific point
What is the primary difference between a script file and a function file in MATLAB?
Script files run in the base workspace, whereas function files run in their own workspace.
What is the purpose of the input
function in MATLAB?
To prompt the user for a value.
What is the purpose of the disp
function in MATLAB?
To display a value to the user.
What is the purpose of the fprintf
function in MATLAB?
To display a set of values to the user.
What is the output of the stats
function when given the input [8 5 10 12 6 7.5 4]
?
mean = 7.5, stdev = 2.1
What is the purpose of a function handle in MATLAB?
To assign a function to a variable.
What is the formula for calculating the volume of a cylinder?
V = pir^2h
What is the formula for calculating the total surface area of a cylinder?
S = 2pirh + 2pi*r^2
Study Notes
MATLAB Basics
- The
clear
command is used to delete all current variables; to delete specific variables, useclear var1 var2
. -
who
andwhos
are used to request a list of variables in use during the current session, withwhos
also displaying size and type.
Symbols and Usage
-
%
is used to denote a non-executable line or portion of a line, and can be used for commenting. -
;
is used to suppress the display of a MATLAB line and can also be used to separate commands on one line. -
,
is used to separate several MATLAB commands on one line. -
…
is used to continue a MATLAB command onto the following line.
Numerical Values and Formats
- The format of numerical values in the command window is automatically set to have 4 values to follow the decimal, even if trailing zeros must be written.
-
format long
is used to display 16 numerical digits. -
format bank
is used to display numbers in banking format.
Variables
- A variable name is a location used to store either the results of mathematical operations or to store data.
- A variable name can contain letters, numbers, and/or underscores, but must be less than 33 characters and start with a letter.
- Variable names are case sensitive and should be relevant to the value it represents.
- If no location is specified,
ans
is the default variable name.
Special Variables
- Certain variables (e.g.
i
,j
,eps
) should not be used as variable names.
Mathematical Operations
- MATLAB supports various mathematical operations, including trigonometric functions (e.g.
tan
,sin
,cos
) and complex values. - When dealing with complex numbers, the format type should be left as
short
.
Matrix Manipulations
- Matrices can be indexed using
A(:,3)
to select columns andA(3,:)
to select rows. - Matrices can be manipulated using various operations, including exponentiation (
A^2
), element-wise exponentiation (A.^2
), and matrix multiplication. - The transpose of a matrix can be obtained using the
'
operator. - Matrices can be augmented using
Aug=[A I]
andD=[A;I]
. - The matrix inverse can be computed using the
inv
function. - The matrix determinant can be computed using the
det
function.
Arrays, Vectors, and Matrices
- The colon operator is used to create and manipulate arrays.
- Functions can be built and scripts can be created in the MATLAB editor.
Programming in MATLAB
- A function is a self-contained set of instructions designed to do a specific task.
- A function has its own workspace for variables, and information can be added to or removed from the workspace only through input and output variables.
- Function handles can be assigned to variables.
- Script files can be created using
File, New, M-file
. -
clc
,clear all
, andclose all
are used to clear the command window and reset variables.
Input-Output
- The
input
function is used to prompt the user for values directly from the command window. - The
disp
function is used to display a value. - The
fprintf
function is used to display a set of values.
Decisions
- The
if
structure is used for conditional statements.
MATLAB Functions
- The
roots
function is used to determine all the roots, both real and complex, of a polynomial equation. - The
lu
function is used to generate the LU factorization of a matrix. - The
chol
function is used to generate the Cholesky factorization of a matrix.
Learn basic commands in MATLAB such as clearing variables and listing variables with their size and type.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free