Let's say I define a function giving the enthalpy of water:

f[t_]:=QuantityMagnitude@ThermodynamicData["Water","Enthalpy",{"Pressure"->Quantity[1,"Bars"], "Temperature"->Quantity[t,"DegreesCelsius"]}]

I'd like to use that to find out what temperature corresponds to a given enthalpy:


But this gives me no result. Is there a way to do it?


Restrict the argument of f to numeric values:

f[t_?NumericQ] := QuantityMagnitude @ ThermodynamicData[
    {"Pressure"->Quantity[1,"Bars"], "Temperature"->Quantity[t,"DegreesCelsius"]}

Then, you can just use FindRoot:

FindRoot[f[t] == 300000, {t, 50}]

{t -> 71.6414}

  • $\begingroup$ Interesting. I had tried that with NSolve but it didn't work, so I assumed it wouldn't work with FindRoot either. $\endgroup$ – Whelp May 16 '19 at 15:23

How about generating an interpolation over the expected range and use FindRoot like so?

f = Interpolation@
       "Enthalpy", {"Pressure" -> Quantity[1, "Bars"], 
        "Temperature" -> Quantity[t, "DegreesCelsius"]}]}, {t, 1, 
FindRoot[f[t] - 300000, {t, 50}]
(* {t -> 71.6414} *)

Also, if you are just interested in having temperature as a function of enthalpy, you could transpose the table and avoid FindRoot all together.

tofh = Interpolation@
       "Enthalpy", {"Pressure" -> Quantity[1, "Bars"], 
        "Temperature" -> Quantity[t, "DegreesCelsius"]}], t}, {t, 1, 
     99, 10}];
(* 71.6414 *)
  • $\begingroup$ That's a method I've been considering. I was worried it might be very slow. $\endgroup$ – Whelp May 16 '19 at 14:45
  • $\begingroup$ The database call is the slowest part. Once the table is populated, the interpolations are very fast. $\endgroup$ – Tim Laska May 16 '19 at 14:47
  • $\begingroup$ I'll accept and give it a try. Given that behind the hood it's just calling a database, I doubt it can be made much more efficient than that. $\endgroup$ – Whelp May 16 '19 at 14:50
  • $\begingroup$ If you are only interested in the liquid phase region, you need very few points. If you are near the boiling point, you may need a lot of points to capture the transition. I got the same answer when I stepped by 10 degrees. $\endgroup$ – Tim Laska May 16 '19 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.