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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Usage of NaN in calculations

Manfred_F
6-Contributor

Usage of NaN in calculations

Every function, which is called with an argument of NaN should deliver NaN as a result !

Some functions deliver odd values such as log, ln, or ln0. Very problematic are the functions min and max which deliver min(NaN)=0 and max(NaN)=0. This can lead to incorrect results, as it was the case in our calculations. This error occured with Prime 8.

Prime8_minmaxNaN.gif

 

 

9 REPLIES 9
ttokoro
20-Turquoise
(To:Manfred_F)

Prime 9 also.

image.pngimage.png

So, we should do.

image.pngimage.pngimage.pngimage.png

But, if image.pngthen alsoimage.png


@ttokoro wrote:

 

So, we should do.

image.pngimage.pngimage.png

 


This does not help much as it still fails if NaN is the first entry of the vector!

Werner_E_0-1691572521372.png

 

 

LucMeekes
23-Emerald III
(To:Manfred_F)

Sorry to say, but this is behaviour as designed; according to the Help information on NaN in "About the NaN (Not a Number) Built-In Constant":

"... A NaN can only be processed by functions specifically written to use it. Other functions may return errors or incorrect results if passed a NaN."

After all, it's PTC sofware.

 

Mathcad 11 gives:

LucMeekes_0-1691527236336.png

Success!
Luc

Manfred_F
6-Contributor
(To:LucMeekes)

Hi Luc,

did you try this on Prime8:

Prime8_logNaN.gif

Manfred

The bug (or unexpected and undesired result, as its behavior according to the help) with "min" and "max" is already present in Mathcad, so we can blame PTC only for not fixing it.

Werner_E_1-1691572974962.png

What we can blame PTC for is for making it even worse as your example with the logs showed

Werner_E_2-1691573066793.png

I am surprised that the imaginary part is pi. Would expect at least an integer multiple of 2 pi !?

Here is the same in MC15

Werner_E_3-1691573100074.png

Here is something "nice", too

Werner_E_4-1691573625027.png

Note that NaNi and also the number in the exponent are labeled as "Unit" ????

In MC15 this still was OK

Werner_E_5-1691573703956.png

 

Even though the help states that using functions on NaN may give wrong results, you may consider opening a ticket at PTC support and report this bug and/or demand that this undesirable behavior should be changed.

 

 

ttokoro
20-Turquoise
(To:Manfred_F)

Using vector M, Edit: Without NaN fix.

image.pngimage.pngimage.png

image.pngimage.pngimage.png

Which results do you get when you use a vector without any NaN's? 😉

 

EDIT: AH, I see that you have editted your post and fixed your functions to deal correctly with that case 😄 

Manfred_F
6-Contributor
(To:Werner_E)

I would expect that min() or max() filters out the NaN and calculates then min/max from the rest. If there is no value left (all values are NaN) then the result should be NaN. I tried several combinations and it seems to depend on the sign and position of NaNs:

Prime8_minmaxNaN2.gif

LucMeekes
23-Emerald III
(To:Manfred_F)

 

It looks as though it checks vectors on NaN's only for the first element, and when found, the NaN is replaced with a 0; scalar NaN in min() and max() is replaced with a 0 as well. NaN's appearing elsewhere in the vector are discarded.

LucMeekes_0-1691588719899.png

Fortunately NaN is retained in other functions, one way or another...

It's a bug.

May be (remotely?) related to the bug in FilterNaN https://community.ptc.com/t5/Mathcad/Prime-bug-with-quot-filterNaN-quot/m-p/882956#M207191

 

Success!
Luc

Top Tags