/usr/share/freemat/toolbox/poly/polyfit.m is in freemat-data 4.0-5build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | % POLYFIT POLYFIT Fit Polynomial To Data
%
% Usage
%
% The polyfit routine has the following syntax
%
% p = polyfit(x,y,n)
%
% where x and y are vectors of the same size, and
% n is the degree of the approximating polynomial.
% The resulting vector p forms the coefficients of
% the optimal polynomial (in descending degree) that fit
% y with x.
% Copyright (c) 2002-2006 Samit Basu
% Licensed under the GPL
function p = polyfit(x,y,n)
x = x(:);
y = y(:);
if (size(x,1) ~= size(y,1))
error('size mismatch on arguments to polyfit - they should be the same size');
end
if (n < 0 | n > 200)
error('invalid polynomial order in polyfit - must be between [1,200] inclusive');
end
A = zeros(size(x,1),n+1);
xp = x*0+1;
for i=(n+1):-1:1
A(:,i) = xp;
xp = xp.*x;
end
p = (pinv(A)*y)';
|