Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

physics

This module involves mostly around PhysicalNumber and its derivatives. A PhysicalNumber is a DoubleElement, but the uncertainty is stated (it is a Measurement), and knows how to propagate those uncertainties when doing algebraic operations.

Also, a PhysicalNumber can be assigned Units. This can be used for proper displaying the value, and for dimensional analysis.

Example code for how measurements work
import static org.meeuw.physics.Measurement.measurement;
import static org.meeuw.physics.SI.DecimalPrefix.k;
import static org.meeuw.physics.SI.DecimalPrefix.none;
import static org.meeuw.physics.SI.*;
import static org.meeuw.physics.SIUnit.kg;
import static org.meeuw.physics.SIUnit.m;

...
PhysicalNumber twoLightYear = new Measurement(2, 0.1, ly);        //
PhysicalNumber oneParsec = measurement(1, 0.1, pc); // using the static import as a shortcut

assertThat(twoLightYear.plus(oneParsec).toString()).isEqualTo("5.3 ± 0.4 ly");
assertThat(oneParsec.plus(twoLightYear).toString()).isEqualTo("1.61 ± 0.13 pc");
assertThat(oneParsec.plus(twoLightYear).eq(twoLightYear.plus(oneParsec))).isTrue(); //different toString does not mean that they represent a different value
log.info(twoLightYear + "+" + oneParsec + "=" + twoLightYear.plus(oneParsec));

Physical numbers themselves are actually only forming a multiplicative group, because they cannot be added without constraints. In this example they can only be added to each other because both values have the same dimensions (both are about distance).

Physical numbers can freely be multiplied and divided by each other.

Objects of the statistic module can be converted to 'physical numbers' like so:

event rate to measurement
WindowedEventRate rate = ...

PhysicalNumber measurement = new Measurement(rate);
PhysicalNumber rateInHours = measurement.toUnits(Units.of(SI.hour).reciprocal());
statistical number to measurement
 StatisticalDouble statisticalDouble = new StatisticalDouble();
 statisticalDouble.enter(10d, 11d, 9d);

 PhysicalNumber measurement = new Measurement(statisticalDouble, Units.of(SI.min));

 assertThat(measurement.toUnits(Units.of(SIUnit.s)).toString()).isEqualTo("600 ± 45 s");