Skip to main content
1-Visitor
April 24, 2013
Question

Mathcad Precision problem

  • April 24, 2013
  • 2 replies
  • 8537 views

I have stumbled upon what seems to be a serious precision error with Mcad. As shown in the attached worksheet, I implemneted a function to calculate the stirling number of the second kind (S2). The stirling number of the second kind is the number of ways to partition a set of n objects into k non-empty subsets. When n=k the answer should be 1; so S2(10,10) = 1 and S2(100,100)=1. However, I found that I only get correct results for small values up to n = 25. Above that I get all kinds of errors. See the attached worksheet.

2 replies

25-Diamond I
April 24, 2013

Thats really bad looking and I like the way you investigated to trap the problem.

But numerical evaluations are afflicted with numerical inaccuracies by nature - while I wouldn't have believed it to be that bad, so I can understand you call it an error/bug, but probably it isn't.

Anyway - you get the correct results if you use the symbolic evaluation:

symbolsterling.png

1-Visitor
April 25, 2013

Thanks for the reply.

Yes, the symbolic evaluation can be used to get the correct answers; However, because of the limitations associated with the symbolic processor, it's not of much use for the problem I'm working on which requires manipulating and ploting 2D functions that have the sterling function incorporated within it.

It would be nice if Mathcad had an option that would increase the internal precision for numerical evaluations.

25-Diamond I
April 25, 2013

Look at the attached. This modified function S2 will not behave exactly like a normal numeric function in all situations, but maybe you can benefit from it nonetheless.

1-Visitor
April 26, 2013

I've written a program that calculates n! to whatever precision you need up to 400!

The attached program outlines the method that can be expanded to even larger factorials.

25-Diamond I
April 26, 2013

Interesting approach - didn't you post a similiar sheet for calculation of pi a while ago?

How would you apply that method here to construct a function S2 with enough precision which is numerically useable also for plotting (mine isn't) as the poster demanded?

1-Visitor
April 26, 2013

Yes, it borrows multiplication from the pi calculation.

That worksheet has addition, subtraction, multiplication, and division methods for very large numbers.

I can re-post it here or someone can look it up. It may be useful for this problem.