2% BARYCENTRICINTERP returns the barycentric interpolation weights given a
3% set of interpolation nodes
4%
5% interpWeights = barycentricInterp(interpNodes, npts, xval)
6% returns barycentric interpolation weights given 'interpNodes', a vector
7% of size 'npts' containing interpolation nodes, and 'xval', a value where
8% the barycentric interpolating polynomial is evaluated
10% if nargin == 0, test_barycentricInterp; return; end
12% Precompute barycentric interpolation factors
13X=repmat(interpNodes,1,npts);
14w = 1./prod(-X+X.'+eye(npts),1);
16tol = 1.0e-20;
17xvalminusInterpNodes = xval - interpNodes';
18rr = prod(xvalminusInterpNodes);
20interpWeights = rr*w./(xvalminusInterpNodes);
21interpWeights(abs(xval - interpNodes')<tol) = 1;
23end
25% function test_barycentricInterp
26% clf;
27% ax = 0; bx = 1;
28% npts = 6;
29% interpNodes = linspace(ax,bx,npts);
30%
31% xval = (bx-ax)*rand + ax;
32% interpWeights = barycentricInterp(interpNodes, npts, xval);
33%
34% bar(interpWeights);
35% title(sprintf(['Interpolation weights\n for %d equidistant interpolation...' ...
36% ' nodes\n in [%1.0f,%1.0f] evaluated at x = %1.2f'],npts,ax,bx,xval));
37%
38% end