The interp command interpolates a discretized function at a list of given points by using fast spline interpolation routines in GSL. You should use this command when you do not need the interpolated function itself but only its values at a sequence of points.
The description of spline types below is quoted from GSL documentation.
This example is adapted from GSL documentation. To define some synthetic data, enter:
x,y:=makelist(k->k+0.5*sin(k),0,10),makelist(k->k+cos(k^2),0,10):; |
This gives you 11 data points. To interpolate the function at intermediate points, enter:
t:=linspace(min(x),max(x),1000):; z:=interp(x,y,t):; |
Now plot the data and the interpolated values together:
listplot(tran([t,z])); scatterplot(tran([x,y]),display=blue+point_width_2) |
To see the difference between the supported spline types, interpolate in the segment [4,6]. Enter:
t:=linspace(4,6):; c,a,s:=interp(x,y,t,"cubic"),interp(x,y,t,"akima"),interp(x,y,t,"steffen"):; listplot(tran([t,c]),color=blue+quadrant4,legend="cubic"); listplot(tran([t,a]),color=red,legend="akima"); listplot(tran([t,s]),color=magenta,legend="steffen"); |