# Converting Units in formula

I have the following formula

\[HBar] = hbar = (6.6260693*joule*sec)/(10^34*(2*Pi));

chp[Te_, ne_,
M_] := (1.3806505*(joule/kelvin)*Te*kelvin*
Log[1 - Exp[-((2*Pi*hbar^2*
ne*(10^11/(cm*cm)))/((4*M*9.1093826*kg*kelvin*
Te*1.3806505*(joule/kelvin))/(10^31*10^23)))]])/10^23

chp[50, 1, 0.5]

(* 6.90325*10^-22 joule Log[
1 - E^(-((5.55596*10^-6 joule sec^2)/(cm^2 kg)))] *)


My question is what is the best way to have an output that is in eV. Please note that the argument of the Exp is unitless...even though it is expressed in terms of cm, kg etc. So the output should only be in terms of eV.

• Have you looked into Quantity and UnitConvert? Nov 9, 2015 at 5:07
• Yes.....just how do you use them for this particular relation.....in a neat way. I can do it ...a bit messily Nov 9, 2015 at 5:12

You could do this using Quantity and UnitConvert, and defining your units beforehand.

kelvin = Quantity[1, "Kelvins"];
joule = Quantity[1, "Joules"];
\[HBar] = hbar = Quantity[1, "ReducedPlanckConstant"];
cm = Quantity[1, "Centimeters"];
kg = Quantity[1, "Kilograms"];
chp[Te_, ne_,
M_] := (1.3806505*(joule/kelvin)*Te*kelvin*
Log[1 - Exp[
UnitConvert[-((2*Pi*hbar^2*
ne*(10^11/(cm*cm)))/((4*M*9.1093826*kg*kelvin*
Te*1.3806505*(joule/kelvin))/(10^31*10^23)))]]])/10^23

UnitConvert[chp[50, 1, 0.5], "Electronvolts"]


results in

Quantity[-0.0125725, "Electronvolts"]

• Thks, I have modified my code to include "DimensionlessUnit"...this was what I was looking for...useful in calculations involving several related formulas. Nov 9, 2015 at 6:33
• @Michael Witt I had to wrap the argument of the exponent in the chp function with UnitConvert[-((2*Pi*hbar^2...] in order to get it to work. Nov 9, 2015 at 19:31
• @JackLaVigne Yeah, for some reason it ran when I tested it initially, but didn't run now. I've updated my solution to include the UnitConvert in the argument of the exponential. Nov 10, 2015 at 17:53

Found out that "DimensionlessUnit" would help greatly, so the code is

\[HBar] = hbar = (6.6260693*10^-34)/(2 \[Pi]); (* Joule*Second*)

chp1[Te_] :=
UnitConvert[Quantity[1.3806505*10^-23 Te, "Joule"],
Quantity["Electronvolts"]]

chp2[Te_, ne_, M_] :=
chp1[Te]*Log[1 - Exp[-UnitConvert[ Quantity[(2 Pi hbar^2  ne 10^11)/
(4 M 9.1093826*(10^-31) Te 1.3806505*(10^-23) ), "Joules"*"Seconds"^2
/("Centimeters"^2*"Kilograms")], Quantity["DimensionlessUnit"]]]]

chp2[50, 1, 0.5]
(* - 0.0125725 eV *)