I'm having trouble with numerically evaluating some functions. The problem essentially comes down to
Log[Quantity[3, "Meters"]] - Log[Quantity[2, "Kilometers"]]
The above code doesn't evaluate to a numerical answer even though it should since $$ \log(3\ {\rm m}) - \log(2\ {\rm km}) = \log \left(\frac{3\ {\rm m}}{2\ {\rm km}} \right)=\log\left(\frac 3{2000}\right)$$ Is there a way to get mathematica to automatically combine the logs of unitful quantities?
EDIT:
Note the following:
Log[ Quantity[3, "Meters" ] / Quantity[2, "Kilometers"] ]
(* -Log[2000/3] *)
Simplify[ Log[a] - Log[b], b > 0]
(* Log[a/b] *)
Simplify[ Log[ Quantity[3, "Meters"] ] - Log[ Quantity[2, "Kilometers"] ] ]
(* Log[ 3 m ] - Log[ 2 km ] *)
Log[QuantityMagnitude@Quantity[3, "Meters"]] - Log[QuantityMagnitude@Quantity[2, "Kilometers"]] // N
could be a workaround. $\endgroup$UnitConvert
, i.e.,Log[QuantityMagnitude@Quantity[3, "Meters"]] - Log[QuantityMagnitude@UnitConvert@Quantity[2, "Kilometers"]] // N
$\endgroup$Log[Quantity[3, "Meters"]] - Log[Quantity[2, "Kilometers"]] /. Log[a_] - Log[b_] :> Log[a/b]
$\endgroup$Log[ Quantity[3, "Meters"] ]
is undefined. The first example is unrelated becauseQuantity[3, "Meters"]/Quantity[2, "Kilometers"]
evaluates to a number. So the question is comparing the logarithm of a number with logarithms of distances. $\endgroup$