|
JScience v3.3 | ||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Class Summary | |
|---|---|
| Constants | This class provides most accurate physical constants measures; the more accurate the constants, the higher the precision
of the calculations making use of these constants. |
| Measure<Q extends Quantity> | This class represents a measurable amount; the nature of the amount
is deduced from the measure unit; the quality of
the measure is given by the measurement error. |
| MeasureFormat | This class provides the interface for formatting and parsing measures instances. |
| MeasureVector<Q extends Quantity> | This class represents a measurement vector for which all components are of the same type. |
| Exception Summary | |
|---|---|
| MeasureException | Signals that an illegal measure operation has been performed. |
Provides support for exact or arbitrary precision measurements.
quantities:Measure
base class is parameterized with the quantity onto which the measure applies
(Measure<Q extends Quantity>). If the quantity is not known then
<?> can be used. For example:
Measure<?> carMileage = Measure.valueOf(20, MILE.divide(GALLON_LIQUID_US));
Measure<?> gazPrice = Measure.valueOf(1.2, EUR.divide(LITER)); // 1.2 €/L
If the expected quantity result for a measure is known but has been lost
due to the calculations performed; better than using <?>, the measure can
be stated in a known unit for this quantity. It ensures dynamic check of
the measure dimension/unit and avoid compiler warnings. For example:
// No problem here as the measure type is infered from the unit.
Measure<Length> tripDistance = Measure.valueOf(400, KILO(SI.METER));
// Warning as the measure type is lost during calculation.
Measure<Money> tripCost = tripDistance.divide(carMileage).times(gazPrice);
// Better: Dimension check and no warning (USD is a Currency (Unit<Money>))
Measure<Money> tripCost = tripDistance.divide(carMileage).times(gazPrice).to(USD);
It should be noted that this conversion is immediate if the specified
unit is the actual unit for the measure (which is then returned unchanged).
Error calculations:
Measures take into account measurement and calculation errors. For example:
import static org.jscience.physics.units.SI.*;
...
Measure<Length> x = Measure.valueOf(1.0, METER);
Measure<Velocity> v = Measure.valueOf(0.01, METER_PER_SECOND);
Measure<Duration> t = Measure.valueOf(1.0, MICRO(SECOND));
for (int i = 0; i < 10000000; i++) {
x = x.plus(v.times(t));
}
MeasureFormat.setInstance(MeasureFormat.getExactDigitsInstance());
System.out.println(x);
> 1.10000000 m
The exact value is guaranteed to be in the range: ]1.09999999 m, 1.10000001 m[
The same calculation using primitive double type would have display:
> 1.099999999392253
with no idea on the accuracy of the result.
Dimension checking.
The unit of a measure determinates its type.
For example, Measure.valueOf("1 µm") and Measure.valueOf("1.2 ft")
are Length measures (both "µm" and "ft" units
are derived from SI.METER). Multiple physical models are supported (e.g. Standard,
Relativistic, High-Energy, Quantum
and Natural). The physical model sets which conversions are allowed or disallowed.
For example:
RelativisticModel.select(); // Selects a relativistic model.
Measure<Length> x = Length.valueOf(100, NonSI.INCH);
x = x.plus(Measure.valueOf("2.3 µs")).to(METER); // Length and Duration can be added.
Measure<Mass> m = Quantity.valueOf("12 GeV").to(KILOGRAM); // Energy is compatible with mass (E=mc2)
System.out.println(x);
System.out.println(m);
> (692.06265340000008 ± 5.1E-13) m
> (2.1391940763025056E-26 ± 4.3E-42) kg
Measurement vectors
This package provides measurement vectors compatible with the mathematical vectors
module. For example:
MeasureVector<Velocity> velocityVector = MeasureVector.valueOf(METER_PER_SECOND, 12.3, -2.9);
Measure<Velocity> velocity = velocityVector.norm();
Matrix<Measure<?>> M = ...;
Vector<Measure<?>> solution = M.solve(velocityVector);
Physical Constants
Finally, this package holds the latest physical constants measurements
with the best known accuracy (the more accurate the constant, the higher the precision of the calculations
making use of these constants).
Overview
Package
Class
Tree
Deprecated
Index
Help
JScience v3.3
PREV PACKAGE
NEXT PACKAGE
FRAMES
NO FRAMES
Copyright © 2006 JScience.