You can get rid of the ThermodynamicData::quant
error by keeping ThermodynamicData
from evaluating when p
is symbolic by wrapping it in a ?NumericQ
-protected function.
See
"How do I use ?NumericQ to affect order of evaluation?";
more examples on Stackexchange here.
You can get rid of the FindRoot::jsing
error by avoid methods that use derivatives, such as the Secant Method, which is automatically invoked if you use two starting points. This makes sense because ThermodynamicData
does not return an expression that can be symbolically differentiated.
One issue that arose for me is that ThermodynamicData
occasionally timed out, which caused FindRoot
to throw an error.
pressure[s_Real, t_Real] := Module[{p, obj},
obj[p_?NumericQ] :=
QuantityMagnitude[
ThermodynamicData["CarbonDioxide",
"Entropy", {"Temperature" -> Quantity[t, "DegreesCelsius"],
"Pressure" -> Quantity[p, "Megapascals"]}]];
sol = FindRoot[s == obj[p], {p, 13, 12.5}];
p /. sol]
pressure[2209., 2.]
(* 1.00249 *)