Skip to content

stirling2

specfun · scripts/specfun/stirling2.m

: s = stirling2 (n, k)

Stirling numbers of the second kind.

stirling2 (N, K) returns the number of ways to partition a set of n objects into exactly k non-empty unlabeled subsets. Both n and k must be real non-negative integer scalars. The result is 0 when k > n (except S(0,0) = 1).

Output class follows nchoosek: double by default, single if either argument is single, or the common integer class when both arguments share one.

Behaviour note (MATLAB R2026a): stirling1 / stirling2 are not shipped by MathWorks in R2026a. Values match the classical combinatorial table (stirling2 (4, 2) == 7, stirling2 (5, 2) == 15).