function polynomial = lagrange_interp(X,Y,x) // ===================================================== // Lagrange Polynomial Interpolation // ===================================================== // X : interpolation points // Y : value of f(X) // x : points where we want an evaluation of P(x), // where P is the interpolator polynomial // ===================================================== // // Author: Manolo Venturin // http://www.openeering.com // This code is released under a Creative Commons // Attribution - NonCommercial - NoDerivs 3.0 Unported License. // // Adapted to Scilab from the MATLABŪ examples presented // in Prof. Parviz Moin book // "Fundamentals of Engineering Numerical Analysis" // available at http://numerics.stanford.edu/ n = length(X); phi = ones(n,length(x)); polynomial = zeros(1,length(x)); // Construct table of differences for i = 1:n for j = 1:n if i~=j then phi(i,:) = phi(i,:) .* (x-X(j)) ./ (X(i)-X(j)); end end end for i = 1:n polynomial = polynomial + Y(i)*phi(i,:); end endfunction