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?
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Splines についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!