Challenge - 5 Problems
Element-wise Operations Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of element-wise multiplication
What is the output of the following MATLAB code?
MATLAB
A = [1 2 3]; B = [4 5 6]; C = A .* B; disp(C);
Attempts:
2 left
💡 Hint
Remember that .* multiplies each element of A by the corresponding element of B.
✗ Incorrect
The operator .* performs element-wise multiplication. So each element in A is multiplied by the corresponding element in B: 1*4=4, 2*5=10, 3*6=18.
❓ Predict Output
intermediate2:00remaining
Result of element-wise division
What will be displayed after running this MATLAB code?
MATLAB
X = [10 20 30]; Y = [2 4 5]; Z = X ./ Y; disp(Z);
Attempts:
2 left
💡 Hint
Element-wise division divides each element of X by the corresponding element of Y.
✗ Incorrect
The operator ./ divides each element of X by the corresponding element of Y: 10/2=5, 20/4=5, 30/5=6.
❓ Predict Output
advanced2:00remaining
Output of element-wise power operation
What is the output of this MATLAB code snippet?
MATLAB
P = [2 3 4]; Q = [3 2 1]; R = P .^ Q; disp(R);
Attempts:
2 left
💡 Hint
The .^ operator raises each element of P to the power of the corresponding element in Q.
✗ Incorrect
Element-wise power means: 2^3=8, 3^2=9, 4^1=4. So the result is [8 9 4].
❓ Predict Output
advanced2:00remaining
Error type from wrong operator usage
What error does this MATLAB code produce?
MATLAB
A = [1 2 3]; B = [4 5 6]; C = A * B;
Attempts:
2 left
💡 Hint
The * operator is matrix multiplication and requires matching inner dimensions.
✗ Incorrect
A is 1x3 and B is 1x3, so their inner dimensions (3 and 1) do not match for matrix multiplication. MATLAB throws an error about inner matrix dimensions.
🧠 Conceptual
expert2:00remaining
Number of elements in result after element-wise operations
Given two matrices A (2x3) and B (2x3), what is the number of elements in the result of A .* B?
Attempts:
2 left
💡 Hint
Element-wise operations keep the same size as the input matrices.
✗ Incorrect
Element-wise multiplication produces a matrix of the same size as the inputs. Since A and B are 2 rows by 3 columns, the result has 2*3=6 elements.