How to find the matlab interp1 computational complexity?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kalasagarreddi Kottakota
am 26 Okt. 2023
Kommentiert: Kai Angermueller
am 9 Apr. 2025
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 Kommentar
Bruno Luong
am 26 Okt. 2023
"Are these correct?"
No, O(n^3) is completely off (over estimated), see my answer. Also you don't tell what n is.
Akzeptierte Antwort
Bruno Luong
am 26 Okt. 2023
Bearbeitet: Bruno Luong
am 26 Okt. 2023
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 Kommentare
Kai Angermueller
am 9 Apr. 2025
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!