/usr/share/freemat/toolbox/poly/roots.m is in freemat-data 4.0-5.
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 34 35 36 37 38 39 40 41 42 | % ROOTS ROOTS Find Roots of Polynomial
%
% Usage
%
% The roots routine will return a column vector containing the
% roots of a polynomial. The general syntax is
%
% z = roots(p)
%
% where p is a vector containing the coefficients of the polynomial
% ordered in descending powers.
% Copyright (c) 2002-2007 Samit Basu
% Licensed under the GPL
function z = roots(p)
if(any(isnan(p) | isinf(p)))
error('Input to ROOTS must not contain NaN or Inf.');
end
if (isempty(p))
z = zeros(0,1,class(p));
return;
end
while(any(isinf(p./p(1))))
p=p(2:end);
end
if (numel(p) <= 1)
z = zeros(0,1,class(p));
return;
end
p = vec(p);
n = numel(p)-1;
o = ones(n-1,1);
if (isa(p,'single'))
o = single(o);
end
A = diag(o,-1);
A(1,:) = -p(2:n+1)./p(1);
s = eig(A);
[n,m] = sort(-abs(s));
z = s(m);
|