I am trying to use quantities with physical units to calculate my result, but I encountered the "Incompatible units" problem. I don't know what is going on. Here is my code, could I have some second-opinions?

Convert[λ^2 Ins/(π ω ℏ) /. ω -> (
     2 π c)/λ /. ℏ -> h/(2 π) /. {Ins -> 
    51*10^-3 Watt/Centimeter^2, c -> SpeedOfLight, 
   h -> PlanckConstant, λ -> 369*10^-9 Meter}, Hertz]
  • $\begingroup$ Does your code work if you define your variables as Quantitys? I.e. \[Lambda] = Quantity[396*^-9,"Meter"] $\endgroup$ Commented Oct 11, 2022 at 19:21

2 Answers 2

UnitConvert[λ^2 Ins/(π ω ℏ) /. ω -> \
(2 π c)/λ /. ℏ -> h/(2 π) /. {Ins -> 
     Quantity[51*10^-3, "Watts"/("Centimeters")^2], 
    c -> Entity["PhysicalConstant", "SpeedOfLight"]["Value"], 
    h -> Entity["PhysicalConstant", "PlanckConstant"][
      "Value"], λ -> Quantity[369*10^-9, "Meters"]}, 
  "Hertz"] // N

Quantity[4.10604[Times]10^7, "Hertz"]

enter image description here


Looking at your code, I decided to test the comment I sent you. Try the following:

\[Lambda] = Quantity[369*^-9,"Meters"]
h = Quantity[1, "PlanckConstant"]
c = Quantity[1, "SpeedOfLight"]
Ins = Quantity[51*^-3, "Watts"/"Centimeters"^2]
hBar = h/(2*\[Pi])
Omega = (2 * \[Pi] c)/\[Lambda]

N[UnitConvert[\[Lambda]^2 * Ins/(\[Pi] * Omega * hBar),"Hertz"]]

As far as I'm aware, there's not an easier way to work with units other than the Quantity function.


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.