MathGroup Archive 2008

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

Search the Archive

Re: Calculating with Units

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94180] Re: Calculating with Units
  • From: John Jowett <John.M.Jowett at gmail.com>
  • Date: Sat, 6 Dec 2008 06:17:52 -0500 (EST)
  • References: <200812011202.HAA05923@smc.vnet.net> <493467F2.3020709@wolfram.com>

Hello again,
I think it is might be worth while to show how the original question
can be answered very simply with the use of two packages that have
been included in Mathematica since the very earliest versions.  In the
following I have just cut and pasted from a notebook; the formulas
look nicer in StandardForm of course.

In[59]:= Needs["Units`"]

In[61]:= Needs["PhysicalConstants`"]

B = (mu0 Ii)/(2 \[Pi] r);

In[75]:= B /.{r -> 20. Meter, Ii -> 2 Ampere,
  mu0 -> VacuumPermeability}

Out[75]= (2.*10^-8 Second Volt)/Meter^2

In[76]:= Convert[%, Tesla]

Out[76]= 2.*10^-8 Tesla

The reason I originally wrote the package mentioned in my previous
post (many years ago now) was to combine the two standard packages
with the Notation package and add a few more functions that make the
combination much more useful.

One thing I did was to introduce conventionally used symbols like c or
\mu_0 that would only evaluate under the action of N[], rather like Pi
and E, and unlike symbols such as SpeedOfLight that have assigned
values in the PhysicalConstants` package.  That's because you often
don't want general formulas involving them to be partly converted to
numerical values
(E== m c^2  rather than
E == (89875517873681764 m Meter^2)/Second^2 ).

So this example can be worked as

In[34]:= Needs["Accelerator`ConstantsUnits`"]

In[45]:= ?Subscript[\[Mu], 0]

Subscript[\[Mu], 0] or mu0 is a symbol for the permeability of the \
vacuum; it evaluates numerically with N[ ].

In[56]:= B = (Subscript[\[Mu], 0] Ii)/(2 \[Pi] r);

In[57]:= B /.{r -> 20 Meter, Ii -> 2 Ampere} // N

Out[57]= (2.*10^-8 Ampere Henry)/Meter^2

In[58]:= Convert[%, Tesla]

Out[58]= 2.*10^-8 Tesla

There is also a system of registration of the dimensionality of
symbols which allows you to check whether formulas are dimensionally
correct without even plugging in numerical values as follows.  I'm
throwing in Statampere and Furlong just to demonstrate that, thanks to
Convert[] and ToFundamentalSI[] you can evaluate expressions using any
old mix of units.


In[111]:= Clear[B, Ii, r];
IntroduceSymbol[B, "is the magnetic field.", Tesla];
IntroduceSymbol[Ii, "is the current in the wire.", Statampere];
IntroduceSymbol[r, "is the distance from the wire.", Furlong];

In[115]:=
DimensionCheck[B/((Subscript[\[Mu], 0] Ii)/(2 \[Pi] r))] //
  N // ToFundamentalSI

Out[115]= 2.20918*10^20

In[98]:= DimensionCheck[B/((Subscript[\[Mu], 0] Ii)/(2 \[Pi] r))] //
  N // ToFundamentalSI

Out[98]= 7.36901*10^10

The fact that this is a dimensionless number (the value is
meaningless) confirms that the argument of DimensionCheck[] is
dimensionless in SI units.

This refers everything to SI units.  I think Daniel Lichtblau's method
might allow you to work in other systems with varying numbers of basic
dimensions.

John Jowett


On Dec 4, 1:17 pm, Daniel Lichtblau <d... at wolfram.com> wrote:
> Nikolaus Rath wrote:
>
>  > Hello,
>  >
>  > Until now, I have always defined my units manually in terms of
>  > the 4 base units Kilogram, Meter, Coulomb and Second:
>  >
>  > Newton = Kg Meter / Second^2;
>  > Joule = Newton Meter;
>  > Henry = Weber / Ampere;
>  > Weber = Volt Second;
>  > etc.
>  >
>  > This allows me to evaluate expressions like
>  >
>  > B = (\[Mu] Ii)/(2 \[Pi] r);
>  >
>  > B /. { r -> 20 Meter, \[Mu] -> 4 \[Pi]  * 10^-7 Henry/Meter,
>  >   Ii -> 2 Ampere}
>  >
>  > % / Tesla
>  >
>  > and directly see if the units in the final result are correct.
>  >
>  > But since all these units (and many more) are already defined in the
>  > Mathematica Units package, I was wondering if there isn't a way to u=
se
>  > that package in the same way. Unfortunately, it doesn't seem to
>  > simplify the units, i.e. when I enter
>  >
>  > (Ampere Henry)/(Meter Meter) // Simplify // SI
>  >
>  > I get the same expression back. What I would like to get is either
>  > "Tesla" or "Kilo Gram / (Coulomb Second)".  Is there a way to
>  > accomplish this?
>  >
>  >
>  > Best,
>  >
>  >
>  >    -Nikolaus


  • Prev by Date: RE: Re: Mathematica 5,6,7 WeatherData, CityData
  • Next by Date: Re: A problem in Pi digits as Lattice space filling
  • Previous by thread: Re: Calculating with Units
  • Next by thread: Re: Calculating with Units