Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to speed up calculations with unit conversions. I suspect primarily that some units evaluate from Wolfram|Alpha. Any way to prevent this automatically, so that Mathematica throws errors/warnings instead of grabbing units from Wolfram|Alpha?

share|improve this question
4  
Set $AllowInternet to False? –  rm -rf Mar 6 at 15:16

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
    
this works, but could not get any speed up –  denfromufa Mar 6 at 16:49
1  
@denfromufa Well, you only asked about suppressing connection :) I doubt that you can speed up the Units functionality that easily... A lot of the slowdown has to do with the fact that the data with units is stored as unpacked arrays. Depending on your actual needs, you can avoid having to use any units (track them separately) and use efficient packed arrays for computations. –  rm -rf Mar 6 at 16:52
    
yep, removing units is the only option –  denfromufa Mar 6 at 17:25

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 correct the malformed Quantity[1,"Foot"] expression.

share|improve this answer
    
yes, this my current solution, but not automated, since I have to go through each unit one by one to see if it is in offline unit set –  denfromufa Mar 6 at 15:57

I gave up trying to use Quantity and the units package in version 9 because of the drop in speed and the clumsy way of incorporating units that makes long expressions difficult to read. I have therefore stuck with Jon McLoone's package that works very well. It can found at http://blog.wolfram.com/2010/12/09/automatic-physical-units-in-mathematica/#comments

share|improve this answer
1  
Please don't copy-paste the same answer repeatedly. You have already written that as an answer here, which is where it really belongs. –  rm -rf Mar 12 at 21:55
    
this package is not updated since 2012 according to the author: "This package is now largely obsolete as similar functionality is included in Mathematica 9. wolfram.com/mathematica/new-in-9/units It has also become incompatible with 9 due to a name conflict, though there is an easy fix: Open the file AutomaticUnits.m and do a search and replace on all occurrences of “CompatibleUnitQ” change it to a different word, I suggest “DimensionCompatibleUnitQ”. Replace the file with the modified version." –  denfromufa Mar 12 at 22:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.