How to find the matlab interp1 computational complexity?

조회 수: 9 (최근 30일)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 10월 26일
댓글: Kai Angermueller 2025년 4월 9일
Hi,
I am trying find the computational complexity of interp1 with 'linear', and "cubic". Can I get some help regarding this?
I am thinking it is O(n) and O(n^3). Are these correct?
  댓글 수: 1
Bruno Luong
Bruno Luong 2023년 10월 26일
"Are these correct?"
No, O(n^3) is completely off (over estimated), see my answer. Also you don't tell what n is.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2023년 10월 26일
편집: Bruno Luong 2023년 10월 26일
If N is the number of data points (x, y), M is the query points (xq)
interp1(x, y, xq, ...)
has complexity of O(M*log(N)) for all methods, if x is sorted.
Essentially it is the time of query where xq are located in subintervals. Time of interpolation value are constant per point even for spline method.
If x is not sorted then you need to add log(N) of sorting but then the O notation remains the same
  댓글 수: 7
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2023년 11월 2일
편집: Kalasagarreddi Kottakota 2023년 11월 2일
Just a query about log(N): is the time required to identify which bin a point lies in.
Does in matlab, or every operation, does log(N) exists?. Like for example, I have a discrete signal p(n), with n=1,...,N. Now lets say I advance by a constant n0 samples, like p(n+n0) for all samples in signal p. Does in matlab, the complexity is O(N) as it is addition complxeity applied for N samples or O(N*log(N))?
Kai Angermueller
Kai Angermueller 2025년 4월 9일
if you actually try running interp1 with various N and tic/toc the run time, you'll find it's actually O(M*N) for sorted :( This is terrible. It's also strange that it's O(M*N) whether you are searching for xq near the bottom end of x, the middle, or near the top end of x. So it's not just doing a linear serach. But it's also not scaling like any sort of binary/tree search. Strange and bad.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by