Tag Info

Hot answers tagged

25

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"]]} , ...


16

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, ...


14

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 /: ...


14

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, ...


13

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 = ...


13

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, ...


12

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

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, ...


11

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


8

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, ...


7

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 ...


7

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"]


7

I'm not sure whether this is what you seek, but you can use Trace to investigate in a call to Quantity. Then you extract the essence Quantity["Newtons"]; StringReplace[Names["CalculateUnits`UnitCommonSymbols`*"], "CalculateUnits`UnitCommonSymbols`" ~~ r_ :> r] and you get some kind of list ;-)


5

You might use Assumptions in one form or another. Block[{$Assumptions = Liters > 0 && Mols > 0 && Kelvins > 0}, Simplify[Wideal[5 Liters, 10 Liters, 1 Mols, 298 Kelvins]] ] (* -> 298 Kelvins Mols R Log[2] *) One disappointment for me is that the following doesn't work: Block[{$Assumptions = Liters > 0 && Mols ...


5

Not a full answer since I need to sleep :) but more of an observation, which might help. It seems to have to do with the fact that 0 and 0. are not the same in Mathematica. This simple example shows it UnitConvert[0. + Quantity[5, "Meters"], "Inches"] (*--> UnitConvert[0. + Quantity[5, "Meters"], "Inches"] *) while UnitConvert[0 + ...


5

If you don't want Mathematica to use Wolfram | Alpha for correcting incorrect units, you can just set $AllowInternet = False. The downside of this is that it also blocks internet access for the curated data functions such as WeatherData, FinancialData, etc. You can also use Block to disallow internet only within your function.


5

How about m = Quantity[AstronomicalData["Earth", "Mass"], AstronomicalData["Earth", "Mass", "Units"]] 5.9721986*10^24 kg m // FullForm Quantity[5.9721985999999999999999999999999999999999202`8.*^24,"Kilograms"]


4

If you want something that displays in abbreviated from, you can do the following: Type Quantity[number, "unitstring"], for example Quantity[5, "m"]. Select that expression (pressing Ctrl. twice will do that if you haven't moved the cursor). Perform Evaluate In Place (CtrlShiftEnter on Windows and Linux, CmdEnter on OS X). This will give you something ...


4

A properly formatted Quantity expression should work just fine, without trying to connect to WolframAlpha servers for conversion. For example, Quantity[1, "Feet"] + Quantity[2, "Inches"] should run with or without internet connectivity. In contrast, Quantity[1, "Foot"] + Quantity[2, "Inches"] will attempt to contact WA servers in an attempt to ...


3

Still working out the why, but wrapping an Evaluate[] around your function seems to solve the problem: Plot[ Evaluate[ PVW[V, Quantity[330, "Kelvins"], Quantity[1, "Moles"] ] ], {V,Quantity[0.06, "Liters"],Quantity[0.6, "Liters"]}, Frame -> True, GridLines -> None, LabelStyle -> {FontFamily -> "Helvetica", FontSize -> 15}, FrameLabel ...


3

As a partial answer the documentation says: Supported units include all those specified by NIST Special Publication 811. This is repeated in Unit Discovery. It also states: Unit interpretation requires internet connectivity, and can entail additional evaluation time. If speed is a concern, it is advisable to use the canonical unit specification, ...


3

Here's my extensions to Rojo's answer. I've moved the replacement rules into a global variable, to make them easier to modify on the fly $UnitReplacementRules = {"fm"->"Femtometers","nm"->"Nanometers","\[Mu]m"->"Micrometers","mm"->"Millimeters","cm"->"Centimeters","m"->"Meters","km"|"kms"->"Kilometers","mi"->"Miles", ...


3

For those still preferring the use of AutomaticUnits, Jon has posted a work around to allow its use with v.9 at http://blog.wolfram.com/2010/12/09/automatic-physical-units-in-mathematica/#comments


3

It looks like a typo. Reffering to the code you showed in comments, you are calculating mass for given parameters, one of them is temperature: M[ Quantity[100, "Kelvin"], ... but in fact it is not what you thought: Quantity[100, "Kelvin"] // QuantityUnit "KelvinsDifference" so the resulting value is correct: value kg K^(3/2)/K^(3/2) only K!=K ...


3

A work-around for the OP's problem is to enter the units expression into Quantity as a single string, not as several strings separated by arithmetic operators. Thus k = Quantity[25, "BTU/(Hour Feet Fahrenheit)"]


3

UnitSimplify simplifies the units it doesn't guarantee it'll give you the units in SI. Just use UnitConvert, it gives you the answer in SI units. UnitConvert[(KB T)/(3 Pi eta0 L)]


2

Improved version of Simon's answer which tries several different transformation of the input string to convert it to the full form that Mathematica needs: Begin["System`"] (* Deca is intentionally left out as only one character prefixes are supported *) ...


2

I think it is relatively simple and straightforward to achieve what you want with the new Quantity expressions as well: You could just define the symbols you want to use as units as the corresponding Quantities and go ahead: kNm = Quantity["kN"]*Quantity["m"] cm3 = Quantity["cm"]^3 MPa = Quantity["MPa"] now you can use something like this to do the ...


2

Like others, my first reaction to WM9's system-wide physical units was "Why is this so laborious? Do they expect us to type Quantity[magnitude, unit] everytime we want to associate a unit with some quantity?" After exploring units in WM9 for a while, I figured a way to assign shortcut names for my favorite units which, I think, is more user-friendly than ...


2

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 ...



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