Challenge - 5 Problems
Matrix Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this matrix creation code?
Consider the following MATLAB code that creates a matrix. What will be the resulting matrix?
MATLAB
A = zeros(2,3) + eye(2,3); disp(A);
Attempts:
2 left
💡 Hint
Remember that eye(m,n) creates an m-by-n matrix with ones on the main diagonal and zeros elsewhere.
✗ Incorrect
The zeros(2,3) creates a 2-by-3 matrix of zeros. The eye(2,3) creates a 2-by-3 identity-like matrix with ones on the diagonal. Adding them results in a matrix with ones on the diagonal and zeros elsewhere.
❓ Predict Output
intermediate1:30remaining
What is the size of the matrix created?
What is the size of the matrix B created by this MATLAB code?
MATLAB
B = ones(4) * 5;
Attempts:
2 left
💡 Hint
ones(n) creates an n-by-n matrix of ones.
✗ Incorrect
The ones(4) creates a 4-by-4 matrix of ones. Multiplying by 5 scales every element but does not change the size.
❓ Predict Output
advanced2:00remaining
What does this matrix creation code output?
What is the output of this MATLAB code snippet?
MATLAB
C = diag([3 4 5]); disp(C);
Attempts:
2 left
💡 Hint
The diag function creates a diagonal matrix from the input vector.
✗ Incorrect
diag([3 4 5]) creates a square matrix with 3, 4, and 5 on the main diagonal and zeros elsewhere.
❓ Predict Output
advanced2:30remaining
What is the output of this matrix concatenation?
What matrix does this MATLAB code produce?
MATLAB
D = [1 2; 3 4]; E = [5 6; 7 8]; F = [D E; E D]; disp(F);
Attempts:
2 left
💡 Hint
Square brackets concatenate matrices horizontally and vertically.
✗ Incorrect
The code concatenates D and E horizontally to form the top half, and E and D horizontally to form the bottom half, then concatenates these vertically.
❓ Predict Output
expert3:00remaining
What is the output of this complex matrix creation code?
What is the output of this MATLAB code snippet?
MATLAB
G = repmat([1 2; 3 4], 2, 3); disp(G);
Attempts:
2 left
💡 Hint
repmat repeats the matrix the specified number of times in rows and columns.
✗ Incorrect
repmat([1 2; 3 4], 2, 3) repeats the 2x2 matrix 2 times vertically and 3 times horizontally, resulting in a 4x6 matrix.