Unit conversion is not simplifying units

I'm running into what looks like an error.

<< PhysicalConstants;
fieldGradient = Quantity[10,  "Teslas"/"Meters"] (* Tesla/meter *)
Energy = Quantity[100, "MegaElectronVolts"]
K = fieldGradient*SpeedOfLight*ElectronCharge/Energy (* m^-2 *)


K should have the units of meters^-2, but Mathematica insists on the output:

(Coulomb Meter (Quantity[4.8032*10^-12, ("Teslas")/("Megaelectronvolts" "Meters")]))/Second


Am I using the Units wrong here? This is my first try at using the Units package in Mathematica 9.

• Please define SpeedOfLight and ElectronCharge such that the example is self-contained. – C. E. Dec 19 '14 at 22:01
• Done, sorry, I forgot the PhysicalConstants package. – webb Dec 19 '14 at 22:03

In v10, the PhysicalConstants package isn't required.

\$Version


"10.0 for Mac OS X x86 (64-bit) (December 4, 2014)"

Use UnitConvert to put all units into SI units

fieldGradient = UnitConvert[Quantity[10, "Tesla/Meter"]];

Energy = UnitConvert[Quantity[100, "MegaElectronVolts"]];

UnitConvert[Quantity["SpeedOfLight"]]*
UnitConvert[Quantity["ElectronCharge"]]/
Energy


Quantity[29.97925, 1/("Meters")^2]

or

fieldGradient = Quantity[10, "Tesla/Meter"];

Energy = Quantity[100, "MegaElectronVolts"];


• I assume that if you give it mixed units that it doesn't try to guess what unit system you want and leaves the units as is. Since you stated that you expect the output in 1/meters^2 then SI is presumably what you what. That is the default for UnitConvert. However, you could use //UnitConvert[#,"Imperial"]& and get the output in 1/Inches^2`. – Bob Hanlon Dec 20 '14 at 21:40