Why is it so fast to calculate one-dimensional cubic Spline interpolation through matlab?

21 views (last 30 days)
I learned that the Time complexity of one-dimensional cubic Spline interpolation is at least n ^ 2. I implemented the algorithm through C++and solved System of linear equations through LU decomposition, but obviously the computation is too much!
But why does MATLAB quickly solve for data interpolation of 10 million?
Did you use any acceleration methods?

Accepted Answer

Bruno Luong
Bruno Luong on 12 Jul 2023
Edited: Bruno Luong on 12 Jul 2023
"I learned that the Time complexity of one-dimensional cubic Spline interpolation is at least n ^ 2"
What is n?
There is two distinc steps in spline interpolation, (1) estimate the cubic coefficients from each subinterval of the pp form. (2) Find where the query points are in which intervals then evaluate the 3rd cubic polynomial.
The first step is O(N) with N is number of X-Y, as it requires mainy solving a tridiagonal matrix where the complexity is linear to the size.
The second step is O(M*log(N)) if searching using dichotomy method, where M is number of query points. MATLAB can detect also if the knot points are equidistance and use simply a division to find the interval (I don't know if such optimization is implemented in INTERP1), but that brings the complexity to O(M).
In any case O(n^2) you read is NOT optimal for spline.
  6 Comments
Bruno Luong
Bruno Luong on 13 Jul 2023
"If LU decomposition is used to solve x, then the Time complexity is about O (n ^ 3) (not the n ^ 2 I mentioned earlier"
BTW this figure of complexity must be your (wrong) conclusion, not the book-ref whatever you read. The LU on tridiagonal matrix is O(N), since the Thomas algorithm is actually based on LU.
The key difference is that if ones knows the shape of the input matrix to be decomposed one can stops the loop of LU during the decomposition much earlier. Essentially with this small but important observation the LU becomesThomas algorithm.
Lesson: don't draw a hasty conclusion.
澳旋
澳旋 on 14 Jul 2023
After a deeper understanding, it is indeed my fault!
LU can stop running as soon as possible to make it more efficient!
Thank you again for your enthusiastic reply!

Sign in to comment.

More Answers (0)

Categories

Find more on Spline Postprocessing in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!