Tag Info

Hot answers tagged

23

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


15

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


13

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


12

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


12

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


11

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


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"


10

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


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


8

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


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 ;-)


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


6

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


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


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


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


2

2 important things about Plot, from help: For some reason, Plot is doing Hold on not just the first argument x, but also on the whole argument list, when x1 and x2 are Quantity. When you did x1 = Quantity[1, "Volts"]; x2 = Quantity[2, "Volts"]; Plot[x, {x, x1, x2}] Then Trace shows this: Plot[x, Unevaluated[{x, x1, x2}]] and you can see now x1 and ...


2

Your problem seems to be the Integrate result: as usual it assumes all variables could be complex which results in a complicated ConditionalExpression which will not evaluate correctly when fed with variables that have units. The trick is, as Michael has shown to use assumptions, but I think it is much better to use the assumptions for the formal variables ...


2

Try this: Clear[Wideal] Wideal[V1_, V2_, n_: n, T_: T] := Evaluate[W[V1, V2, Pideal[n, T, V]]] // FullSimplify Wideal[5 Liters, 10 Liters, 1 Mols, 298 Kelvins] 298 Kelvins Mols R Log[2] Clear[WvdW] WvdW[V1_, V2_, n_ : n, T_ : T, a_ : a, b_ : b] := Evaluate[(Integrate[PvdW[n, T, V, a, b], V] /. {{V -> V1}, {V -> V2}}).{-1, 1}] // FullSimplify ...


2

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


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


2

To explore my question a bit I tried the Mathematica 8 AutomaticUnits add-on from http://blog.wolfram.com/2010/12/09/automatic-physical-units-in-mathematica/ You must modify built-in PhysicalConstants.m (benign) as per comments in that blog to play properly with AutomaticUnits. Once done, you can write clearly in Mathematica 8 <<PhysicalConstants` ...


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


1

You can just type "50 m/s" in a WolframAlpha box, like you have. If you want to enter it in "pure Mathematica", without going through W|A, you can use Quantity["50 m/s"]. See its documentation here: http://reference.wolfram.com/mathematica/ref/Quantity.html


1

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



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