With the following code block, I plot a function with units in it in two different ways. Both ways should do the same in my understanding of the documentation.
cm = Quantity["Centimeters"];
f[x_] := Sqrt[x + 5 cm]
Plot[Evaluate@{f[zz cm]}, {zz, -5, 5}]
Plot[Evaluate@{f[zz]}, {zz, -5 cm, 5 cm}]
Plot[Evaluate@{Sqrt[zz]}, {zz, -5 cm, 5 cm}]
Can anyone explain why it does that?
Sqrt[x+5]
and the units shouldn't play a role for plotting. (I'm working on a physics problem with a more complicated formula, but there I basically have the pythagorean theorem, so it would beSqrt[x^2+(5cm)^2]
) $\endgroup$f[zz cm]
givesSqrt[zz*Quantity[1, "Centimeters"] + Quantity[5, "Centimeters"]]
. This gives us the "good" plot. Notice that the units are explicit in both terms. On the other hand,f[zz]
givesSqrt[zz + Quantity[5, "Centimeters"]]
. This gives us the "bad" plot. I wonder if not knowing what units zz will be in is confusing the Plot function. I don't know if this should be expected or not. $\endgroup$f[x_] := 3 (x + 5 cm)
. Similar issue occurs, but it shows (I think) that theQuantity[5, "Centimeters"]
is being ignored/dropped in the second plot. I think Plot must be trying to pre-compute its plotting function, and that 5cm is somehow not being interpreted correctly within that expression. I'm just making noise--we need someone with more expertise/knowledge. $\endgroup$