Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to understand how to easily solve equations that use QuantityVariable.

Why does this fail?

Quantity["Speed of Light"] ==  
  QuantityVariable[ν, "Frequency"] (2 π)/QuantityVariable[k, "wavenumber"] /.  
    QuantityVariable[ν, "Frequency"] -> Quantity[2, "THz"]
// Solve

Solve::units: Solve was unable to determine the units of quantities that appear in the input. >>

while this doesn't?

 QuantityVariable[k, "wavenumber"] == (2 π)/QuantityVariable[λ, "Wavelength"], 
 QuantityVariable[λ, "Wavelength"]]
{{QuantityVariable[λ,"Wavelength"] -> (2 π)/QuantityVariable[k,"wavenumber"]}}

Nor does this,

Solve[ 3 10^8 == 2 10^12 (2 π)/k]
{{k -> (40000 π)/3}}

Notice that its not necessary to explicitly say which variable to solve in the last example as there is only one possibility, yet that fails if using QuantityVariable.

The question is: Why does my first code fails?

share|improve this question
Thanks @Öskå for fixing the formatting. I didn't know how to do it myself. – rhermans Aug 6 '14 at 12:17
up vote 3 down vote accepted
Quantity["Speed of Light"] ==
   QuantityVariable[\[Nu], "Frequency"] (2 \[Pi])/
     QuantityVariable[k, "wavenumber"] /.
  QuantityVariable[\[Nu], "Frequency"] -> Quantity[2, "THz"] //

 Solve[#, QuantityVariable[k, "wavenumber"]][[1]] &

{QuantityVariable[k,"wavenumber"] -> Quantity[(2000000000000 [Pi])/149896229, 1/("Meters")]}

% // N

{QuantityVariable[k,"wavenumber"] -> Quantity[41916.9, 1/("Meters")]}

speedOfLight = 
 Quantity["Speed of Light"] //
   UnitConvert[#, "m/s"] & // 


Solve[speedOfLight == 2 10^12 (2 \[Pi])/k][[1]]

{k -> (2000000000000 [Pi])/149896229}

% // N

{k -> 41916.9}

share|improve this answer
Thanks for the reply, but it does not answer why my code fails. You see that in your first example it becomes necessary to explicitly define the variable that needs to be solved if the variable is a QuantityVariable, where in the normal unit-less variable in the last example, there is no need for that. – rhermans Aug 6 '14 at 14:51
@rhermans I myself avoid using the one-argument syntax of Solve for complex tasks, anyway it's undocumented. And according to my test, it's also slower if one doesn't specify the variable in Solve. – xzczd Sep 2 '14 at 8:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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