![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177957/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177957/image.jpeg)
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!