I am having some difficulties when using UnitSimplify in manipulating expressions for obtaining dimensionless quantities in Mathematica 12.0.0. Here is a minimal example showing the difficulty:

  Quantity[10, "Joules"^(-1)] 
   (Quantity[20, "Joules"] r^2 + 
    Quantity[30, "Gigapascals" ("Picometers")^(3/2)] Sqrt[d^2 Quantity[40, "Liters"] +  
    f^2 Quantity[50, "Liters"]])]

The UnitSimplify appears to do nothing above. To solve this difficulty, I have worked out the unit conversion factor for turning "Gigapascals" ("Picometers")^(3/2) into "Joules"^(1) "Liters"^(-1/2). Then I applied a rule.

% /. Quantity[x_, "Gigapascals" ("Picometers")^(3/2)] -> 
         Quantity[x, "Gigapascals" ("Picometers")^(3/2)], 
         "Joules"^(1) "Liters"^(-1/2)]

Now that I can see that the units cancel, I can just take the magnitudes and find the dimensionless expression.

My question is: can this replacement rule be made more general to avoid working out unit conversion factors every time I come up with a dimensionless expression?


1 Answer 1


Mathematica is assuming that your variables r, d and f are quantities with dimensions, and so it gives up. If you tell Mathematica that they are unitless quantities, then it will work:

    Quantity[10,"Joules"^(-1)] *
        Quantity[20,"Joules"] Quantity[r,"Unities"]^2 +
        Quantity[30,"Gigapascals" ("Picometers")^(3/2)] *
            Quantity[d,"Unities"]^2Quantity[40,"Liters"] +
            Quantity[f,"Unities"]^2 Quantity[50,"Liters"]

10 ((3 Sqrt[40 d^2 + 50 f^2])/(1000000000 Sqrt[10]) + 20 r^2)

  • $\begingroup$ Thanks! I take it that "Unities" is the unit for dimensionless quantities. $\endgroup$
    – Ferca
    Jun 24, 2020 at 17:49
  • $\begingroup$ I think you can also use "DimensionlessUnit". $\endgroup$
    – chuy
    Jun 24, 2020 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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