This package was primarily developed to assist in calculating and writing the estimated standard deviation according to Gaussian error propagation in LaTex. To calculate the uncertainties, the package uses the gaussian error propagation.
Rounding follows the following scheme:
- If the first non-zero digit of the standard deviation is greater than two and is followed by further digits, this digit is rounded up.
- Otherwise, the subsequent digit is rounded up.
- The value is then rounded to the next even number at the same digit.
The package is still in development and will be updated with more features in the future.
Core feature of this package is the rounding of the uncertainties to the correct number of significant figures. Suggested by the physical practicals of the TU Berlin is the following rule:
- If the first non zero digit of the uncertainty is 1 or 2, round to 2 significant non zero figures.
- Else round to 1 non zero significant figure.
- The significant figure is alway rounded up.
The package also provides a function to get the function to calculate the uncertainty in LaTeX format without and with substitution of the variables with the values.
To install the package, simply download the newest release from the releases page page and install it with pip:
pip install physpract-{version}-py3-none-any.whl
To use the package, simply import it and use the functions provided by the package. The package is still in development and will be updated with more features in the future.
To define a value with an uncertainty, simply create a new Value
object with the value and the uncertainty as arguments. The value can be accessed with the value
attribute and the uncertainty with the uncertainty
attribute. The value can be printed with the print
function.
from physpract.uncertainties import Value
a = Value(1, 0.1)
b = Value(2, 0.2)
c = a + b
# Print the value
print(c)
# Output: 3.00 ± 0.23
print(c.eq())
# Output: x_0 + x_1 = 3.00 ± 0.23
# Print the value and the uncertainty
print(c.value, c.uncertainty)
# or
print(c.v, c.u)
# Output: 3.00 0.23
# Print the not rounded value and the uncertainty
print(c.value_not_rounded, c.uncertainty_not_rounded)
# or
print(c.vnr, c.unr)
# Output: 3.0 0.223606797749979
To use the variable names in the LaTeX output, simply pass the variable names as a string to the Value
object.
from physpract.uncertainties import Value
a = Value(1, 0.1, "a")
b = Value(2, 0.2, "b")
c = a + b
print(c)
# Output: 3.00 ± 0.23
print(c.eq())
# Output: a + b = 3.00 ± 0.23
To use the variable names and units in the LaTeX output, simply pass the variable names and units as a string to the Value
object. For the units, sympy.physics.units
must be used.
from physpract.uncertainties import Value
from sympy.physics.units import meter, second
a = Value(1, 0.1, "a", meter)
b = Value(2, 0.2, "b", second)
c = a/b
# Print the value
print(c)
# Output: 0.50 ± 0.08 meter/second
print(c.eq())
# Output: a/b = 0.50 ± 0.08 meter/second
To print the LaTeX output of the equation, use the latex
function.
from physpract.uncertainties import Value
from sympy.physics.units import meter, second
a = Value(1, 0.1, "a", meter)
b = Value(2, 0.2, "b", second)
c = a/b
# Print the LaTeX output
print(c.latex())
# Output: \SI{0.50(8)}{\meter\per\second}
# Print the LaTeX output with equation
print(c.latex(equation=True))
# Output: \frac{a}{b}=\SI{0.50(8)}{\meter\per\second}
To print the equation to calculate the uncertainty, use the get_equation
function of either the Value.value
or Value.uncertainty
attribute. The equation is returned as a string and can be printed with the print
function. To print the equation in LaTeX format, use the latex
function of get_equation
.
from physpract.uncertainties import Value
from sympy.physics.units import meter, second
a = Value(1, 0.1, "a", meter)
b = Value(2, 0.2, "b", second)
c = a/b
# Print the equation of the value
print(c.value.get_equation())
# Output: a/b
# Print the LaTeX equation of the value
print(c.value.get_equation().latex())
# Output: \frac{a}{b}=\frac{\SI{1.0(0.1)}{\meter}}{\SI{2.0(0.2)}{\second}}
# Print the equation of the uncertainty
print(c.uncertainty.get_equation())
# Output: sqrt(\Delta a**2/b**2 + \Delta b**2*a**2/b**4)
# Print the LaTeX equation of the uncertainty
print(c.uncertainty.get_equation().latex())
# Output: \Delta\left(\frac{a}{b}\right)=\sqrt{\frac{\Delta a^{2}}{b^{2}} + \frac{\Delta b^{2} a^{2}}{b^{4}}}=\sqrt{\frac{\left(\SI{0.1}{\meter}\right)^{2}}{\left(\SI{2.0}{\second}\right)^{2}} + \frac{\left(\SI{0.2}{\second}\right)^{2} \left(\SI{1.0}{\meter}\right)^{2}}{\left(\SI{2.0}{\second}\right)^{4}}}
Value:
Uncertainty: