1

I'm trying to calculate the wet bulb temperature from dry bulb temp (dbt), relative humidity (rh) and pressure (p), so that I can monitor an air condition unit with a raspberry pi. I got the equation from a Research paper and it works fine and is fast when calculated in Matchcad Prime. When I try to get Python to solve the equation however, it just sits there without returning anything, while my CPU fan goes crazy until I cancel the terminal.

from sympy import symbols, Eq, solve

Td = 25
rh = 60
p = 1013

Tw = symbols('Tw')
Td = float(Td)
rh = float(rh)
p = float(p)
e = float(2.71828182845905)

eq1 = Eq(((6.112 * e**((17.502 * Tw) / (240.97 + Tw)) - 0.00066 * (1 + 0.00115 * Tw) * p * (Td - Tw)) / (6.112 * e**((17.502 * Td) / (240.97 + Td)))) * 100 - rh, 0)

result = solve(eq1, Tw)

temp_wet = round(result[Tw], 2)
print(f'Wet bulb temperature =  {temp_wet}')

I have also tried nsolve, but it didn't help, and after 9 hours I now give up and politely ask if anyone here can offer a possible solution.

Captain Jack Sparrow
  • 971
  • 1
  • 11
  • 28
Runenaldo
  • 13
  • 3

1 Answers1

0

nsolve is clearly the solution:

>>> nsolve(eq1, 20).round(2)
19.55
smichr
  • 16,948
  • 2
  • 27
  • 34
  • It works, thank you. Could you please explain me, or link to an explanation as to how substituting "Tw" with 20 works and what is means? I was under the impression that the second spot in a sympy solve function was for the "symbol" to solve for, so I'm a bit puzzled. – Runenaldo Apr 19 '20 at 06:44
  • The function here is `nsolve`, not `solve`. If you check `help(nsolve)` it will explain the expectations and give examples. – smichr Apr 19 '20 at 11:34