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

**URL:** <https://community.wolfram.com/t/find-pressure-corresponding-to-an-entropy-s-and-temperature-t/12277>\
**Category:** Questions\
**Tags:** physics, curated-data, equation-solving, units\
**Created:** [April 7, 2018, 12:34pm UTC](https://community.wolfram.com/t/find-pressure-corresponding-to-an-entropy-s-and-temperature-t/12277 "2018-04-07T12:34:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlsonengineer](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@carlsonengineer](https://community.wolfram.com/u/carlsonengineer)\
**Post date:** [April 7, 2018, 12:34pm UTC](https://community.wolfram.com/t/find-pressure-corresponding-to-an-entropy-s-and-temperature-t/12277/1 "2018-04-07T12:34:41Z")

</div>

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]

```

---

<div class="post-metadata">

**Author:** ![anon21378091](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@anon21378091](https://community.wolfram.com/u/anon21378091)\
**Post date:** [April 7, 2018, 2:28pm UTC](https://community.wolfram.com/t/find-pressure-corresponding-to-an-entropy-s-and-temperature-t/12277/2 "2018-04-07T14:28:27Z")

</div>

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?”](http://support.wolfram.com/kb/12502);  
more examples on Stackexchange [here](https://mathematica.stackexchange.com/questions/18393/what-are-the-most-common-pitfalls-awaiting-new-users/26037#26037).

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 *)

```

---

<div class="post-metadata">

**Author:** ![carlsonengineer](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@carlsonengineer](https://community.wolfram.com/u/carlsonengineer)\
**Post date:** [April 7, 2018, 10:50pm UTC](https://community.wolfram.com/t/find-pressure-corresponding-to-an-entropy-s-and-temperature-t/12277/3 "2018-04-07T22:50:36Z")

</div>

Excellent explanation. Thank you also for the links.
