# Tag Info

35

If we pre-evaluate the expression: x1 B[Quantity[ll, "Micrometers"], Quantity[1000, "Kelvins"]] then the run time can be reduced by about factor 10. We can do this by hoisting the expression out of the loop and pre-evaluating using With: p = Module[{ll} , With[{v = x1 B[Quantity[ll, "Micrometers"], Quantity[1000, "Kelvins"]]} , Table[{Quantity[...

34

This is certainly the optimal way of obtaining the list you are looking for Quantity;QuantityUnitsPrivate$UnitReplacementRules[[1, All, 1]] EDIT for v10 (thanks @DavidCreech) In v10 this undocumented variable format has been changed into an association, whose keys are the units. Quantity; Keys[QuantityUnitsPrivate$UnitReplacementRules]

28

There are system options available that should restore the old behavior for most of the currated data paclet: SetSystemOptions[SystemOptions["DataOptions"] /. True -> False] {"DataOptions" -> {"ReturnEntities" -> False, "ReturnQuantities" -> False, "UseDataWrappers" -> False}} Note that this prevents these paclets from returning Entity,...

27

I believe you can use "DimensionlessUnit" to get the desired result: Quantity[3, "DimensionlessUnit"] 3 (note this is the unit produced by QuantityUnit on a dimensionless value): QuantityUnit[3] "DimensionlessUnit"

23

Here is a cheap way which does not involve WA, but will only be as good as you make it to be (so that you'd have to customize it yourself): create a dynamic environment: ClearAll[withUnits]; SetAttributes[withUnits, HoldAll]; withUnits[code_] := Function[Null, Block[{Quantity}, SetAttributes[Quantity, HoldRest]; Quantity /: UnitConvert[...

23

This should list you all available units in Mathematica. Needs["QuantityUnits"] Keys[QuantityUnitsPrivate$UnitReplacementRules] Inspired by eldo I made a little dynamic interface: Needs["QuantityUnits"] table = Keys[QuantityUnitsPrivate$UnitReplacementRules]; Panel[DynamicModule[{f = ""}, Column[{Text[Style["Mathematica Unit Search:", Bold]],...

21

In physics, the Planck constant may be used as a natural unit. If you want to switch to another unit system, use UnitConvert[]. For example, you can switch to standard SI units this way: UnitConvert[Quantity[1, "PlanckConstant"], "SIBase"] which will give you: Quantity[6.626070*10^-34, ("Kilograms" ("Meters")^2)/("Seconds")] This can be done at the ...

20

Oops - found it! QuantityMagnitude[quantity] does the job. For example, In[1]:= QuantityMagnitude[Quantity[1, "Feet"]] Out[1]= 1

18

This appears to be a bug. The dimensions of the Boltzmann constant are incorrect. In fact, all the physical constants I checked have TemperatureUnit where they should have TemperatureDifferenceUnit. You should only have to make a substitution when making calls to physical constants in Quantity: q = UnitConvert[Quantity["elementary charge"]]; k = (...

18

This is a long comment for Nick Lariviere's answer. You can use Trace to see how lengthy the entity and quantity logic is. Version 9: Tuples@{Range@112, {"Symbol", "Group"}} // First ElementData @@ % // Trace; % // ByteCount 78336 TreeForm[%%, VertexLabeling -> False, ImageSize -> 800, AspectRatio -> 2] Version 10: ... % // ByteCount ...

17

Just some analysis to try to find where the slow down. On my PC, it took 25 seconds to build the table. ps. I never used Units before. Your main loop: x = UnitConvert@Quantity["PlanckConstant" "SpeedOfLight"/"BoltzmannConstant"] x1 = UnitConvert@Quantity[2, "PlanckConstant" ("SpeedOfLight")^2] B[L_, T_] := (L^(-5))/(Exp[x/(L T)] - 1) c = Quantity[1000, "...

17

x is not in mL..it is just a pure number. Quantity[x, "ml"] is the 'thing' that is in mL. To get what you want, you need to recast your Solve command as Solve[x Quantity[5, "mol"] + (Quantity[250, "ml"] - x) Quantity[7, "mol"] == Quantity[250, "ml"] Quantity[6, "mol"], x] However, the result is a bit strange looking. {{x -> Quantity[1/8000, ("...

16

You need to use 'better' units: UnitConvert[Quantity[1, "GiB"], "MiB"] Quantity[1024, "Mebibytes"] See explanation and definitions in https://en.wikipedia.org/wiki/Gigabyte

15

While it would've been nice if the package handled it automatically, it can be fixed with a simple overloading of Quantity: Unprotect@Quantity; Quantity /: (0 | 0.) Quantity[_, unit_] := Quantity[0, unit] Protect@Quantity; You can add this to your init.m, so that you don't have to define it each time. You can test your examples with this: 0. Quantity[1, "...

15

I have mined the Units package for the names of all units defined therein and correlated them to the built-in strings recognized by Quantity(referenced here). I then define a new function Quantify to convert the old school units into Quantity objects. unitRules = Dispatch[{Abampere -> Quantity[1, "ABAmperes"], Abcoulomb -> Quantity[1, "...

15

At the beginning of your notebook set the Metric system as default. $UnitSystem = "Metric" This works for me. If not try below suggestion Remember you are reading the data from wolfram alpha! it's a regional thing so if the upper solution didn't work, you can try something like (I don't remember exactly though) SetOptions[WolframAlpha, PodStates -> {"... 14 The CGS units are available. Out of the need to ensure dimensional consistency, the different things which are all called ESUs must be carefully distinguished. In[59]:= Quantity[1, "ESU of charge"] Out[59]= Quantity[1, "ESUsOfCharge"] In[60]:= Quantity[1, "ESU"] Out[60]= Quantity[1, "ESUOfDielectricDisplacement"] Also, when a unit has a special name, ... 14 You can use the relative uncertainty 1.1*10^-5 from the CODATA website you also referenced, and use Around to construct a value for the Planck length with uncertainty which has a much nicer formatting for showing the relevant digits of the number: Around[UnitConvert[Quantity["PlanckLength"], "m"], Scaled[1.1*^-5]] (1.616255±0.000018) x 10^-35 m Since ... 13 It is generally better to work in dimensionless units to start with. In your case, your a and b have units of$L^{-2}$, while eta is dimensionless. Taking fx''[x] + a*fx[x] == -I*eta*fy''[x] - b*fy[x] as an example, you could use$\xi=x/L$,$\alpha=a L^2$,$\beta=b L^2$(all of which are now dimensionless), whereupon your differential equation becomes$L^{-2}...

13

That code should work and it does work on my machine. The problem could be the following. You have only one part that requires Wolfram|Alpha interpretation: Quantity[24, "1/Seconds"] It is not built in unit - so it goes to Wolfram|Alpha for interpretation (how cool is that? ;-) ). This works almost always - unless something is wrong with internet ...

12

UnitConvert[Quantity[179., "Centimeters"], MixedRadix["Feet", "Inches"]] returns Quantity[MixedRadix[5, 10.472440944881885], MixedRadix["Feet", "Inches"]] which formats as 5'10.4724"

11

Below is some code I use to work with units. I am aware that the unit system I am calling "CGS" is only semi-CGS, since I am keeping the SI electromagnetic units, but this is the flavor of consistent unit system we sometimes use in our lab. Really, though, this is a recipe for choosing your own set of base units. The method works by applying ...

11

As noted in the documentation for Quantity, you can use ctrl-= to input units. This uses Wolfram|Alpha, so needs an internet connection. Quantity will also use Wolfram|Alpha to try to interpret strings, so you could also use: In[8]:= UnitConvert[Quantity["1 m/s^2*(1 min)^2"], Quantity["km"]] Out[8]= Quantity[18/5, "Kilometers"]

11

You could set an input alias such as With[{rules = {"m" -> "Meters", "km" -> "Kilometers"}}, AppendTo[CurrentValue[InputNotebook[], InputAliases], "qu" -> TemplateBox[{"\[SelectionPlaceholder]", "\[Placeholder]"}, "QuantityUnit", DisplayFunction -> (PanelBox[RowBox[{##}], FrameMargins -> 2] &), InterpretationFunction -&...

11

The difference between 0 °C and 100 °C in Fahrenheit is 180 °F. The difference between 0 K and 100 K in Fahrenheit is 180 °F. But 100 °C is 212 °F, while 100 K is 279.688 °F. The underlying reason are, of course, the differing scale origins (zero points); the conversions are therefore not direct proportions (not homogeneous functions). Instead they are ...

11

A bit too long for a comment... My best guess is that WolframAlpha["earth's gravity", "MathematicaResult"] is simply rounding to too few digits. It returns 32.2 ft/s^2, which seems pretty round for what it represents. Now maybe that's ok to do because gravity varies around the globe: data = GeogravityModelData[{{-90, -180.}, {90, 180.}}, "Magnitude", ...

11

The 4.652... at the end of 1.616255000000000066841324.652207380644164*^-35 should tell you that Mathematica knows this constant only up to 4.65 decimal digits. You have to enforce first to treat the number as a higher precision number first: NumberForm[ SetPrecision[ QuantityForm[UnitConvert[Quantity["PlanckLength"], "Meters"], "LongForm"], 7], {7,...

10

Expanding a little bit on paw's nice discovery: Needs["QuantityUnits"] table = Keys[QuantityUnitsPrivate`\$UnitReplacementRules]; Since this table is very long one can restrict the output, f.e. with Union @ Flatten[StringCases[#, "Feet" ~~ ___] & /@ table] // TableForm UPDATE A similar question could arise with the more than 1000 inbuilt ...

10

The following works for V10. First we define some abbreviation rules: rule = {"Newtons" :> N, "Meters" :> m, "Pascals" :> Pa, "Farads" :> F}; (* add more rules here *) Then: unit = TextString[QuantityUnit[Quantity[1, "Newtons/Meters^2"]] /. rule] "N/m^2" StringQ[unit] True TextString[QuantityUnit[Quantity[1, "Meters*Pascals/Farads^2"]] /....

Only top voted, non community-wiki answers of a minimum length are eligible