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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Translate the entire conversation x

max( ) works and min( ) doesn't ?

lvl107
20-Turquoise

max( ) works and min( ) doesn't ?

  Hello, Everyone.

  From :

(1).PNG

  So the question is : Is there a reason for : " max(  ) works and min(  ) doesn't " ?

       Thanks in advance for your time and help.

              Best Regards.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:AlanStevens)

Ah, I did not realize that it depends on the first item in the vector.

Anyway, that behaviour sure is not as it should be and we may call it a bug.

But I am not sure how I would like min or max to behave. Normally in Mathcad, whenever a calculation encounters a NaN, it returns NaN as result. So for consistency min and max should return NaN in the examples above. On the other hand I guess it would not do any harm and would be convenient if those functions would simply ignore the NaN's - just like my filterNaN workaround.

Based on your information we can provide another workaround by simply putting + or - infinity at the front. But both workarounds will only work for vectors and must be modified slightly differently for row and column vectors.

View solution in original post

8 REPLIES 8
Werner_E
25-Diamond I
(To:lvl107)

Both, max and min, work OK the same way. NaN simply is interpreted as zero.

You may use filterNaN to get what you expect:

AlanStevens
19-Tanzanite
(To:Werner_E)

min works as expected as long as the first item in the vector is not NaN.  Also works ok if the first item is NaN and the minimum is less than zero.

max has the same problem if all the terms, other than NaN, are negative.

Alan

Werner_E
25-Diamond I
(To:AlanStevens)

Ah, I did not realize that it depends on the first item in the vector.

Anyway, that behaviour sure is not as it should be and we may call it a bug.

But I am not sure how I would like min or max to behave. Normally in Mathcad, whenever a calculation encounters a NaN, it returns NaN as result. So for consistency min and max should return NaN in the examples above. On the other hand I guess it would not do any harm and would be convenient if those functions would simply ignore the NaN's - just like my filterNaN workaround.

Based on your information we can provide another workaround by simply putting + or - infinity at the front. But both workarounds will only work for vectors and must be modified slightly differently for row and column vectors.

lvl107
20-Turquoise
(To:Werner_E)

   Many thanks, Werner and Alan.

        Regards.  

StuartBruff
23-Emerald IV
(To:Werner_E)

I was searching for other threads that mentioned problems with the min function and found this thread.  Out of idle curiosity, I emulated the indicated "problem" in Mathcad Express 11.

 

2025 10 21 B.png

 

As filterNaN is a Premium feature, I had to implement an Express version.  I chose to do this via a general filter function.

 

2025 10 21 C.png

 

Which I then used to provide substitutes for mean, var, stdev, sort, min, and max.

 

I chose to sort NaNs to the end of the sorted vector, as this seems to be the preferred method used by a number of other mathematical and general programming languages.

 

2025 10 21 D.png

 

Stuart

Werner_E
25-Diamond I
(To:lvl107)

Based on Alans observation concerning the first item in a vector here are some Min/Max replacement with one and two arguments which ignore NaN's and also can be used vectorized.

LucMeekes
23-Emerald IV
(To:lvl107)

For what it's worth: Mathcad 11.

The error message for stdev is: "Encountered a floating point error.".

Luc

Werner_E
25-Diamond I
(To:LucMeekes)

Thanks - so it was still not as consequent as we would  like it to be, but at least the outcome did not depend on the first item of the vector.

BTW, in Mathcad 15 stdev returns NaN, which I consider a better way to deal with the NaN in the vector.

Announcements

Top Tags