To support @awkward, I have cut and paste a Matlab code that computes the probability values; it is consistent in solution with inputs p = 0.9, r = 20, and n = 100 with the solution provided by awkward. I removed my help menu so the formatting does not interfere with the paste.
function pr = fellerconsecPdf(p,r,n)
d = [size(p(:),1), size(r(:),1), size(n(:),1)];
id = setdiff( unique(d), 1);
if(numel(id) > 3/2)
erorr('MATLAB:fellerconsecPdf.m: non-scalar inputs must match in size');
end
m = max( d );
p = repmat(p(:), m - (size(p(:),1)-1), 1);
r = repmat(r(:), m - (size(r(:),1)-1), 1);
n = repmat(n(:), m - (size(n(:),1)-1), 1);
if(isscalar(p))
q = (1 - p);
c = zeros(r+2,1);
c(1) = q.*(1 - q).^r;
c(r+1) = -1;
c(r+2) = 1;
xsol = roots(c);
xsol = xsol( abs(imag(xsol)) < eps );
xsol = xsol(xsol>0);
[~,ii] = max( abs(xsol - 1./p) );
x = xsol(ii);
else
q = (1 - p);
x = [];
for k = 1:length(r)
c = zeros(r(k)+2,1);
c(1) = q(k).*(1 - q(k)).^r(k);
c(r(k)+1) = -1;
c(r(k)+2) = 1;
xsol = roots(c);
xsol = xsol( abs(imag(xsol)) < eps );
xsol = xsol(xsol>0);
[~,ii] = max( abs(xsol - 1./p(k)) );
x = cat(1,x,xsol(ii));
end
end
pr = ( (1 - p.*x)./((r + 1 - r.x).(1-p)) ).x.^(-1(n + 1));
return;
Please not that star-dot-star does not show up in the text correctly, but it should be clear from context that that I intend point-wise multiplication of vectors.