0
0
MATLABdata~10 mins

Interpolation (interp1) in MATLAB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to interpolate the value at x = 2.5 using linear interpolation.

MATLAB
x = [1 2 3 4 5];
y = [10 20 30 40 50];
result = interp1(x, y, [1]);
Drag options to blanks, or click blank then click option'
A3.5
B2.5
C1.5
D4.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value outside the range of x, which causes NaN result.
Using an x value that is not numeric.
2fill in blank
medium

Complete the code to use 'nearest' method for interpolation at x = 3.7.

MATLAB
x = [1 2 3 4 5];
y = [10 20 30 40 50];
result = interp1(x, y, 3.7, [1]);
Drag options to blanks, or click blank then click option'
A'nearest'
B'linear'
C'spline'
D'pchip'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'linear' instead of 'nearest' changes the interpolation behavior.
Forgetting the quotes around the method name.
3fill in blank
hard

Fix the error in the code to interpolate at x = 6 using extrapolation.

MATLAB
x = [1 2 3 4 5];
y = [10 20 30 40 50];
result = interp1(x, y, 6, 'linear', [1]);
Drag options to blanks, or click blank then click option'
A'spline'
B'linear'
C'extrap'
D'nearest'
Attempts:
3 left
💡 Hint
Common Mistakes
Not specifying 'extrap' causes NaN for out-of-range points.
Using 'nearest' or 'linear' without extrapolation option.
4fill in blank
hard

Fill both blanks to create a vector of interpolated values at points 1.5 and 4.5 using 'pchip' method.

MATLAB
x = [1 2 3 4 5];
y = [10 20 30 40 50];
xi = [[1] [2]];
result = interp1(x, y, xi, 'pchip');
Drag options to blanks, or click blank then click option'
A1.5
B4.5
C2.5
D3.5
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing points outside the x range without extrapolation.
Using points that are not numeric.
5fill in blank
hard

Fill all three blanks to interpolate values at points 2, 3.3, and 5 using 'spline' method.

MATLAB
x = [1 2 3 4 5];
y = [10 20 30 40 50];
xi = [[1] [2] [3]];
result = interp1(x, y, xi, 'spline');
Drag options to blanks, or click blank then click option'
A2
B3.3
C5
D'spline'
Attempts:
3 left
💡 Hint
Common Mistakes
Using points outside the x range without extrapolation.
Not using the correct method string for interpolation.