;cubic spline interpolation
; generate a dataset
n = 5
m = 100
t = 1:n
tnew = 1:m
xnew = tnew/m-1/m
x = t/n-1/n
y = cos(10*x)
yold = cos(10*xnew)
func = xnew~yold
d = x~y
; interpolate the data y
ynew = spline(x,y,xnew,0)
; plot the data
; the uderlying function is shown by a dashed black line
; cubic spline interpolation is a blue line
; linear interpolation is a red line
dnew = xnew~ynew
results = createdisplay(2,1)
setmaskl(d,t',4,1,2)
setmaskp(d,4,3,10)
setmaskl(dnew,tnew',1,1,3)
setmaskp(dnew,1,0,1)
setmaskl(func,tnew',0,4,2)
setmaskp(func,1,0,1)
show(results,1,1,d,dnew,func)
setgopt(results,1,1,"title","cubic spline interpolation")
;
;adaptive smoothing
; generate the dataset
n = 50
m = 100
vr = 1.0
t = 1:n
tnew = 1:m
xnew = tnew/m-1/m
x = t/n-1/n
y = cos(10*x) + 3*x
;add Gaussian white noise to the data
randomize(1234567)
data = y + vr*normal(n)
d = x~y
ndata = x~data
; call the adaptive cubic spline smoother(lambda < 0.0)
ynew = spline(x,data,xnew,-10)
; plot the data
; the uderlying function is shown by a black dashed line
; adaptive estimator is a blue line
; input data are red crosses
dnew = xnew~ynew
setmaskl(d,t',0,4,2)
setmaskp(d,0,0,10)
setmaskl(ndata,t',3,1,1)
setmaskp(ndata,4,11,8)
setmaskl(dnew,tnew',1,1,4)
setmaskp(dnew,1,0,1)
show(results,2,1,d,dnew,ndata)
setgopt(results,2,1,"title","adaptive spline smoothing")