/usr/share/freemat/toolbox/poly/polyder.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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | % POLYDER POLYDER Polynomial Coefficient Differentiation
%
% Usage
%
% The polyder function returns the polynomial coefficients resulting
% from differentiation of polynomial p. The syntax for its use is either
%
% pder = polyder(p)
%
% for the derivitave of polynomial p, or
%
% convp1p2der = polyder(p1,p2)
%
% for the derivitave of polynomial conv(p1,p2), or still
%
% [nder,dder] = polyder(n,d)
%
% for the derivative of polynomial n/d (nder is the numerator
% and dder is the denominator). In all cases the polynomial
% coefficients are assumed to be in decreasing degree.
% Contributed by Paulo Xavier Candeias under GPL
function [pder1,pder2] = polyder(p1,p2)
if nargin < 1 | nargout > nargin
error('wrong use (see help polyder)');
end
if (nargin == 1)
% Simple derivative case
n = numel(p1);
if (n <= 1)
pder1 = 0;
return;
end;
x1 = (p1(:).').*(n-1:-1:0);
x1 = x1(1:end-1);
pder1 = polyder_trim_zeros(x1);
if (isa(p1,'single'))
pder1 = single(pder1);
end
return;
end
f1 = conv(p1,polyder(p2));
f2 = conv(polyder(p1),p2);
m = max(numel(f1),numel(f2));
f1 = [zeros(1,m-numel(f1)),f1(:).'];
f2 = [zeros(1,m-numel(f2)),f2(:).'];
if (nargout < 2)
pder1 = polyder_trim_zeros(f1+f2);
else
pder1 = polyder_trim_zeros(f1-f2);
pder2 = polyder_trim_zeros(conv(p2,p2));
end;
if (isa(p1,'single'))
pder1 = single(pder1);
end
function y = polyder_trim_zeros(x)
if (isempty(x) | isempty(find(x,1)))
y = 0;
else
y = x(find(x,1):end);
end
|