Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to handle Units of Measure

  • To: mathgroup at
  • Subject: [mg100239] Re: How to handle Units of Measure
  • From: AES <siegman at>
  • Date: Thu, 28 May 2009 19:35:39 -0400 (EDT)
  • Organization: Stanford University
  • References: <gvlhom$djb$>

In article <gvlhom$djb$1 at>,
 Alexei Boulbitch <Alexei.Boulbitch at> wrote:

> In this very simple example if I write
> R+iwL
> where R is measured in Ohms, w in s^-1, L in H, I expect that the
> result is given in Ohms.
> Why it doesn't happen in Mathematica ? Ho can I do to handle in a
> simple way those conversions ?
> Thanks

Here is one way to handle -- and think about -- these situations, which 
works for me.

Your example involves the equation

   v = (r + j w l) i

which is a true equation provided _all_ the quantities in it are in a 
_consistent_ set of units (volts, ohms, radian/sec, henries, and amps 
would be are a consistent and widely used set for this case).

So, in _any_ calculation you do, always write *all the equations that 
are going to be used to do the calculations* in a consistent set of 
units (mks is good, but you might for some reason want to use another 
set: cgs, ipj, etc).

But, you might also want to provide _input_ data to these calculations, 
or print or plot _output_ data from these calculations, using other 
units.  As just one example, you might want to do calculations with the 
above equation using the standard units given the above, but supply 
input date for r in kilo-ohms and display output results for i in 

To do this, define at some appropriate spot early in your calculations 
the "units"

   kOhm = 10^3;  mA = 10^-3;  (* use whatever names you like *)

If you want to put into the calculation at some point an input 
resistance of 10 kilohms, or an input current of 10 milliamps, you 
_input_ these values as

   r = 10 kOhm;   OR   i = 10 mA;     (* for _inputs_  *)

which means the numerical values of r and i in the calculations are now 
in the correct basic set of units.

If on the other hand, at some later point you want to, say, Plot or 
tabulate an output current in milliamps (remembering that it is 
_calculated_ in amps). or a resistance in kilohms, you write

   Plot[ i/mA, { . . . }]   OR  Table[ r/kOhm,  { . . . }]

The mental construct to keep in mind in this latter case is that writing 
"i/mA" in Mathematica now gives you the value of the current i _in 

This approach doesn't put _labels_ of any sort on these outputs; but you 
should preferably handle those labels yourself anyway, and keep them 
separate from the calculations.  

In the above case, for example, you can put "r in kilohms" in the column 
heading of the Table, or write

   Print[ "Current = "<>ToString[i/mA]<>" milliamps"] 

   Print[ "Current in milliamps = "<>ToString[i/mA]] 

to label the plot.

I find this approach, used consistently, to be consistent and readable 
in all my notebooks.

  • Prev by Date: p.s. // Re: Re: new to group - Chemical Equation
  • Next by Date: Re: new to group - Chemical Equation
  • Previous by thread: Re: How to handle Units of Measure
  • Next by thread: Shade area between two polar curves