Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Team,
Does anyone have a Mathcad Prime routine to calculate the unsigned Stirling numbers of the first kind?
Thanks,
Glen Atlas, MD
@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.
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
Added an iterative function which builds a table of values.
The speed gain is significant - its about 3000 times faster.
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
Here's another version:
NB ORIGIN is the default value of 0 in the above.