Challenge - 5 Problems
Interpolation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of interp1 with linear method
What is the output of the following MATLAB code snippet?
MATLAB
x = [1 2 3 4 5]; y = [10 20 30 40 50]; xi = 2.5; yi = interp1(x, y, xi, 'linear'); disp(yi);
Attempts:
2 left
💡 Hint
Linear interpolation finds the value halfway between y(2) and y(3).
✗ Incorrect
The value at xi=2.5 is halfway between y(2)=20 and y(3)=30, so the output is 25.
❓ Predict Output
intermediate2:00remaining
Output of interp1 with 'nearest' method
What will be the output of this MATLAB code?
MATLAB
x = [0 1 2 3 4]; y = [0 10 20 30 40]; xi = 2.7; yi = interp1(x, y, xi, 'nearest'); disp(yi);
Attempts:
2 left
💡 Hint
Nearest method picks the y value of the closest x point.
✗ Incorrect
2.7 is closer to 3 than 2, so yi = y(4) = 30.
❓ Predict Output
advanced2:00remaining
interp1 with 'spline' method output
What is the output of this MATLAB code snippet?
MATLAB
x = [1 2 3 4]; y = [1 4 9 16]; xi = 2.5; yi = interp1(x, y, xi, 'spline'); disp(round(yi,2));
Attempts:
2 left
💡 Hint
Spline interpolation fits a smooth curve through points.
✗ Incorrect
The spline interpolation at 2.5 gives approximately 6.56 after rounding.
❓ Predict Output
advanced2:00remaining
interp1 with extrapolation option
What is the output of this MATLAB code?
MATLAB
x = [1 2 3]; y = [2 4 6]; xi = 4; yi = interp1(x, y, xi, 'linear', 'extrap'); disp(yi);
Attempts:
2 left
💡 Hint
Extrapolation extends the linear trend beyond known points.
✗ Incorrect
Linear extrapolation beyond x=3 gives yi=8 at x=4.
🧠 Conceptual
expert2:00remaining
Error type from invalid interp1 input
What error does MATLAB produce when calling interp1 with non-monotonic x vector like this?
x = [1 3 2 4];
y = [10 30 20 40];
xi = 2.5;
interp1(x, y, xi);
Attempts:
2 left
💡 Hint
interp1 requires x to be sorted strictly increasing or decreasing.
✗ Incorrect
The x vector is not strictly monotonic, so interp1 throws an error about monotonicity.