cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Unsigned Stirling numbers of the first kind

gatlas
10-Marble

Unsigned Stirling numbers of the first kind

Team,

 

Does anyone have a Mathcad Prime routine to calculate the unsigned Stirling numbers of the first kind?

 

Thanks,

Glen Atlas, MD

3 REPLIES 3
Werner_E
25-Diamond I
(To:gatlas)


@gatlas wrote:

Team,

 

Does anyone have a Mathcad Prime routine to calculate the unsigned Stirling numbers of the first kind?

 

Thanks,

Glen Atlas, MD


I just gave it a try and my first idea was to use  a  program with a local symbolic evaluation.

I implemented it in Mathcad 15 and its quite fast when used with symbolic evaluation (it can't be evaluated numerically) but of course this method does not work in Prime.

 

My second way (function s1) was to use the recursion. This should work in Prime as well, but is prohibiting slow when evaluated symbolically.

Werner_E_1-1732598002390.png

My guess as of the error at the end is because the symbolics tries to evaluate/simplify the expression symbolically first before the value for n is used and as we know it does not can handle conditionals that way.

For signed Stirling numbers you simply use (1-n) instead of (n-1) for the first factor in the last line.

I guess that the function could be speeded up by building some kind of tree instead of recursively calculate the same values multiple times. But a simple recursion is much easier to program 😉

 

MC15 sheet attached

Werner_E
25-Diamond I
(To:Werner_E)

Added an iterative function which builds a table of values.

The speed gain is significant - its about 3000 times faster.

Werner_E_0-1732599361033.png

Using a slight modification you can also use this method to return the whole table of values similar to what is shown in Wikipedia -> Stirling numbers of the first kind

Werner_E_1-1732599996701.png

Here's another version:

StirlingNbrs.png

 

NB ORIGIN is the default value of 0 in the above.

Announcements

Top Tags