
Last chance! 50% off unlimited learning
Sale ends in
This function computes Stirling numbers of the second kind,
Stirling2(n, k)S2(n, k)
An vector of Stirling numbers of the second kind
A vector of one or more positive integers
A vector of one or more positive integers
S2()
: Compute Stirling numbers of the second kind
James Curran
The implementation on this function is a simple recurrence relation which
defines n
and n
have different lengths then expand.grid
is used to construct a vector of (n, k) pairs
https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind#Recurrence_relation
## returns S(6, 3)
Stirling2(6, 3)
## returns S(6,1), S(6,2), ..., S(6,6)
S2(6, 1:6)
## returns S(6,1), S(5, 2), S(4, 3)
S2(6:4, 1:3)
Run the code above in your browser using DataLab