net.grelf
Class MeasuredValue

java.lang.Object
  extended by net.grelf.MeasuredValue
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class MeasuredValue
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Record to hold a measured value x, its standard error S and its units, so it can be stated as x +/- S units. The theory used is explained in N.C.Barford "Experimental Measurements: Precision, Error and Truth", Addison-Wesley 1967.

See Also:
Serialized Form

Constructor Summary
MeasuredValue(java.util.Collection<java.lang.Double> x, java.lang.String units)
          Calculates mean value and standard error from the given data.
MeasuredValue(double[] x, java.lang.String units)
          Calculates mean value and standard error from the given data.
MeasuredValue(double x, double stdErr, java.lang.String units)
          If stdErr is unknown set it to 0.0.
 
Method Summary
 MeasuredValue add(double a)
          Returns a new MeasuredValue in which the value has number a added to it but stdErr is unchanged.
 MeasuredValue add(MeasuredValue x)
           
 MeasuredValue clone()
          Returns a new MeasuredValue object with the same data.
 MeasuredValue divide(MeasuredValue x)
           
 boolean equals(java.lang.Object other)
          Tests for equality of value, sigma and units to 12 decimals.
 double getStdErr()
          Standard error, S.
 java.lang.String getUnits()
           
 double getValue()
          Value, x.
 int hashCode()
           
 MeasuredValue multiply(double a)
          Returns a new MeasuredValue in which both the value and the standard error have been multiplied by number a.
 MeasuredValue multiply(MeasuredValue x)
           
 double probablyEquals(java.lang.Object other)
          Still experimental - Aims to returns probability of equality, from 0 to 1.
 MeasuredValue subtract(MeasuredValue x)
           
 java.lang.String toString()
          Outputs in the form "value +/- stdErr units" (but only "value units" if stdErr is 0.0).
 java.lang.String toString(java.text.DecimalFormat df)
          Outputs in the form "value +/- sigma units" (but only "value units" if sigma is 0.0).
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MeasuredValue

public MeasuredValue(double x,
                     double stdErr,
                     java.lang.String units)
If stdErr is unknown set it to 0.0. That may also be taken to mean that the value is precisely known.


MeasuredValue

public MeasuredValue(double[] x,
                     java.lang.String units)
Calculates mean value and standard error from the given data. S = sqrt ((sumX2 / n - mean * mean) / (n - 1))


MeasuredValue

public MeasuredValue(java.util.Collection<java.lang.Double> x,
                     java.lang.String units)
Calculates mean value and standard error from the given data. S = sqrt ((sumX2 / n - mean * mean) / (n - 1))

Method Detail

getValue

public double getValue()
Value, x.


getStdErr

public double getStdErr()
Standard error, S.


getUnits

public java.lang.String getUnits()

toString

public java.lang.String toString()
Outputs in the form "value +/- stdErr units" (but only "value units" if stdErr is 0.0).

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.text.DecimalFormat df)
Outputs in the form "value +/- sigma units" (but only "value units" if sigma is 0.0). Specify the format of the numbers.


equals

public boolean equals(java.lang.Object other)
Tests for equality of value, sigma and units to 12 decimals. Consider using probablyEquals () instead.

Overrides:
equals in class java.lang.Object

probablyEquals

public double probablyEquals(java.lang.Object other)
Still experimental - Aims to returns probability of equality, from 0 to 1. Units must be the same. Values and sigmas are then used to estimate probability of the measurement being the same, assuming Gaussian distributions.


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

clone

public MeasuredValue clone()
Returns a new MeasuredValue object with the same data.

Overrides:
clone in class java.lang.Object

add

public MeasuredValue add(double a)
Returns a new MeasuredValue in which the value has number a added to it but stdErr is unchanged. The current object is unchanged.


add

public MeasuredValue add(MeasuredValue x)
                  throws MixedUnitsException
Throws:
MixedUnitsException

subtract

public MeasuredValue subtract(MeasuredValue x)
                       throws MixedUnitsException
Throws:
MixedUnitsException

multiply

public MeasuredValue multiply(double a)
Returns a new MeasuredValue in which both the value and the standard error have been multiplied by number a. The current object is unchanged.


multiply

public MeasuredValue multiply(MeasuredValue x)
                       throws MixedUnitsException
Throws:
MixedUnitsException

divide

public MeasuredValue divide(MeasuredValue x)
                     throws MixedUnitsException
Throws:
MixedUnitsException