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?

  • $\begingroup$ Thanks @Öskå for fixing the formatting. I didn't know how to do it myself. $\endgroup$
    – rhermans
    Aug 6, 2014 at 12:17

1 Answer 1

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}

  • $\begingroup$ 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. $\endgroup$
    – rhermans
    Aug 6, 2014 at 14:51
  • 1
    $\begingroup$ @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. $\endgroup$
    – xzczd
    Sep 2, 2014 at 8:17

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.