Difference between spline(x,y,xq) and interp1(x,y,xq,'spline')
5 views (last 30 days)
Show older comments
Mohammad Shojaei Arani
on 5 Jun 2022
Commented: Bruno Luong
on 5 Jun 2022
Hello friends,
I have a simple question. I am wondering what is the difference between the commands spline(x,y,xq) and interp1(x,y,xq,'spline'). They
should do the same job but they strongly differ from each other by their different execution times. interp1(x,y,xq,'spline') is way faster. I
have some codes which are computationally expensive. So, if I use the command interp1(x,y,xq,'spline') then I can reduce the computational time greatly.
Do spline(x,y,xq) and interp1(x,y,xq,'spline') differe in their accuracies? I hope interp1(x,y,xq,'spline') is more accurate but I guess that spline(x,y,xq) is more accurate since in this world nothing is for free!
Thanks in advance,
Babak
0 Comments
Accepted Answer
More Answers (1)
Bruno Luong
on 5 Jun 2022
spline is a MATLAB file that build the intermediate piecewise polynomial then evalutae it (in your case).
INTERP1 call an internal low-level implementation, perhaps no need the intermediate pp strcuture. Thus it is just faster. There is no accuracy penalty.
Both has matlab wrapper, you can follow with the debugger.
5 Comments
Bruno Luong
on 5 Jun 2022
They could, but there are also many reasons why they keep it that way :
- to warranty consistency results in 2-step and 1-step call of spline
- to have the same code less dependant the rest, which is also good source mainenace, for not breaking things wespecially hen one forget what depends on what.
If was them I don't make any cross call like what tey decide to do.
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!