Can ThermodynamicData be used with NSolve?
Restrict the argument of f
to numeric values:
Clear[f]
f[t_?NumericQ] := QuantityMagnitude @ ThermodynamicData[
"Water",
"Enthalpy",
{"Pressure"->Quantity[1,"Bars"], "Temperature"->Quantity[t,"DegreesCelsius"]}
]
Then, you can just use FindRoot
:
FindRoot[f[t] == 300000, {t, 50}]
{t -> 71.6414}
How about generating an interpolation over the expected range and use FindRoot like so?
f = Interpolation@
Table[{t,
QuantityMagnitude@
ThermodynamicData["Water",
"Enthalpy", {"Pressure" -> Quantity[1, "Bars"],
"Temperature" -> Quantity[t, "DegreesCelsius"]}]}, {t, 1,
99}];
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@
Table[{QuantityMagnitude@
ThermodynamicData["Water",
"Enthalpy", {"Pressure" -> Quantity[1, "Bars"],
"Temperature" -> Quantity[t, "DegreesCelsius"]}], t}, {t, 1,
99, 10}];
tofh[300000]
(* 71.6414 *)