I have a multivariate scattered data. I tried using griddatan for interpolating at some unknown points and it worked. Now i wanted to get an Interpolating polynomial for the same. What code should I use and Does any one has an example to share. I am also attaching the my data file.
MATLAB: How to get the interpolating polynomial for multivariate scattered data
interpolating polynomial for multivariate scattered data
Related Solutions
Well, the simple answer is to not use interp1. Just use spline and then ppval.
The problem is that for a spline interpolant, every time you call interp1, it must effectively call spline inside on your data. By calling spline once, this makes it more efficient.
For example...
x = linspace(-1,1,100);y = exp(x);xev = rand(1,1000)*2 - 1;S = spline(x,y);timeit(@() interp1(x,y,xev,'spline'))ans = 0.0003005timeit(@() ppval(S,xev))ans = 0.00025177
Not as big of a difference as I thought it might be, but some.
You MIGHT also gain some time if you are willing to pre-interpolate the function to a finer interval, so that then you could do linear interpolation. Since linear interpolant will be faster to do, this should see some gain too.
x = linspace(-1,1,10);y = exp(x);xfine = linspace(-1,1,1000);yfine = interp1(x,y,xfine,'spline');xev = rand(1,1000)*2 - 1;timeit(@() interp1(x,y,xev,'spline'))ans = 0.00028546timeit(@() interp1(xfine,yfine,xev))ans = 0.00022313
You can also see some gain by using pchip instead of spline, as that is a faster way to build the spline, though sometimes not quite as smooth.
timeit(@() interp1(x,y,xev,'pship'))ans = 0.00026064
Finally I recall seeing some tools on the file exchange that tried to give a speedup for interp1, but they were mostly for linear interpolation.
Finally, while you could certainly use a mexfile to improve the time, that presumes that your skills are sufficient to write a spline interpolant, and to do so efficiently in C. I'm afraid that compiled MATLAB code would gain you nothing here.
That you can't find it is a good thing.
Lagrange interpolation is a nice thing for ONE purpose only: to teach students some basic ideas. What those teachers fail to followup with is that it is a bad thing to use when you really need to do interpolation. So then those students go into the world, and try to use it. Worse, then they want to do stuff like use it for 2-d interpolation. Don't do it. The idea has "bad" written all over it.
There are many schemes around for 2-d interpolation/modeling. Use one of them. Start with scatteredInterpolant, or you might use radial basis function interpolation (I recall it being on the FEX), or approximation tools like my gridfit (on the FEX), or neural nets. Or there is Kriging, or use splines.
Best Answer