Code covered by the BSD License  

Highlights from
Negative binomial series

from Negative binomial series by Antonio Trujillo-Ortiz
binomial,negative binomal,Newton's binomial,binomial theorem

negbins(x,y,n)
function [s,c] = negbins(x,y,n)
%NEGBINS Negative binomial series.
% This m-file gives the expansion of powers of sums of any real or complex
% numbers x and y, and any negative integer n. In 1676 Newton showed that
% the binomial theorem also holds for negative integers n, which is the
% so-called negative binomial series and converges for |x| < y. From this
% emerges the negative binomial distribution, a discrete probability
% distribution. The formulation is as,
%                    
%                   _inf
%                  \             (n+k-1)!
%     (x + y)^-n = /_    (-1)^k  -------- x^k y^(-n-k)
%                    k=0         k!(n-1)!
%
% 
% Syntax: function negbins(x,y,n) 
%      
%     Input:
%          x,y - pair of interested terms to expand
%            n - coefficient/power to increase the binomial theorem (it is
%            a negative integer that file automatically gives)
%     Output:
%          result of the negative binomial series sum
%          vector of the negative binomial series (optional)
%
% Example: For x=2, y=1, n=3
%
% Calling on Matlab the function: 
%             [s,c]=bintheor(2,1,3)
%
%  Answer is:
%
%  s = -61.0000
%
%  c = 1.0000   -6.0000   24.0000  -80.0000
%
% Created by A. Trujillo-Ortiz, R. Hernandez-Walls, K. Barba-Rojo
%            and N. Nunez-Valencia
%            Facultad de Ciencias Marinas
%            Universidad Autonoma de Baja California
%            Apdo. Postal 453
%            Ensenada, Baja California
%            Mexico.
%            atrujo@uabc.mx
% Copyright. November 13, 2008.
%
%  To cite this file, this would be an appropriate format:
%  Trujillo-Ortiz, A., R. Hernandez-Walls, K. Barba-Rojo and 
%    N. Nunez-Valencia. (2008). negbins:Negative binomial series. A MATLAB file.
%    [WWW document]. URL http://www.mathworks.com/matlabcentral/fileexchange/
%    loadFile.do?objectId=22086
%
% Reference:
% M. Abramowitz and Stegun, I.A. (1972), Handbook of Mathematical
%      Functions with Formulas, Graphs, and Mathematical Tables. 
%      9th printing. New York:Dover, pp. 14-15.
%

if  nargin < 3
    error('TooFewInputs:NEGBINS requires three input arguments.');
end

n = abs(n);

c = [];
for i =0:n,
    ni = gammaln(n + i) - gammaln(i + 1) - gammaln(n);
    lni = i.*log(-1) + ni + i.*log(x) + (- n - i).*log(y);
    yi = exp(lni);
    c = [c yi];
    c = real(c);
end

s = sum(c);

return

Contact us at files@mathworks.com