tkmcgov (Customer) asked a question.

Wet Bulb Calc in Do-More Designer MATH

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.


  • HOST_franji1 (HOST Engineering)

    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) 

     

     

    Expand Post
    Selected as Best
  • HOST_franji1 (HOST Engineering)

    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) 

     

     

    Expand Post
    Selected as Best
  • RBPLC (Customer)

    I fought the ** power issue for about two hours one time.

  • HOST_franji1 (HOST Engineering)

    Technically, C/C++ do not support ** as raised-to-power - they have a function, e.g. pow(2.0, 0.5). But a lot of algebraic equations are written with raised to power as a binary operator (e.g. 2.0 ^ 0.5), which is still XOR in C/C++. But we decided to "meet in the middle" and support the binary operator version to more closely match algebraic expression, vs a "programming language function" implementation.

     

    BASIC I think uses ** as raised-to-a-power, so we ran with that for the token text (since C/C++ does not have a token for that binary operator).

     

    Some other potential "gotchas" in C/C++ Do-more MATH grammar (these are all binary operators in Do-more MATH except for = ):

    & vs. &&

    | vs. ||

    >> vs. >>>

     

    and invalid/valid

    = vs. ==

    <> vs. !=

     

    and a not-so-obvious MATH function

    []

    i.e. array index expression is allowed in both the Result parameter AND in the Expression parameter, e.g.

    R[V0 * 42 + V1]

    will simulate a 2D array where a row has 42 columns (so the column range is 0..41), where V0 is the row# and V1 is the column number.

    Expand Post
  • tkmcgov (Customer)

    Thank you - per your edits I am now getting the correct result.

    • Isomorphic (Customer)

      would you please share your working formula? I've been trying to get this to work as well and have hit a brick wall.

  • Isomorphic (Customer)

    I currently have the following: Temp F * atan(0.151977 * (Humidity  + 8.313659))^(3.0/2.0) + atan(Temp F  + Humidity ) - atan(Humidity  - 1.676331) + 0.00391838 *(Humidity )^(3.0/2.0) * atan(0.023101 * Humidity ) - 4.686035

     

    i'm getting a result of 27453 when my Temp F is 34 and humidity is 92

     

    I should also note this is in Productivity 2000 Series MATH function

    Expand Post
    • adccommunitymod (AutomationDirect)

      Please start a new thread under the Productivity topic with your question. This will keep from hijacking the original thread. Thanks.

    • tkmcgov (Customer)

      As noted the issue is the ^ needs to be **. My final formula in the ladder is:

       

      ((((RX5 * ATAN(0.151977 * ((RX4 + 8.313659) ** (1.0 / 2.0)))) + ATAN(RX5 + RX4)) - ATAN(RX4 - 1.676331)) + (0.00391838 * (RX4 ** (3.0 / 2.0)) * ATAN(0.023101 * RX4))) - 4.686035

  • HOST_franji1 (HOST Engineering)

    See the accepted answer detailing the grammar used by Do-more (based on C, C++, Java, et. al.) where ^ is the XOR operator. ** is the Raised to a Power operator.