spline
spline(x,v,xq) returns the cubic spline interpolated data of function v corresponding to the querying
elements in xq.
Spline uses the not-a-knot end conditions by default but it can also use the 'clamped' end condition.
- x: vector with sample points
- v: evaluation of x. It can be a vector or a matrix. If v is a vector the same size as x, the not-a-knot end conditions are use. If v is a vector containing exactly two more elements than x, the 'clamped' end conditions are used. In this case, the first and last elements in v are used as the end-slopes for the cubic spline. The same applies row by row in the case of v being a matrix
- xq: coordinates of querying points. It can be a vector or a matrix
Examples
>> x = [1 2 3 4] y = [5 2 10 9] xq = 1:0.1:4 yq = spline(x,y,xq) op = struct('show', false) overlay({plot(xq,yq,op), scatter(x,y,op)})
>> x = [1 2 3 4] y = [5 2 10 9; 1 3 -5 7]% y matrix
xq = 1:0.1:4 yq = spline(x,y,xq) op = struct('show', false) overlay({plot(xq,yq,op), scatter(x,y,op)})
>> x = [0 1 3 4] y = [0 0 2 2] xq = 0:0.1:4% not-a-knot interpolation
yq1 = spline(x,y,xq)% 'clamped' interpolation: 0 and 1 are used as endslopes
yq2 = spline(x,[0 y 1],xq) o = struct('show', false)% options struct for scatter
o.markerStroke = 'black' o.markerSize = 4 s = scatter(x,y,o) o = struct('show', false)% options struct for not-a-knot
o.lineStroke = 'blue' p1 = plot(xq,yq1,o) o = struct('show', false)% options struct for clamped
o.lineStroke = '#ff0000' o.dashArray = '6 8' o.lineWidth = 2 p2 = plot(xq,yq2,o) o = struct% initializing global options struct
o.showLegend = true o.legendLabels = {'data points','not-a-knot', 'clamped'} o.legendX = 263 o.legendY = 180 overlay({s,p1,p2},o)
References
[1] C. de Boor, "A Practical Guide to Splines", Springer-Verlag, 1978.