4
$\begingroup$

I am trying to calculate precise values for certain expressions, see the image below. enter image description here

The output testZPF of the function $\Delta$Fn should be a single output. I am trying to understand why Mathematica does not provide me with a single number in fully simplified units (here the dimension of the result is $[m]$), but instead prints the result in units of $c$ and $\hbar$.

Edit

For the dimensions, I tried to use UnitConvert, but get an error here. The error is very strange as the result should have indeed dimensions $[m^{-1}]$. enter image description here

Edit 2

Here is the code:

\[Omega] = 
 2 Pi*Quantity[1, 
   "SpeedOfLight"]*(1/Quantity[735, "Nanometers"] - 
    1/Quantity[900, "Nanometers"])
Subscript[m, red] = Quantity[6, "AtomicMassUnit"]
Subscript[h, bar] = Quantity[1, "ReducedPlanckConstant"]

\[Del]Fn[\[Omega]_, m_] := Sqrt[Subscript[h, bar]/(\[Omega]*m)]
testZPF = \[Del]Fn[\[Omega], Subscript[m, red]]
UnitConvert[testZPF, "Meters"^(-1)]
$\endgroup$
5
  • $\begingroup$ You have all integers and symbolic numbers (\[Pi]) in your equations. Mma uses infinite precision in these cases. You can move to machine precision by following your integers with a decimal; e.g. 1. instead of 1. This makes them machine precision reals and you'll get reals in the output. $\endgroup$
    – Edmund
    Mar 20, 2022 at 13:36
  • $\begingroup$ Ok, but what about the dimensions? How can I simplify them? I tried to use UnitConvert, but got an error. See edit to question above. $\endgroup$ Mar 20, 2022 at 13:41
  • 2
    $\begingroup$ Welcome to Mathematica StackExchange. Please, provide your code as a copy-paste text, not as a screenshot. Furthermore, check UnitSimplify. $\endgroup$
    – Domen
    Mar 20, 2022 at 13:41
  • $\begingroup$ @Domen Thanks, I added the code and still have the same problem. $\endgroup$ Mar 20, 2022 at 13:55
  • 2
    $\begingroup$ First of all, do not use character ∇ as part of the symbol name as it gets interpreted as Del[...]. Secondly, as I have proposed, use UnitSimplify and you will get the result in picometres. Thirdly, you can use UnitConvert[testZPF, "Meters"]. $\endgroup$
    – Domen
    Mar 20, 2022 at 13:59

1 Answer 1

9
$\begingroup$
Clear["Global`*"]

ω = 
  2 Pi*Quantity[1, 
    "SpeedOfLight"]*(1/Quantity[735, "Nanometers"] - 
     1/Quantity[900, "Nanometers"]);
Subscript[m, red] = Quantity[6, "AtomicMassUnit"];
Subscript[h, bar] = Quantity[1, "ReducedPlanckConstant"];

∇Fn[ω_, m_] := Sqrt[Subscript[h, bar]/(ω*m)]
testZPF = ∇Fn[ω, Subscript[m, red]]

enter image description here

Using the default conversion ("SIBase")

UnitConvert[testZPF]

enter image description here

Using other unit systems may not convert all constants

{#, UnitConvert[testZPF, #]} & /@ {"Conventional", "Imperial", 
  "Metric", "SI", "SIBase"} // Grid[#, Frame -> All] &

enter image description here

You can convert to any compatible unit, i.e., a distance

UnitConvert[testZPF, # <> "meters"] & /@ 
  {"centi", "milli", "micro", "nano", "pico"}

enter image description here

As pointed out by Domen

UnitSimplify[testZPF]

enter image description here

$\endgroup$

Your Answer

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

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