# [?] Find pressure corresponding to an entropy (s) and temperature (t)?

Posted 3 years ago
3991 Views
|
2 Replies
|
2 Total Likes
|
 This function is supposed to return the pressure corresponding to an entropy (s) and temperature (t).Instead the function just returns the initial guess in FindRoot. What's wrong?Thanks. pressure[s_Real, t_Real] := Module[{p}, sol = FindRoot[ s == QuantityMagnitude[ ThermodynamicData["CarbonDioxide", "Entropy", {"Temperature" -> Quantity[t, "DegreesCelsius"], "Pressure" -> Quantity[p, "Megapascals"]}]], {p, 13}]; p /. sol] 
2 Replies
Sort By:
Posted 3 years ago
 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 *)