I am asked to investigate the different types of interpolation using Matlab for the following points:
x = [32 34 35 36 37 38]
y = [26 28 31 30 29 25]
and find the values for f(33)
, f(33.5)
and f(35)
.
When plotting x and y, I can see that f(33)
should be around 27, which is also what I get using interp1(x,y,33)
.
I am not sure if this is the correct way of using the Cubic spline interpolation function but I used spline(x,y,33)
and got ans = 24.3906
.
Shouldn't I still get the same value for f(33)
no matter what type of interpolation I use?
Interpolation makes sure the values of the interpolated function are the same as the values of original function at the points you provided. Looking at your code, it means that f(35)
will be same and will be equal to 31 for every interpolation method.
However, depending on the method of interpolation, the curve between each of the consecutive methods will vary, hence giving you different values, which is expected.