0
0
MATLABdata~20 mins

Special matrices (zeros, ones, eye, rand) in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Special Matrices Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of zeros and ones matrix operations
What is the output of the following MATLAB code?
 A = zeros(2,3);
 B = ones(3,2);
 C = A * B;
 disp(C);
MATLAB
A = zeros(2,3);
B = ones(3,2);
C = A * B;
disp(C);
A[1 1; 1 1]
B[3 3; 3 3]
CError: Matrix dimensions must agree.
D[0 0; 0 0]
Attempts:
2 left
💡 Hint
Remember that zeros multiplied by any number results in zeros.
Predict Output
intermediate
2:00remaining
Eye matrix diagonal values
What does the following MATLAB code display?
 I = eye(4);
 disp(I(2,2));
 disp(I(2,3));
MATLAB
I = eye(4);
disp(I(2,2));
disp(I(2,3));
A
0
1
B
1
1
C
1
0
D
0
0
Attempts:
2 left
💡 Hint
Eye matrix has ones on the diagonal and zeros elsewhere.
🔧 Debug
advanced
2:00remaining
Identify the error in matrix creation
What error does this MATLAB code produce?
 M = zeros(3);
 N = ones(2,3);
 P = M + N;
MATLAB
M = zeros(3);
N = ones(2,3);
P = M + N;
ANo error, P is a 3x3 matrix of ones.
BError: Matrix dimensions must agree.
CError: Undefined function or variable 'P'.
DNo error, P is a 2x3 matrix of zeros.
Attempts:
2 left
💡 Hint
Check the sizes of M and N before adding.
Predict Output
advanced
2:00remaining
Random matrix value range
What is the range of values produced by this MATLAB code?
 R = rand(2,2);
 disp(min(R(:)));
 disp(max(R(:)));
MATLAB
R = rand(2,2);
disp(min(R(:)));
disp(max(R(:)));
AValues between 0 and 1, exclusive
BValues between 0 and 1, inclusive
CValues between -1 and 1
DValues between 1 and 2
Attempts:
2 left
💡 Hint
rand generates numbers in the interval (0,1).
🧠 Conceptual
expert
2:00remaining
Number of elements in special matrices
How many elements does the matrix created by eye(5,3) contain in MATLAB?
A15
B5
C3
D8
Attempts:
2 left
💡 Hint
Count total elements in a 5-by-3 matrix.