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"];
D[
  D[
   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:

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

I there a way to make this happen.

Notes:

  • 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"];
D[
  D[
   Sin[p] (m),
   Quantity[p, "Seconds"]] ,
  Quantity[p, "Seconds"]] // Expand //nonQuantitiesAsMagnitudes
share|improve this answer
1  
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 at 19:25

Your Answer

 
discard

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.