Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

Solve[
 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 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"] & // 
  QuantityMagnitude

299792458

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 at 14:51
1  
@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 at 8:17

Your Answer

 
discard

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.