Message Boards Message Boards

13
|
38749 Views
|
15 Replies
|
27 Total Likes
View groups...
Share
Share this post:

Palette for Inputting Typeset Units and Package with Input Aliases

Posted 10 years ago
I have written a palette and a package to help input properly typeset units.  The palette and package allow for quick input of units in Mathematica, avoiding the clunky units-discovery approach involving Wolfram Alpha queries. As an example, the expression below can be inputted quickly using the palette or by using the input aliases that are loaded by the package.

The link to a page for downloads is: http://www.blinn.edu/brazos/natscience/phys/thonan/Mathematica/ .
POSTED BY: Terrence Honan
15 Replies

I'm not sure what is happening but it still works for me running 10.3.1 under OS X.

What does happen sometimes is the input aliases somehow get locked into the User's init.m file; the aliases persist even when the package is not loaded. It happens rarely and might be connected to a Mathematica crash when the package is open. Fixing this is clunky; I get into the Option Inspector under "Global Preferences", open "Editing Options" => InputAliases and then delete all of the package's input aliases.

I don't know if this is your problem but the InputAliases might have become corrupted.

POSTED BY: Terrence Honan

It's a really nice tool, but suddenly the esc-q-esc functionality stopped working. Does anyone have a solution to this? I have tried to delete and reinstall the unit palette, but without success.

POSTED BY: Benny Bomstærk

Terrence, thanks again for a quick and very useful response. I've deleted the old versions of your palette, downloaded the new one and installed it. BTW, "installing" a new palette without first removing the old one from the UserBaseDirectory does not overwrite the old file.

POSTED BY: Ben Rodanski

A Nonosecond is a forbidden time! I corrected the typo and posted the update. It evaluated correctly only because unrecognized Quantity[] arguments go to Wolfram Alpha, which corrected the typo. One point of the palette and package is to avoid the need for regular Alpha queries.

As for uninstalling you have to go to the installation directory and delete it there. When you reopen Mathematica it will no longer appear in the list. Type $BaseDirectory into Mathematica (or $UserBaseDirectory for a user-specific installations) to find the top level directory. Packages are in $BaseDirectory/Applications and Palettes are in $BaseDirectory/SystemFiles/FrontEnd/Palettes.

POSTED BY: Terrence Honan

I just installed your interesting palette (with the same mistake as Ben Rodanski...). Your palette writes "Nonoseconds" in the cell expression. Shouldn't it be "Nanoseconds"? It evaluates correcly as Nanoseconds, though.

POSTED BY: Gianluca Gorni

Thanks, Terrence. I have another question: How to 'uninstall' a palette? When installing your Units, I mistakenly selected another .nb file and it is now listed on the Palettes drop-down menu. I've spent an hour or so trying to find a way to remove it from the list, but no luck...

POSTED BY: Ben Rodanski

Ben, the Wolfram units system does not simplify as a default. The package and shortcuts do not change the behavior of this units system; it just allows for easier and prettier input. To simplify, use the UnitSimplify function. The palette has a //UnitSimplify button and with the shortcuts installed you can get that with the shortcut esc us esc.

Raymond, I'm not sure if there are any Wolfram NSolve issues with units but your posted second expression had only two equations, where your first expression had three. It gave no solution but didn't crash for me. Adding the third expression does give the result in SI, which is odd. The only way I could convert to lbs. and in. was to follow it with: /. (x_ -> y_) :> (x -> UnitConvert[y, "Imperial"])

POSTED BY: Terrence Honan

Fantastic package, Terrence! Much better than the clunky Mathematica 10 syntax Quantity[]. Just like Kyle, I still prefer MathCAD's way of handling units. One thing I'm really missing in Mathematica is the automatic unit conversion to the most commonly used ones. Example:

In[1]:= cu1 = 10 Quantity["Amperes"]; vo1 = 10 Quantity["Volts"]; In[2]:= Rx = vo1/cu1 Out[2]= Quantity[1, ("Volts")/("Amperes")]

I think everyone would expect the result to be in "Ohms".

POSTED BY: Ben Rodanski
Posted 10 years ago

just installed, tried it on a simple shear stress problem and having problems;

without units, I get a solution

Clear[aa, \[Tau]1, \[Tau]2, t1, t2, T]
t1 = .2; t2 = .3; T = 50000;
NSolve[{aa == (3.5 - t2/2)*(4 - t1) + .5 \[Pi]*(2 - 
       t1/2)^2, \[Tau]1 == T/(2 aa t1), \[Tau]2 == 
   T/(2 aa t2)}, {aa, \[Tau]1, \[Tau]2}]

