wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

MATLAB Fundamentals Worksheet Questions

Total questions: 20

Worksheet time: 30mins

Name
Class
Date
1.

Which symbol is used to precede a comment in MATLAB code?

a)

//

b)

#

c)

%

d)

;

2.

If you enter num = 10 and then Num = 20 in MATLAB, what happens?

a)

The variable num is overwritten with 20.

b)

An error occurs because the variable already exists.

c)

Two separate variables, num and Num, are created.

d)

MATLAB asks for confirmation to rename the variable.

3.

What is the effect of placing a semicolon (;) at the end of a statement?

a)

It indicates the start of a comment.

b)

It suppresses the printing of the result to the Command Window.

c)

It stops the program execution.

d)

It is required to end every line of code.

4.

If you use the command plot(y) where y is a vector, what is plotted on the x-axis?

a)

The values of y.

b)

The index of the elements of y.

c)

A range from 0 to 1.

d)

It results in an error; x must be specified.

5.

What does the command hold on do when plotting?

a)

It pauses the execution of the script.

b)

It saves the current figure to a file.

c)

It allows adding new plots to an existing graph without replacing it.

d)

It locks the axes limits.

6.

Which suffix does MATLAB use to denote the imaginary part of a complex number?

a)

k or l

b)

i or j

c)

im or z

d)

c or d

7.

Which syntax correctly defines a user-defined function in MATLAB?

a)

def functionName(args):

b)

function [output] = functionName(input)

c)

void functionName(input)

d)

create function functionName

8.

In the context of matrix operations, what does the dsolve function primarily do?

a)

It solves linear algebraic equations.

b)

It finds symbolic solutions to ordinary differential equations.

c)

It computes the determinant of a matrix.

d)

It diagonalizes a matrix.

9.

To solve the differential equation dx/dt + 2x = 0 using dsolve, how should the equation be represented in MATLAB code?

a)

diff(x) + 2*x = 0

b)

dx/dt + 2x == 0

c)

diff(x,t) + 2*x == 0

d)

integral(x) + 2*x = 0

10.

Which MATLAB command converts a symbolic solution s into a vector that can be plotted numerically?

a)

double(s)

b)

numeric(s)

c)

eval(vectorize(s))

d)

plot(s)

11.

The dsolve function requires two main arguments to solve a specific initial value problem. What are they?

a)

The equation and the time vector.

b)

The equation and the initial conditions.

c)

The initial conditions and the plot type.

d)

The differential equation and the integral limit.

12.

According to the finite difference method, how is the numerical derivative of a function f(x) approximated with a step size h?

a)

(f(x+h) + f(x))/h

b)

(f(x+h) - f(x))/h

c)

f(x+h) - f(x)

d)

(f(x) - f(x-h))/2h

13.

What condition must be met regarding the number of subintervals to use Simpson’s 1/3 rule?

a)

The number of subintervals must be odd.

b)

The number of subintervals must be even.

c)

The number of subintervals must be a multiple of 3.

d)

The number of subintervals must be greater than 100.

14.

Which MATLAB command is used in the code to calculate the difference between adjacent elements of the vectors f1 and f2?

a)

gradient()

b)

deriv()

c)

diff()

d)

sub()

15.

Analyze the following MATLAB code snippet: Matlab A = [5 1 8; 4 7 8; 2 5 6]; s = sum(sum(A)); disp(s); What will be the output displayed in the Command Window?

a)

[11 13 22]

b)

46

c)

14

d)

21

16.

Consider the following script using flow control: Matlab for n = 1:5 if mod(n, 2) == 0 continue; end disp(n); end What sequence of numbers is displayed?

a)

1, 2, 3, 4, 5

b)

2, 4

c)

1, 3, 5

d)

1, 2, 3

17.

Review the code below regarding vector sizes: Matlab h = 0.1; t = 0:h:1; y = diff(t); disp(length(y)); (Note: t creates a vector from 0 to 1 with step 0.1, resulting in 11 elements) What value does length(y) return?

a)

11

b)

10

c)

1

d)

0

18.

Look at this snippet which modifies a matrix based on row differences: Matlab a = [2 4; 6 8]; b = zeros(2); for i = 2 for j = 1:2 b(i,j) = a(i,j) - a(i-1,j); end end disp(b(2,2)); What is the value of b(2,2)?

a)

4

b)

2

c)

8

d)

6

19.

Consider a function that calculates a sum based on a condition: Matlab % Function Definition function s = calc(N) s = 0; for i = 1:N if mod(i,2) == 0 s = s + i; end end end % Function Call val = calc(5); disp(val); What is the final output?

a)

15

b)

9

c)

6

d)

5

20.

Analyze the execution of the following MATLAB code snippet: Matlab M = [1 2 3; 4 5 6; 7 8 9]; [rows, cols] = size(M); for i = 1:rows for j = 1:cols if i == j M(i,j) = M(i,j) + 10; elseif i > j M(i,j) = 0; end end end val = M(2,1) + M(2,2) + M(2,3); disp(val); What value is displayed in the Command Window?

a)

15

b)

21

c)

19

d)

9