I have a hunch that this is a straightforward variant of similar questions regarding how functions are evaluated by Plot, but this case has me stumped. Let's say I want to produce a plot of the density of water as a function of temperature. So I define
DensWater[temp_] :=
ThermodynamicData["Water", "Density",
{"Temperature" -> Quantity[temp, "DegreesCelsius"]}]
I can call this function with any value for T such as DensWater[25.0]
and I receive a result with an attached unit as expected. However, when I try to plot this function using
Plot[DensWater[T], {T, 10., 65.}]
I get ThermodynamicData::quant: T is not a real number.
I did try various ways to get this resolved, but somehow can't get the Plot
command to work without giving error messages. What's the trick?
P.S.: Just to be clear, the Plot
command does provide a plot in the end, I'm just surprised by the error message.
Update:
The above is just a minor annoyance, but if I define a function of two variables, say pressure and temperature like so:
DensAir[T_, p_] :=
ThermodynamicData["Air", "Density",
{"Temperature" -> Quantity[T, "DegreesCelsius"], "Pressure" -> Quantity[p, "Pascals"]}]
and try to plot this using Plot3D
, I get an empty plot. When plotting 2D slices of the above function using Plot
this function works as above (with error messages, but giving a plot).