
tkmcgov (Customer) asked a question.
I'm trying to use the MATH function to calculate wet bulb temperature based on temperature and RH (both analog inputs), using the formula:
Tw = T * arctan[0.151977 * (rh% + 8.313659)^(1/2)] + arctan(T + rh%) - arctan(rh% - 1.676331) + 0.00391838 *(rh%)^(3/2) * arctan(0.023101 * rh%) - 4.686035
However, I am unable to get the proper result, both when using the inputs directly (so using RX0 and RX1 which are my temp and humidity) or when using example numbers directly in the formula (such as 20 degC and 50 %RH). The formula with the example numbers is typed in MATH as:
20 * ATAN(0.151977*(50+8.313659)^(1/2)) + ATAN(20+50) - ATAN(50-1.676331) + 0.00391838*50^(3/2) * ATAN(0.023101*50) - 4.686035
I'm indicated PL1 for the result and getting a value of 65504. Per an online calculator (https://www.omnicalculator.com/physics/wet-bulb) 20degC and 50RH yield 13.7 wet bulb, and copying and pasting the same formula from MATH into wolfram alpha yield the correct result: https://www.wolframalpha.com/input?i=20+*+ATAN%280.151977*%2850%2B8.313659%29%5E%281%2F2%29%29+%2B+ATAN%2820%2B50%29+-+ATAN%2850-1.676331%29+%2B+0.00391838*50%5E%283%2F2%29+*+ATAN%280.023101*50%29+-+4.686035
Any idea what I am missing in the MATH function to get this to calculate properly?
Many thanks in advance.
The MATH instruction grammar is based on C/C++/Java/PHP so ^ is XOR. ** is raised-to-a-power.
Also, like C/C++/et. al. Integer Math is different than floating point math, so 3/2 (integers) is 1 (integer), not 1.5. 3.0/2.0 is 1.5. So all your ** raised-to-power values need to be (3.0/2.0).
For details on the MATH operators, see Help Topic DMD0085 or look here:
MATH - Calculate Expression (hosteng.com)