View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

Be the first to rate this file! 3 Downloads (last 30 days) File Size: 2.51 KB File ID: #38597 Version: 1.1




16 Oct 2012 (Updated )

Stirling number(s) of the second kind.

| Watch this File

File Information

Stirling number of the second kind is the number of ways to partition a set of n objects into k non-empty subsets and is denoted by S(k,i). Stirling numbers of the second kind occur in the field of mathematics called combinatorics and the study of partitions. In short words, it is the number of ways to distribute k distinguishable elements into I indistinguishable receptacles with no receptacle empty.

Stirling numbers of the second kind is one of two kinds of Stirling numbers, the other kind being called Stirling numbers of the first kind, are the coefficients of powers of x in the polynomials [eg. Q(x)=(x-1)*(x-2)*...*(x-n)].

It is called as it after the British mathematician James Stirling (1692-1770).

In statistics, it is used in calculate (deriving) raw moments (non-central) in some discrete distributions as Geometric, Binomial, Negative Binomial, and Poisson, in a way that simplify the usual method of deriving raw moments of higher order of an integer-valued random variable by differentiate the generating function as many times as the order of the moment requires.

They can be calculated using the following explicit formula:

S(k,i) = 1/i! * i=0_Sum_r * (-1)^(r-i) * rCi * i^k

where 0 =< r =< k and k are any non-negative integer. rCi, combination i from r.

Here we develp the m-file to generate the Stirling number of the second kind. It is considered more informative than the previous m-files generated before in this MCFEX such as by Nikollaus Lorrell (13-11-2006) and Luca (11-03-2011). This for it gives, not only a specific Stirling number of second kind, but also (by default) the complete k partition.

Syntax: function x = nstir2k(a,b)
a - set of n objects
b - i non-empty subsets

x - Stirling number(s) of the second kind

Required Products MATLAB
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
30 Jan 2013 Franck Dernoncourt

nstir2k(100 , 100) = -1.7403e+37
Should be equal to 1.

Comment only
17 Oct 2012 1.1

It was added an appropriate format to cite this file.

Contact us