1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
<a name="Module:Scientific.Physics.PhysicalQuantities"><h1>Module Scientific.Physics.PhysicalQuantities</h1></a>
<p>Physical quantities with units.</p>
<p>This module provides a data type that represents a physical
quantity together with its unit. It is possible to add and
subtract these quantities if the units are compatible, and
a quantity can be converted to another compatible unit.
Multiplication, subtraction, and raising to integer powers
is allowed without restriction, and the result will have
the correct unit. A quantity can be raised to a non-integer
power only if the result can be represented by integer powers
of the base units.</p>
<p>The values of physical constants are taken from the 1986
recommended values from CODATA. Other conversion factors
(e.g. for British units) come from various sources. I can't
guarantee for the correctness of all entries in the unit
table, so use this at your own risk!
</p>
<hr width=70%>
<h2>Functions</h2>
<ul>
<li> <p>
<a name="Function:Scientific.Physics.PhysicalQuantities.isPhysicalQuantity"><b><i>isPhysicalQuantity</i></b>(<i>x</i>)</a><br>
</p>
<p>Returns 1 if <i>x</i> is an instance of PhysicalQuantity.</p></ul>
<hr width=70%>
<a name="Class:Scientific.Physics.PhysicalQuantities.PhysicalQuantity"><h2>Class PhysicalQuantity: Physical quantity with units</h2></a>
<p>Constructor:</p>
<ul>
<li> <p>
PhysicalQuantity(<i>value</i>, <i>unit</i>), where <i>value</i> is a number of
arbitrary type and <i>unit</i> is a string containing the unit name.</p><li> <p>
PhysicalQuantity(<i>string</i>), where <i>string</i> contains both the value
and the unit. This form is provided to make interactive use more
convenient.</p></ul>
<p>PhysicalQuantity instances allow addition, subtraction,
multiplication, and division with each other as well as
multiplication, division, and exponentiation with numbers.
Addition and subtraction check that the units of the two operands
are compatible and return the result in the units of the first
operand. A limited set of mathematical functions (from module
Numeric) is applicable as well:</p>
<p><dl>
<dt>sqrt</dt>
<dd><p>
equivalent to exponentiation with 0.5.</p></dd>
<dt>sin, cos, tan</dt>
<dd><p>
applicable only to objects whose unit is compatible
with <tt>rad</tt>.
</p></dd>
</dl>
</p>
<b>Methods:</b><br>
<ul>
<li> <b><i>convertToUnit</i></b>(<i>unit</i>)
<p>Changes the unit to <i>unit</i> and adjusts the value such that
the combination is equivalent. The new unit is by a string containing
its name. The new unit must be compatible with the previous unit
of the object.</p>
<li> <b><i>inUnitsOf</i></b>(<i>*units</i>)
<p>Returns one or more PhysicalQuantity objects that express
the same physical quantity in different units. The units are
specified by strings containing their names. The units must be
compatible with the unit of the object. If one unit is
specified, the return value is a single PhysicalObject. If
several units are specified, the return value is a tuple of
PhysicalObject instances with with one element per unit such
that the sum of all quantities in the tuple equals the the
original quantity and all the values except for the last one
are integers. This is used to convert to irregular unit
systems like hour/minute/second. The original object will not
be changed.
</p>
</ul>
|