sg_coefficients.m 394 Bytes
function C = sg_coefficients(n, order)

if(mod(n, 2) == 0)
    disp('The number of coefficients must be odd');
    return;
end

%assemble the column vector based on positions
r = floor(n/2);         %maximum extent around zero (0)
x = -r:1:r;

%calculate J
J = zeros(n, order + 1);

%columns values are 1, x_i, x_i^2, ...
for i = 1:order+1
    J(:, i) = (x').^(i-1);
end
C = (J' * J)^(-1) * J';