% POLYELECTRON finds the polynomial on the left-hand side of Eq. (7) of
% L{\"o}fgren and Gunell Phys. Plasmas, vol. 4, 3469-3476 (1997). The
% right-hand side of that equation is 0.
%
% P = POLYELECTRON(UHPpole, UHPresid, C)
%
% UHPpole:     the poles of the distribution function in the upper half plane
% UHPresidues: residues of those poles of the distribution function that
%              are in the upper half plane
% C:           a constant that should be equal to k^2. 
%
% P:           the polynomial that is the output of this function

function P = polyelectron(UHPpole,UHPresid,C)
n=length(UHPpole);
fullpoly=poly(UHPpole);
fullpoly=conv(fullpoly,fullpoly); %% Double roots

P = C*fullpoly;
for ii=1:n
  temp = deconv(fullpoly, poly(UHPpole(ii)));	%Polynomial division
  temp = deconv(temp    , poly(UHPpole(ii)));	%Polynomial division
  P    = P - 2i*pi*UHPresid(ii)*[0 0 temp];
end
