Using spline as an interpolating function

1 view (last 30 days)
ts = linspace(-10,10,1024);
fs = func(t);
Lets say I do not have access to func. Normally I can't use f as a function, so to do this I use
f = @(t)spline(ts,fs,t);
Which works just fine, but I couldn't find much information on the time complexity.
How many points in fs does spline use to interpolate at a single point? I hope it isn't more than I few. What is the general complexity of the function?
Any better way to achieve what I'm trying to do?

Accepted Answer

Matt J
Matt J on 7 Aug 2015
Edited: Matt J on 7 Aug 2015
How many points in fs does spline use to interpolate at a single point? I hope it isn't more than I few. What is the general complexity of the function?
The interpolation at a given t makes use of all ts(i) and fs(i), which is why the test code below produces a linear increase in the execution time as a function of N=length(fs), even when interpolating at a single point only. However, the test code also shows that if you make a vectorized call to spline() at multiple t(i), the computational expense is amortized. You can see in the plot that execution time does not increase significantly with length(t). So, as long as you call f(t) on vectorized batches of t, you should be fine.
j=0;
Nrange=1e4:1e4:1e5;
for L=[1,100]
j=j+1; k=0;
for N=Nrange
k=k+1;
fs=1:N;
ts=fs;
f = @(z)spline(ts,fs,z);
t=(1:L)+.3;
tic
f(t);
T(j,k)=toc;
end
end
plot(Nrange,T(1,:),'--',Nrange,T(2,:),'-.')
legend('Evaluations=1','Evaluations=100')
xlabel('Length fs')
ylabel('Execution Time (sec)')

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!