Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Would it be possible to get Mathematica to group units more sanely. For example the calculation:

m = Quantity["Meters"];
   Sin[p] (m),
   Quantity[p, "Seconds"]] ,
  Quantity[p, "Seconds"]] // Expand

This gives an visual output:

(-1 m/s^2) Sin[p]

however it would be more natural to show:


I there a way to make this happen.


  • Expand is strictly not necessary in this case but can nice be in more complex cases.
share|improve this question

1 Answer 1

up vote 1 down vote accepted

These seem to work

m = Quantity[#, "Meters"] &;
D[D[Sin[p] // m, Quantity[p, "Seconds"]], 
  Quantity[p, "Seconds"]] // Expand

Or you transform by hand

nonQuantitiesAsMagnitudes[expr_] := 
 expr /. x_ Quantity[y_, unit_] :> Quantity[x y, unit]

m = Quantity["Meters"];
   Sin[p] (m),
   Quantity[p, "Seconds"]] ,
  Quantity[p, "Seconds"]] // Expand //nonQuantitiesAsMagnitudes
share|improve this answer
Yeah that's it. Still think that Mathematicas syntax for units is atrocious. My engineering students seem to come up with hives about this. But i think they can live with this. What does the &; do? –  joojaa Jan 13 '14 at 19:25
Terribly late reply, but & makes the preceding term into a pure function, while the ; ends the statement and suppresses output. This means you can use m as a function, where # represents the first argument: m[1] would evaluate to Quantity[1,"Meters"]. The // in the second line is a postfix function application, so the m is used as m[Sin[p]]. –  Widjet Mar 9 at 6:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.