Question

It is helpful to use physical constants included in mathematica. Unfortunately they all include units. This provides errors when trying to integrate numerically. Is there a way just to get the value of a variable without any dimensions?

Thank you! Martin

Was it helpful?

Solution

If e.g. c is the speed of light:

c = UnitConvert[Quantity["SpeedOfLight"]]

Then the obvious way would be to write:

c/Quantity["Meters"/"Seconds"]

Because that way, you're certain the unitless quantity you work with actually means something in m/s, not e.g. ft/hour. In other words: If you wrote c/Quantity["Feet"/"Hours"], the result would be the speed of light, in ft/hour, without a unit attached.

Alternatively, you could always write:

QuantityMagnitude[c]

Which just returns the magnitude, without the unit

OTHER TIPS

Perhaps this will help

In[1]:= sol = UnitConvert[Quantity["SpeedOfLight"]]

Out[1]= 299792458 m/s

In[2]:= FullForm[sol]

Out[2]//FullForm= Quantity[299792458,Times[Meters,Power[Seconds,-1]]]

In[3]:= mysol = First[sol]

Out[3]= 299792458

In[4]:= FullForm[mysol]

Out[4]//FullForm= 299792458
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top