I believe you can vectorize this for loop also. I wrote a function to compute the Lagrange polynomial before, you could refer to it in http://www.mathworks.com/matlabcentral/fileexchange/36522-compute-the-value-of-lagrange-polynomial-at-given-points/content/lagrangePolyVal.m 