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

Newbie

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.

17 REPLIES 17

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:

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.

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.

Your file has extension .xmcdz which doesn't open with Mathcad 14. Can you post it as .xmcd or as a PDF file.

Hmm, there is no difference in file format between MC14 and MC15 AFAIK and MC14 should be able to open xmcdz-files.

Anyway, here it is in xmcd and MC11 mcd format.

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.

In (my) MathCad 11.2 the definition of S2() fails with an error message of: 'This variable of function is not defined above.'

It appears it cannot evaluate the combin() function symbolically, only numerically.

"combin(3,1)=3"

"combin(3,1)->" produces an 'Unknown error.'

S2_detail() fails to produce the table, it lacks a statement to return A.

When I add a 'return A' to that function, it produces a table, and then the expression following "producing the error" results in '1' (which IS equal to the required 1!, isn't it?). No sorry, it returns 0.999868247598799; is that close enough?

Luc

 "combin(3,1)->" produces an 'Unknown error.'

You may try using numbcomb(3,1) instead or replace by the definition using factorials.

The problem with S2(), with its symbolic eval definition and problematic numeric representation reminds me of this thread: http://communities.ptc.com/message/197737#197737

Also the big differences between MC11 and newer versions seem to be covered there.

Highlighted