Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.7K Views
|
1 Reply
|
1 Total Like
View groups...
Share
Share this post:

Avoid results with unexpected units with FindRoot and ThermodynamicData?

Posted 9 years ago
POSTED BY: Robert McHugh

Robert,

There appears to be a bug in the way FindRoot handles units. I would report this.

This works:

In[1]:= FindRoot[Quantity[6, "ft"] == x, {x, Quantity[4, "in"]}]

Out[1]= {x -> Quantity[1.8288, "Meters"]}

but this does not:

In[6]:= FindRoot[
 Quantity[6, "ft"] == x, {x, Quantity[4, "in"], Quantity[400, "in"]}]

Out[6]= {x -> Quantity[10.16, ("Meters")^2]}

I generally avoid using units in expression handling as the results I've observed have been unpredictable. Your problem can be solved by doing this:

In[2]:= func[x_Real] := 
 QuantityMagnitude[
  ThermodynamicData["Water",  "Enthalpy", {"Pressure" -> p0, 
    "Temperature" -> Quantity[x, "DegreesFahrenheit"]}]]

In[11]:= FindRoot[QuantityMagnitude[h0] == func[tx], {tx, 900., 1100.}]

Out[11]= {tx -> 1000.}

Note that the x_Real pattern is necessary because I found that FindRoot calls the expression with symbols and numbers (I guess that it tries to first solve things analytically). If you do not protect the function by only letting it get called with Real numbers, you get the correct answer with warning messages like this:

ThermodynamicData::quant: tx is not a real number.

Regards

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard