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

Mathcad Precision problem

Highlighted
Newbie

Mathcad Precision problem

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
Highlighted

Re: Mathcad Precision problem

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

Highlighted

Re: Mathcad Precision problem

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.

Re: Mathcad Precision problem

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.

Highlighted

Re: Mathcad Precision problem

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

Thanks in advance.

Highlighted

Re: Mathcad Precision problem

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.

Highlighted

Re: Mathcad Precision problem

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

Highlighted

Re: Mathcad Precision problem

"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

Re: Mathcad Precision problem

For a while there I thought you found what I am looking for. Using the symbolic processor does give accurate results now -thanks! But it can only be used as a scalar. What's strange is that when I'm calling the function now to setup an array, you see it doing all the calculations "live" in front of your eyes! ... but they are not saved in the array!

Highlighted

Re: Mathcad Precision problem

The files are

Announcements