function p1 = polydiff(p,k)

% derivative of a polynomial

if nargin == 1
	k = 1;
end

if k > length(p)

p1 = [];

elseif k > 0

s = size(p);
p1 = p(:) .* [length(p)-1:-1:0]';

p1(length(p1)) = [];

if s(2) >  1
	p1 = p1';
end

k = k - 1;

p1 = polydiff(p1,k);

else

p1 = p;

end

