0
0
MATLABdata~20 mins

Interpolation (interp1) in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Interpolation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
A25
B20
C30
DError: Undefined function or variable 'interp1'
Attempts:
2 left
💡 Hint
Linear interpolation finds the value halfway between y(2) and y(3).
Predict Output
intermediate
2: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);
A30
B27
C20
DError: Input data must be strictly increasing
Attempts:
2 left
💡 Hint
Nearest method picks the y value of the closest x point.
Predict Output
advanced
2: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));
A8.50
B7.25
C6.56
DError: Method 'spline' not supported
Attempts:
2 left
💡 Hint
Spline interpolation fits a smooth curve through points.
Predict Output
advanced
2: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);
A6
B8
CNaN
DError: Extrapolation not allowed
Attempts:
2 left
💡 Hint
Extrapolation extends the linear trend beyond known points.
🧠 Conceptual
expert
2: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);
ANo error, returns interpolated value.
BError using interp1: Y must be a vector of the same length as X.
CError using interp1: XI must be within the range of X.
DError using interp1: X must be strictly monotonic increasing or decreasing.
Attempts:
2 left
💡 Hint
interp1 requires x to be sorted strictly increasing or decreasing.