1
$\begingroup$

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.
$\endgroup$
2
$\begingroup$

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
$\endgroup$
  • 1
    $\begingroup$ 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? $\endgroup$ – joojaa Jan 13 '14 at 19:25
  • $\begingroup$ 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]]. $\endgroup$ – Widjet Mar 9 '15 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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