Returns the k-th Lagrange cardinal polynomial for the given nodes Input arguments: nodes, the interpolation nodes k, integer specifying one of the nodes Output arguments: L, symbolic variable of the Lagrange polynomial
0001 function L = Lagrangecardinal( nodes,k ) 0002 % Returns the k-th Lagrange cardinal polynomial for the given nodes 0003 % Input arguments: 0004 % nodes, the interpolation nodes 0005 % k, integer specifying one of the nodes 0006 % Output arguments: 0007 % L, symbolic variable of the Lagrange polynomial 0008 0009 [n,m]=size(nodes); % finding the size of nodes 0010 if m~=1; 0011 error('input needs to be a column vector'); 0012 elseif mod(k,1)~=0 || k<=0 || k>n; % if k does not equal zero modulo 1 0013 % then it is not an integer value and it has to 0014 % specify a valid index 0015 error('input must specify a valid index'); 0016 end 0017 syms x; % create a symbolic variable 0018 syms L; % initialize symbolic variable to hold kth lagrange polynomial 0019 L=1; % set to unity 0020 for j=1:n; 0021 if j==k; 0022 % do nothing 0023 else 0024 L=L*(x-nodes(j))/(nodes(k)-nodes(j)); % add another term to 0025 % the product 0026 end 0027 end