필터 지우기
필터 지우기

Using spline as an interpolating function

조회 수: 1 (최근 30일)
htrh5
htrh5 2015년 8월 7일
편집: Matt J 2015년 8월 7일
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