# Propagation of uncertainty

Is there any simple method in sage to do a calculation with uncertainties? Something like this: $(10\pm2) * (3\pm1) = (30\pm18)$. Or with a more "sophisticated" formula: $(30\pm11.67)$ because of $(10 \times 3 \times \sqrt{(2/10)^2 + (1/3)^2} = 11.67)$. Both ways are taken from here, but the second way is also described on wikipedia.

To do such calculations I have already seen a method using RIF's like the following:

R=RIF(8,12)*RIF(2,4)
R.str(error_digits=2); R.lower(); R.upper(); R.center()


Which outputs:

32.?16
16.0000000000000
48.0000000000000
32.0000000000000


But with as one can see the center result is $32$ ($\frac{16+48}{2}$) instead of $30$ ($10*3$). Also I think it is a bit complex, because one has to calculate the upper an lower limits before, instead of a simple thing like:

uncertain(10,2)


(And as last point, I think result with the question mark is not very nice)

If one of my calculations is wrong please let me know, because I am new to error calculations.

edit retag close merge delete

Sort by » oldest newest most voted

Your approach with RIF is the right one.

You should understand that the product of the middles is usually not equal to the middle of the products, not every map is flat! Actually, the result $32\pm 16$ given by RIF is more accurate than your $30\pm 18$, since the interval $[16,48]$ is strictly contained in the interval $[12, 48]$, and both are valid results.

The result using the "sophisticated" formula is wrong: the smallest product between $10\pm 2$ and $3\pm 1$ is $8\times 2 = 16$, and is smaller than $30-11.67 = 18.33$. It uses a truncated Taylor estimation, so it can only be used to have a quick rough estimate of the error, not a guaranteed upper bound, see the Caveats and warnings section.

If you want to use custom functions instead of RIF defaults, you can define:

sage: uncertain = lambda value, error : RIF(value-error, value+error)
sage: value_error = lambda r : (r.center(), r.absolute_diameter()/2)


Then you can do:

sage: R = uncertain(10,2) * uncertain(3,1)
sage: value_error(R)
(32.0000000000000, 16.0000000000000)

more

Thank you for your answer. To the second point (wrong method/calculation): I haven't read the whole Wikipedia article, because I got it first from the other site. Thanks for pointing that out. Also your "custom functions" are really nice.

( 2013-10-26 09:19:12 -0600 )edit