but when I add the units, as soon as divide T by aa the solution crashes

Clear[aa, \[Tau]1, \[Tau]2, t1, t2, T]
t1 = .2 Quantity["Inches"]; t2 = .3 Quantity["Inches"]; T = 
 50000 Quantity[("PoundsForce")/("Inches")^2];
NSolve[{aa == (3.5 Quantity["Inches"] - t2/2)*(4 Quantity["Inches"] - 
       t1) + .5 \[Pi]*(2 Quantity["Inches"] - t1/2)^2, \[Tau]1 == 
   T/(2 aa)}, {aa, \[Tau]1, \[Tau]2}]

two problems:

  1. my units are in inches, yet the result is in m^2, how can I keep my original units??
  2. how can I prevent the crash???
POSTED BY: Raymond Low

Just installed. Works great. Will become part of my daily routine.

POSTED BY: Dave Lubbers
Posted 10 years ago
Thank you Hans. I've been using the q method myself, and for now I think the q method that Mr Honan came up with is the best method there is. I hope that WRI incorporates this in future MMA releases. I
POSTED BY: Kyle Nguyen
Posted 10 years ago
Hi Kyle I have found the esc q 'symbol' esc approach to be quite seamless especially as there are already quite a large number shortcut inputs that follow that pattern that I already use. At least this way keeps all the unit symbols (eg m, l, s, g, A,...) free to be user defined smbols and not Protected. I installed the palette about a month ago I am finding usage of Mathematica's unit functions so much more accessible. Here's some code I put together to generate a function to format partially worked explanations for my students that were having trouble extracting info from worded problems; converting units and correctly applying Boyle's law - not overly complex but never the less the unit template made entering quantities fast enough to make it possible to use my predefined function on the fly in class.

(*define function*)
boylesLaw[p1_,v1_,p2_,v2_,precision_]:=SetPrecision[Style[Grid[{{"Identify all information given in the question and convert to SI units"},{},{Grid[{{"Subscript[P, 1]","=",p1,"=",N@UnitConvert[p1,kPa]},{"Subscript[V, 1]","=",v1,"=",N@UnitConvert[v1,L]},{"Subscript[P, 2]","=",p2,"=",N@UnitConvert[p2,kPa]},{"Subscript[V, 2]","=",v2},{},{"This question requires Boyle's Law:",SpanFromLeft},{"Subscript[P, 1]Subscript[V, 1]","=" ,"Subscript[P, 2]Subscript[V, 2]"},{"\[Therefore] Subscript[V, 2]","=","(Subscript[P, 1] Subscript[V, 1])/Subscript[P, 2]","=",Column[{Row[{ N@UnitConvert[p1,kPa]," * ",N@UnitConvert[v1,L]}],N@UnitConvert[p2,kPa]},Alignment->Center,Dividers->{None,{None,True,None}}],"=",N@UnitConvert[(v1 p1)/p2,"Liters"]}},Alignment->Left]},{},{Row[{"\[Therefore] the final volume is ",Style[ScientificForm@UnitConvert[(v1 p1)/p2,"Liters"],Bold]}]}},Alignment->Left],"Text"],precision]


(*example usage, quantities can be entered easily using using esc q 'symbol' esc from InputUnits aliases*)
boylesLaw[101kPa,50mL,4atm,"?",3]
POSTED BY: Hans Schmidt
Posted 10 years ago
This unit palette is invaluable for scientists and engineers to conveniently work with units. I switched from Mathcad to Mathematica because of the vastly improved computational resources, but one thing I really miss about Mathcad is its brilliant handling of units--a letter "m" after a number immediately shows up as meters, with a different syntax highlighting than the number itself. This palette (and the hotkey package) is a big step toward that goal, but I'd love to see this fully integrated into Mathematica such that the user could just append a unit naturally after a number--as he/she would on paper--and use that for future calculations. I firmly believe that adding this feature (instead of the clunky and slow Quantity function) to future releases of Mathematica would lead to much greater adoption by scientists and engineers alike.

POSTED BY: Kyle Nguyen
Posted 10 years ago
Awesome palette, it's worthy of full inclusion for Mathematica v10!! It's the physics teacher's dream addition to Mathematica. Thank you for sharing Terry.

Cheers,
POSTED BY: Hans Schmidt
This is excellent, Terrence, - something I needed. I Thanks for sharing!
POSTED BY: Sam Carrettie
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract