0

I've been using the uncertainties library for calculation of the gaussian error propagation with good results for quite some time.

The problem is that I use the numpy library for all mathematical functions like sin(), sqrt(), and so on. Which does not support any arguments of ufloat type. Thus making it impossible to calculate the error propagation of a function with any mathematical function implemented with numpy.

If I am not mistaken a simple typecast doesn't fix the issue because the ufloat data type isn't "natural" to python.

So let me give you an example of the issue.

import numpy as np
from uncertainties import *

#Stack example
def function_1():
    # When not using uncertainties np works as expected
    Var_1 = 0.13
    Var_2 = 0.32
    Result_1 = 1/(np.sqrt(np.sin(Var_1*Var_2)))
    print(Result_1)

    # However it doesn't work with ufloat data type
    var1 = ufloat(0.31, 0.10)
    var2 = ufloat(0.32, 0.02)
    result = 1/(np.sqrt(np.sin(var1*var2)))
    print(result)
function_1()

So summarizing I would like to know how to calculate the error propagation of functions containing standard mathematical expressions like sin(), sqrt(), etc.

Of course if a different library provides functions compatible with uncertainties, then I don't need to stick with numpy, it was just an example.

All help is appreciated, thanks in advance!

Mark
  • 131
  • 9
  • 1
    Have you read the documentation? The `uncertainties.umath` module includes implementations of most mathematical functions for interval objects. https://pythonhosted.org/uncertainties/ – Tim Roberts Dec 23 '22 at 23:31

0 Answers0