0
0
MATLABdata~20 mins

MATLAB vs Python vs R comparison - Practice Questions

Choose your learning style9 modes available
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
intermediate
2: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;
A[19 22; 43 50]
B[17 20; 39 46]
C[5 12; 21 32]
D[12 16; 28 40]
Attempts:
2 left
💡 Hint
Remember that * in MATLAB means matrix multiplication, not element-wise.
Predict Output
intermediate
2: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)
A
[[19 22]
 [43 50]]
B
[[1 2]
 [3 4]]
C
[[5 6]
 [7 8]]
D
[[5 12]
 [21 32]]
Attempts:
2 left
💡 Hint
In NumPy, * means element-wise multiplication, unlike MATLAB's *.
Predict Output
advanced
2: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)
A[10 20 10 20]
B[11 22 13 24]
C[11 22 33 44]
DError: vectors must be same length
Attempts:
2 left
💡 Hint
R recycles shorter vectors to match the length of longer vectors.
🧠 Conceptual
advanced
1:30remaining
Key difference in indexing between MATLAB and Python
Which statement correctly describes a key difference in indexing between MATLAB and Python?
AMATLAB uses 1-based indexing; Python uses 0-based indexing.
BBoth MATLAB and Python use 0-based indexing.
CMATLAB uses 0-based indexing; Python uses 1-based indexing.
DBoth MATLAB and Python use 1-based indexing.
Attempts:
2 left
💡 Hint
Think about the first element position in each language.
Predict Output
expert
2: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);
AError: Unsupported operation
B7
C2
D3
Attempts:
2 left
💡 Hint
arr > 2 creates a logical array; sum counts true values.