WorksheetsECE404L - Long Test
Total questions: 98
Worksheet time: 49mins
What does MATLAB stand for?
Matrix Laboratory
Math Library Tool
Mathematical Language Tool
Matrix Language Toolkit
Which window in the MATLAB interface is primarily used to enter commands directly?
Editor Window
Workspace Window
Command Window
Figure Window
How do you suppress output of a command in MATLAB?
Put a comma at the end of the line
Put a semicolon at the end of the line
Use the keyword silent
Use parentheses around the command
Which command clears all variables from the workspace?
clear all
reset
clc
close all
What is returned by typing who in the MATLAB command window?
A list of all open figure windows
A list of all functions in the path
A list of variables currently in workspace
A list of built-in MATLAB commands
How do you get detailed help on the function sin?
? sin
help sin
info sin
docs sin
Which file extension is standard for MATLAB script files?
.m
.mat
.mdl
.mlx
What happens if you try to use a variable that has not been defined yet?
MATLAB assigns it a default value of zero
MATLAB throws an error
MATLAB assumes it is symbolic
MATLAB ignores it
The Command clc in MATLAB:
Clears command window contents
Deletes all workspace variables
Closes all figure windows
Clears breakpoints
The Command clear x does what?
Sets variable x to zero
Removes x from the workspace
Clears the screen and resets x
Overwrites x with an empty matrix
What's the result of 5 + 3 * 2 in MATLAB, without parentheses?
16
11
10
13
How do you comment a single line in a MATLAB script?
// this is a comment
# this is a comment
% this is a comment
/* this is a comment */
If you want to run a script file named myscript.m, how do you do it?
Type run myscript.m
Type myscript (assuming it's in the path or current folder)
Double-click on the file in Current Folder window
All of the above
Which key-binding or menu option would you use to stop a running MATLAB script?
CTRL+C in Command Window
CTRL+Z
ESC
SHIFT+Q
What data type does MATLAB use for numbers by default?
symbolic
single precision floating-point
double precision floating-point
integer
Which command shows you list of all variables along with their sizes and types?
whos
vars
info
workspace
What is the result of pi in MATLAB?
3.14 exactly
The literal string "pi"
A variable storing π to double precision
An undefined variable unless declared
The command load datafile will do what assuming datafile.mat exists?
Display its contents
Load variables saved in that file into workspace
Import data as a text file
Create a new file named datafile
If you type a = 10; b = a + 1; what is the value of b?
10
11
1
Undefined
What is the effect of type myfile.m in the Command Window?
Executes myfile.m
Deletes myfile.m
Displays the contents of myfile.m on screen
Edits myfile.m in the editor
Which operator is used for element-wise multiplication of vectors or matrices?
*
.*
x
dot
How do you compute symbolic power of a symbolic expression x to the n?
x ^ n (numeric)
power(x, n) with symbolic
x .^ n
sympower(x,n)
What does ./ do in MATLAB?
Division, treating vectors/matrices normally
Left matrix division
Element-wise division
Not a valid operator
Which function returns the remainder after division?
divide
mod
rem
Both B and C
What is the difference between mod(a,b) and rem(a,b)?
No difference
Sign of result differs when a is negative
mod works only with integers, rem works with floats
mod returns symbolic, rem returns numeric
Which operator is used for matrix multiplication?
.*
*
dot
/
If a and b are symbolic variables, which command is correct to create them?
a = sym a; b = sym b;
syms a b
declare symbolic a, b
symvar a b
What happens if you try element-wise division of incompatible sized arrays?
MATLAB automatically broadcasts
Error due to dimension mismatch
It truncates to smallest dimension
Fills with zeros where no match
In symbolic arithmetic, how do you simplify the expression (x^2 - y^2)/(x-y)?
Use expand
Use factor
Use simplify
Use subs
Which of the following is NOT an arithmetic operator in MATLAB?
+
-
#
^
Suppose a = [1 2 3] and b = [4 5 6]. What does a .* b produce?
[4 10 18]
[5 7 9]
dot(a,b)
Error
Suppose x is symbolic. What is the result of x * x vs x .* x?
Both same if x is scalar symbolic
.* is needed only when x is numeric array
* does matrix multiplication even for symbolic
.* is invalid for symbolic
Which of the following commands gives element-wise power raising?
.^
^
power (numeric)
mpower
How do you represent exponentials symbolically (e.g., e^x)?
exp(x)
e^x
sym('e^x')
Both A and C
What's the result of sym(1/3) vs 1/3 (without sym)?
Same result numerically
sym(1/3) gives exact rational representation while 1/3 is approximate in floating point
1/3 gives rational, sym(1/3) gives symbolic float
MATLAB error
Which function would you use to convert a symbolic expression to numeric (double)?
double(expr)
num(expr)
real(expr)
vpa(expr)
If a = sym('a'); b = sym('b');, what is a + b?
Numeric sum (error)
Symbolic expression a + b
Undefined
Zero
What is the result of 2 ^ sym(3)?
8 (numeric double)
2^3 symbolic
Error
9
Which operator is used for matrix power (i.e. square of a matrix)?
.^
^
mpower
Both B and C
In symbolic arithmetic, what does nthroot(a, n) do?
Returns the nth power of a
Returns the nth root of symbolic a
Error for non-integer n
Same as a^(1/n) always
Which of the following is a valid variable name in MATLAB?
2ndVar
temp_val
my-var
count.
What is the result of executing x = 5; x = x + 2;?
Throws an error
x = 5
x = 7
x remains undefined
What is the difference between sym var = sym('var') and syms var?
No difference
syms clears previous assumptions; sym('var') can preserve some assumptions
sym always numeric, syms always symbolic
syms requires toolbox, sym does not
What does MATLAB do if you assign a new value to an existing variable?
Errors out
Changes the variable's value (overwrites)
Creates a new variable
Keeps both versions
Which command displays the current value of a variable a?
disp(a)
Just typing a in command window
display a
All of the above
How do you check whether a variable z exists in workspace?
exist('z')
isvar z
hasvar z
variable_exists(z)
Which command clears a specific variable named x?
clear all x
clear x
delete x
erase x
What is the effect of doing global g; g = 10; inside a function?
Makes g accessible in base workspace and other functions that declare it global
Only within that function
Errors if g already exists
Makes g permanent
Which MATLAB statement assigns a 3×3 identity matrix to variable I?
I = eye(3);
I = ones(3);
I = zeros(3);
I = eye;
What happens if you try to concatenate variables of mismatched dimensions without proper operators?
MATLAB auto adjusts sizes
Error due to dimension mismatch
Truncation or padding with zeros
Warning only
After a = 2; b = a; a = 5;, what is value of b?
2
5
undefined
MATLAB error
Which type of variable stores text?
double
char or string
symbolic
logical
What is the purpose of who vs whos?
Both same
who gives names only; whos gives names + size + type etc.
whos deletes variables
who clears workspace
How do you make a variable persistent inside a function?
Use persistent keyword
Use global keyword
Use declare persistent
MATLAB does this by default
What is stored in a variable declared as logical?
Only true (1) or false (0) values
Boolean text strings
Numeric floats only
Characters
Which of these is NOT allowed as part of a variable name?
Letters (a-z, A-Z)
Digits, but not as the first character
Underscore _
Spaces
What happens if you refer to a function name as a variable (e.g. sin = 5)?
Overwrites built-in function temporarily
MATLAB errors immediately
It auto-renames the function
Not allowed
If syms x y is executed, what are x and y?
Numeric variables of default type double
Symbolic variables
Strings
Functions
Which of the following is the natural logarithm function in MATLAB?
log
ln
log10
log_e
Which function computes sine of an angle in radians?
sind
sin
sinr
sine
What does the function exp(x) compute?
x raised to the power e
e raised to the power x
logarithm base e of x
exponential integral
How do you compute the derivative of a symbolic expression f(x)?
diff(f,x)
deriv(f,x)
d(f)/dx
symbolicdiff(f)
Which function returns the integral of a symbolic expression?
int(f,x)
integral(f,x)
integrate(f,x)
symbolicint(f,x)
What is sqrt(x)?
Square of x
Square root of x
Error for negative x (numeric)
Both B and C depending on x
How to compute sin(x)^2 + cos(x)^2 symbolically and simplify?
sin(x)^2 + cos(x)^2 and then simplify(...)
Use identity function
MATLAB automatically simplifies
Use expand(...)
Which of the following returns absolute value (numeric)?
abs(z)
magnitude(z)
mag(z)
modulus(z)
How do you compute log base 10 in MATLAB?
log10(x)
log(x)/log(10)
log10f(x)
Both A and B
If f = sym('x^3 + 2*x');, what is subs(f, x, 5)?
f remains symbolic expression
Replaces x by 5 → returns 5^3 + 2*5 = 135 symbolic
135 (numeric double)
Error
What does factor(x^2 - 1) do when x is symbolic?
Converts to expanded form
Factorizes to (x-1)*(x+1)
Numeric root finding
Simplifies to x^2 - 1
Which function gives the inverse of sine (arcsine)?
asin
arcsin
inv_sin
sin-1
How does MATLAB compute symbolic trigonometric functions with exactness?
Always numeric approx
Using symbolic engine so expressions like sin(pi) simplify exactly
It cannot simplify trigonometric symbolic functions
Only for rational multiples of pi
What is the result of log(sym(exp(1)))?
1
log(e) symbolic
Numeric value 1.0000
Error
Which command plots a function f(x) over interval [0,2π]?
plot(f,0,2*pi)
fplot(f, [0, 2*pi])
plot(f(x), 0:2*pi)
symbolicplot(f, [0,2*pi])
To compute the Taylor expansion of exp(x) around x=0 up to 5th order, which function is used?
taylor(exp(x), x, 0, 'Order',5)
series(exp(x),5)
maclaurin(exp(x),5)
expand(exp(x))
The numeric function floor(x) does what?
Rounds x toward negative infinity
Rounds x toward zero
Rounds x to nearest integer
Rounds x toward infinity
What does ceil(x) do?
Round down to integer
Round up to nearest integer
Round toward zero
Round to nearest
What is returned by round(3.7)?
3
4
3.7
Error
For a symbolic f = sym('sin(x)/x'), what does limit(f, x, 0) return?
Undefined
1 (because limit of sin(x)/x as x → 0 is 1)
0
Error
In MATLAB, what are i and j?
Variables like any other
Constants for imaginary unit sqrt(−1)
Functions
Matrix indices
What is the real part of 3 + 4i?
4
3
real(3 + 4i) returns 3
imag(3 + 4i)
What is the magnitude (absolute value) of 3 + 4i?
7
5
sqrt(3+4)
25
What does conj(z) do to complex z?
Returns the real part
Returns the imaginary part
Returns the complex conjugate
Returns magnitude
How do you compute the phase angle of a complex number z in MATLAB?
phase(z)
angle(z)
arg(z)
atan(imag(z)/real(z))
If z = complex(3,4);, what is real(z)?
4
3
Error
complex(3,4)
If z = 5 + 12i, what is abs(z)^2?
13
169
25 + 144 = 169
Both B and C
Which of the following gives an error?
i^2
1i + 2j
i + j
Using i after redefining it as a variable
For complex z = −1 + i*0, what does isreal(z) return?
true (logical 1)
false (logical 0)
error
depends on workspace
What is the result of complex(0,1)^2?
−1
1
i
−i
Which command creates a complex number 2 + 3i symbolically?
sym(2 + 3*i)
2 + 3*1i
complex(2,3) (numeric)
Both A and C
How does MATLAB treat i if you assign i = 5; later?
i stays imaginary unit always
The variable i shadows built-in imaginary unit
MATLAB prevents overriding i
Generates error
What is the result of angle(1 + 1i)?
π/4 (in radians)
1
45 degrees numeric only
0
Which of these computes the complex conjugate transpose of matrix A?
A.'
A'
ctranspose(A)
Both B and C
What does unwrap(angle(z)) do?
Restricts the angle to [−π, π]
Removes discontinuities in phase angle vector
Computes magnitude
Error if z is symbolic
If z1 = 3 + 4i; z2 = 1 - 2i;, what is z1 * z2?
Numeric multiplication
Complex multiplication: (3 + 4i)(1 − 2i) = 11 + 2i
31 − 42 + i(3(−2)+4*1)
Both B and C
How do you plot complex numbers in MATLAB graphically?
Using plot(real(z), imag(z))
complexplot(z)
plot_complex(z)
plot3(z)
What is the output of imag(5 + 6i)?
5
6
i
0
If z = sym('z');, what is abs(z)?
Simplified as abs(z) symbolic
x if assumed real
error until assumptions made
Always z
What is cplxpair([1+2i, 1-2i, 2+0i]) used for?
Sorts and pairs complex conjugates
Computes magnitude pairs
Returns phase angle pairs
Makes matrix pairs
