Using spline as an interpolating function

1 次查看(过去 30 天)
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?

采纳的回答

Matt J
Matt J 2015-8-7
编辑:Matt J 2015-8-7
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)')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Splines 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by