4
$\begingroup$

Is it possible for MMA to convert natural unit (particle physics), for example, $1 eV^{-1}$ wavelength, to about $2\times 10^{-7}m$? I think the key is to tell MMA it's a length unit but I don't see how.

$\endgroup$
  • $\begingroup$ Divide by hbar*c. I.e. q / (Quantity[1, "ReducedPlanckConstant"*"SpeedOfLight"]) $\endgroup$ – b3m2a1 Nov 29 '17 at 8:01
  • $\begingroup$ eV$^{-1}$ is not wavelength, it is inverse energy. But you probably want to convert the energy to the wave-length of photon having such energy. $\endgroup$ – yarchik Nov 29 '17 at 11:05
  • $\begingroup$ It is wavelength in natural units, where $c = \hbar = 1$, and lengths are measured in units of $\text{energy}^{-1}$. $\endgroup$ – dpravos Nov 29 '17 at 13:38
8
$\begingroup$

A few months ago I wrote a function that converts from SI to natural units. A quick way to achieve the inverse conversion is to convert your target units, meters, to natural units to get about 5e6 1/eV. Then divide your wavelength in 1/eV by 5.07e6 to get the number of meters. Of course, it has to work with other units besides 1/eV and meters.

Conversion from SI to natural units

Here is a function that takes a SI quantity and converts it to natural units, which are always eV to some power.

ClearAll[toNaturalUnits]
toNaturalUnits[q_Quantity] := 
 Block[{α, β, γ, δ, ϕ, χ,
   c2 = Quantity["SpeedOfLight"]^2,
   ℏ = Quantity["ReducedPlanckConstant"],
   ℏc = Quantity["ReducedPlanckConstant"] Quantity["SpeedOfLight"], 
   kB = Quantity["BoltzmannConstant"],
   ϵ0 = Quantity["ElectricConstant"]},
  χ = UnitDimensions[q];
  {α, β, γ, δ, ϕ} = \
{FirstCase[χ, {"LengthUnit", α_} -> α],
    FirstCase[χ, {"MassUnit", β_} -> β],
    FirstCase[χ, {"TemperatureUnit", γ_} -> γ],
    FirstCase[χ, {"TimeUnit", δ_} -> δ],
    FirstCase[χ, {"ElectricCurrentUnit", ϕ_} -> ϕ]};
  {α, β, γ, δ, ϕ} = {α, β, γ, δ, ϕ} /. Missing[_] -> 0;
  UnitConvert[
   q  ℏc^(-α + ϕ/2)  ℏ^-δ  c2^(β - ϕ/2)  kB^γ  (4 π ϵ0)^(-ϕ/2) ,
   "Electronvolts"^(-α - δ + β + γ + ϕ)]
  ]
toNaturalUnits[q_List] := Map[toNaturalUnits, q]

Here are some common test cases. In each case, the result should be about 1 eV raised to the appropriate power.

{Quantity[389.4 10^12, "Barns"],
    Quantity[0.19733, "Micrometers"],
    Quantity[0.6582, "Femptoseconds"],
    Quantity[1.78266 10^-36, "Kilograms"],
    Quantity[85.43, "Millivolts"],
    Quantity[1519.27, "Terahertz"],
    Quantity[8.12 10^-13, "Newtons"],
    Quantity[432.9, "Volts"/"Millimeters"],
    Quantity[7.318 10^10, "Amperes"/("Meters")^2]} // toNaturalUnits //
   Round[#, 0.001] & // Column

Conversion from natural units to SI units

This is a rough draft/prototype of a function that takes a quantity q and some target SI unit and returns a quantity in those SI units. The first quantity is assumed to be in units of energy to some power. The second argument is assumed to be a string, like "Meters", or a product of units, like "Newtons"/"Meters". The second argument of fromNaturalUnits will be used as the second argument of the Quantity function, so whatever Quantity recognizes as a valid unit and is compatible with the first argument should be okay. Here is the function that converts from natural units to your target units,

ClearAll[fromNaturalUnits]

fromNaturalUnits[q_Quantity, unit_] := Block[{
   natTarget, natQ, ratio},
  natTarget = toNaturalUnits[Quantity[1, unit]];
  natQ = toNaturalUnits[q];
  ratio = natQ/natTarget;
  If[TrueQ[QuantityUnit[ratio] == "DimensionlessUnit"],
   Quantity[ratio, unit],
   "error message"]
  ]

fromNaturalUnits[q_?NumericQ, unit_] := Block[{
   natTarget, ratio}, {
   natTarget = toNaturalUnits[Quantity[1.0, unit]],
   ratio = q/natTarget,
   If[TrueQ[QuantityUnit[ratio] == "DimensionlessUnit"],
    Quantity[ratio, unit],
    "error message"]
   }
  ]

Two versions of fromNaturalUnits were necessary because sometimes the natural unit is dimensionless. This function has not be extensively tested, but here is an example of how it works with MMA quantities:

m = Quantity["ElectronMass"];
nat = toNaturalUnits[m]
fromNaturalUnits[nat, "Kilograms"]

(*  510998.9 eV
    9.109384*10^-31 kg  *)

Here is the speed of light:

fromNaturalUnits[1.0, "Meters"/"Seconds"]
(*  2.99792*10^8 m/s  *) 

Here are conversions from various powers of an eV. Notice that sometimes Quantity will accept abbreviations like eV and MeV, but not powers of the abbreviations

fromNaturalUnits[Quantity[1.0, ("Electronvolts")^-2], "Barns"]
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^-1], "Micrometers"]
fromNaturalUnits[
 Quantity[1.0, ("Electronvolts")^-1], "Femptoseconds"]
fromNaturalUnits[Quantity[1.0, "MeV"], "Kilograms"]
fromNaturalUnits[Quantity[1.0, "eV"], "Millivolts"]
fromNaturalUnits[Quantity[1.0, "Electronvolts"], "Terahertz"]
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^2], "Newtons"]
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^2], 
 "Volts"/"Millimeters"]
fromNaturalUnits[Quantity[1.0, ("Electronvolts")^3], 
 "Amperes"/("Meters")^2]

Finally, what's up with that "error message"? Well, if the arguments are incompatible, we get the error message. For example, try to convert 1 eV to seconds.

$\endgroup$
  • $\begingroup$ In your fromNaturalUnits function, what's target in the end? I think it should be unit. $\endgroup$ – Turgon Nov 30 '17 at 8:54
  • $\begingroup$ @Turgon Yes! Good catch. I corrected the code 2 places. Many thanks. $\endgroup$ – LouisB Nov 30 '17 at 9:30

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.