MathGroup Archive 2003

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

Search the Archive

RE: Use of units and simplification

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38906] RE: [mg38896] Use of units and simplification
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 18 Jan 2003 00:38:31 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Yves,

One can usually obtain faster responses by providing a proper email address.
There are some cases where responders might wish to respond privately or ask
for more information and it is very slow doing this day by day through the
newsgroup.

The regular Convert routine will simplify your expression.

Needs["Miscellaneous`Units`"]
Needs["Miscellaneous`PhysicalConstants`"]

Sqrt[x*Meter^2]
Convert[%, Meter]
 gives...
Sqrt[Meter^2*x]
Meter*Sqrt[x]

To use prefixes, you must leave a space between the prefix and the unit.

Convert[1500. Milli Meter, Yard]
1.64042 Yard

Unfortunately, when one goes the other way, Mathematica sorts the symbols to
give an unnatural order.

Convert[0.05Yard, Milli Meter]
45.72 Meter Milli

In using units, I think that it is often best to never put the units in the
equations. Put the units in the data. Then you can manipulate and solve your
equations symbolically without units ever showing, and substitute the data
WITH the units at the end. Here is a very simple example. What height will a
stone reach in 20 seconds if dropped from 2 miles.

data = {x0 -> 2Mile, g -> AccelerationDueToGravity, t -> 20Second};

Without introducing units...

v[t_] = Integrate[-g, {t, 0, t}]
-g t

x[t_] = x0 + Integrate[v[t], {t, 0, t}]
-((g*t^2)/2) + x0

Now we can introduce our data WITH the units attached to obtain the answer.

x[t] /. data
Convert[%, Mile]
 giving
-1961.33 Meter + 2 Mile
0.781286 Mile

There are two packages at my web site below, V4ExtendUnits and
V4ReducedUnits, that extend the Units package. Its ToUnit function is a
little more convenient to use than Convert. One can also format the output
at the same time as converting it and there is a new output form called
PrefixForm. It automatically picks a proper prefix and puts the output in a
HoldForm to maintain the customary order. So in the example above...

Needs["Miscellaneous`V4ExtendUnits`"]

0.05Yard // ToUnit[Meter, UnitForm -> PrefixForm]
45.7200 Milli Meter

There are many other useful features. With the regular Units package you
can't convert floating point quantities to Degrees because Mathematica made
the mistake of making Degrees both a constant and a unit. With ExtendUnits
you can convert to degrees. There is a BaseSI command that converts
everything to base SI units. The SI command does not convert everything to
common units. You can convert to multiple units at the same time, and also
parse a quantity into descending compatible units (for example, Day, Hour,
Minute, Second). It will handle units in DiracDeltas, UnitStep and ArcTan.
To do numerical work or plotting it is necessary to remove units one way or
another. The package has a Deunitize function that will deunitize to
standard unit systems. There is also a more controlled function that allows
one to specify the implied input and output units.

The package also allows you to install your own units, (GeV for Giga
ElectronVolt, or mps for Meter/Second, say). The ReducedUnits package allows
the introduction of unit systems where certain physical constants are taken
as 1. These would include such systems as geometrized units or atomic units.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



From: Yves K. [mailto:yk at despammed.com]
To: mathgroup at smc.vnet.net

Hallo,

I would like to use the units of Miscellaneous Units (Mathematica 4.2
Windows).

1) Why does Simplify[Sqrt[x*Meter^2]] give
Sqrt[Meter^2*x] ? The result of the simplification is o.k. when I assume
that Meter>=0:
Simplify[Sqrt[x*Meter^2], Meter >= 0] ->Meter*Sqrt[x]

Of course I could always assume that any unit used is >=0, but that does
not seem to be the right way.
Am I missing something? Is there a way to get the units "properly"
simplified?

2) There is Meter and Centimeter predefined. Where have the Millimeters
gone? I did not succeed in prepending any of the SI unit prefixes. Could
  I simply use MilliMeter? Did not really work for me...

Thanks, and sorry if the questions are silly (which they most probably are).

Yves




  • Prev by Date: RE: What is a smart way to do this?
  • Next by Date: Re: Why is Mathematica incredible slow?
  • Previous by thread: Re: Use of units and simplification
  • Next by thread: Re: Use of units and simplification