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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Mathcad operation

NA_11204287
4-Participant

Mathcad operation

Hi all, 

 

As shown in the attached image,when tf=0.055 is equal to tf.min=0.055, the results should be "OK" since tf must be bigger or equal to tf.min as stated in the if statement

 

NA_11204287_1-1726736941620.png

 

does anyone know why the calculation does not capture the equal sign and produce an "OK" output when the value of tf and tf.min are equal??

Thank you in advance.

ACCEPTED SOLUTION

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

Prime possibly is correct. Let the two vectors display with more than 3 decimals and I guess you would see that second entry in the first vector is slightly smaller than the corresponding element in the second vector.

If this does not matter for you because the values still are within an acceptable tolerance, lets say 10^-4, you could use t.f>=t.min-10^-4 instead of t.f>=t.min.

BTW, I guess it would be better to get rid of the third range argument "i." and call the check function vectorized. That way the result would be a true vector and not an invalid object which only can be displayed but not assigned to a variable.

Werner_E_0-1726741573056.png

 

If you need to use that kind of check more often in a sheet and don't like to have to vectorize the call every time, you may also do it that way:

Werner_E_1-1726742023814.png

As we can't vectorize the if-function directly it was necessary to use a local function f.

 

An alternative approach (as opposed to the tolerance variable) is to actually round the values in both vectors to the desired precision:

Werner_E_2-1726742515003.png

Personally I would not prefer that approach, though.

 

View solution in original post

3 REPLIES 3

Never test for equality with floating point numbers.  Set an acceptable tolerance level (e.g. tol = 10^-6) then replace the if test by something like :

 

if(abs(tf - tmin) >= tol, "OK", "NOT OK")

 

 

Werner_E
25-Diamond I
(To:NA_11204287)

Prime possibly is correct. Let the two vectors display with more than 3 decimals and I guess you would see that second entry in the first vector is slightly smaller than the corresponding element in the second vector.

If this does not matter for you because the values still are within an acceptable tolerance, lets say 10^-4, you could use t.f>=t.min-10^-4 instead of t.f>=t.min.

BTW, I guess it would be better to get rid of the third range argument "i." and call the check function vectorized. That way the result would be a true vector and not an invalid object which only can be displayed but not assigned to a variable.

Werner_E_0-1726741573056.png

 

If you need to use that kind of check more often in a sheet and don't like to have to vectorize the call every time, you may also do it that way:

Werner_E_1-1726742023814.png

As we can't vectorize the if-function directly it was necessary to use a local function f.

 

An alternative approach (as opposed to the tolerance variable) is to actually round the values in both vectors to the desired precision:

Werner_E_2-1726742515003.png

Personally I would not prefer that approach, though.

 

Hi @NA_11204287,


I wanted to see if you got the help you needed.


If so, please mark the appropriate reply as the Accepted Solution. It will help other members who may have the same question.
Please note that industry experts also review the replies and may eventually accept one of them as solution on your behalf.


Of course, if you have more to share on your issue, please pursue the conversation.

Thanks,

Catalina
PTC Community Moderator
Announcements

Top Tags