Challenge - 5 Problems
MATLAB vs Python vs R Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output difference in matrix multiplication
What is the output of this MATLAB code snippet?
A = [1 2; 3 4]; B = [5 6; 7 8]; C = A * B;
MATLAB
A = [1 2; 3 4]; B = [5 6; 7 8]; C = A * B;
Attempts:
2 left
💡 Hint
Remember that * in MATLAB means matrix multiplication, not element-wise.
✗ Incorrect
In MATLAB, * performs matrix multiplication. Multiplying A and B results in [[19 22]; [43 50]].
❓ Predict Output
intermediate2:00remaining
Python vs MATLAB element-wise multiplication output
What is the output of this Python code snippet using NumPy?
import numpy as np A = np.array([[1, 2], [3, 4]]) B = np.array([[5, 6], [7, 8]]) C = A * B print(C)
MATLAB
import numpy as np A = np.array([[1, 2], [3, 4]]) B = np.array([[5, 6], [7, 8]]) C = A * B print(C)
Attempts:
2 left
💡 Hint
In NumPy, * means element-wise multiplication, unlike MATLAB's *.
✗ Incorrect
NumPy's * operator multiplies elements one by one, so C is [[5 12]; [21 32]].
❓ Predict Output
advanced2:00remaining
R vector recycling behavior output
What is the output of this R code?
v1 <- c(1, 2, 3, 4) v2 <- c(10, 20) v3 <- v1 + v2 print(v3)
MATLAB
v1 <- c(1, 2, 3, 4) v2 <- c(10, 20) v3 <- v1 + v2 print(v3)
Attempts:
2 left
💡 Hint
R recycles shorter vectors to match the length of longer vectors.
✗ Incorrect
R repeats v2 elements to add to v1: 1+10=11, 2+20=22, 3+10=13, 4+20=24.
🧠 Conceptual
advanced1:30remaining
Key difference in indexing between MATLAB and Python
Which statement correctly describes a key difference in indexing between MATLAB and Python?
Attempts:
2 left
💡 Hint
Think about the first element position in each language.
✗ Incorrect
MATLAB arrays start at index 1, while Python arrays start at index 0.
❓ Predict Output
expert2:00remaining
Output of mixed language style code snippet
What is the output of this MATLAB code?
arr = [1, 2, 3, 4]; result = sum(arr > 2); disp(result);
MATLAB
arr = [1, 2, 3, 4]; result = sum(arr > 2); disp(result);
Attempts:
2 left
💡 Hint
arr > 2 creates a logical array; sum counts true values.
✗ Incorrect
Elements greater than 2 are 3 and 4, so sum counts 2 true values.