Using uncertainty accuracy

Let's say I have 2 lists containing items:

  • values
  • uncertainties

Values ​​are stored as exact fractions, and I want to print a combined list of numerical values. For example, if I have 1 list of items:

ExA = {5251/977, 19087/53}; ExB = {53/19087, 977/5251}; 

I want the output to be: {5.3746 ± 0.0028, 360.13 ± 0.19} using Err[ExA, ExB] .

Basically, I want the uncertainty to have an element accuracy of 2 digits and a value with the same accuracy as the pair uncertainty. At the moment I have:

 Err[x_, \[CapitalDelta]x_]:= N[x] \[PlusMinus] NumberForm[N[\[CapitalDelta]x], 2]; SetAttributes[Err, Listable]; 

Edit: After almost working, as I want:

 Err[x_, \[CapitalDelta]x_] := PlusMinus[ NumberForm[N[x], {10, 2 - MantissaExponent[\[CapitalDelta]x][[2]]}], NumberForm[N[\[CapitalDelta]x], 2]] SetAttributes[Err, Listable]; 

If the uncertainties of the second category are rounded to 0, then a shorter version is used - I do not want this. For example 1.7007 ± 0.006 , where I want 1.7007 ± 0.0060 .

+4
source share
2 answers

Improved version inspired by Daniel:

 SetAttributes[Err, Listable] Err[n_, e_] := N[n, {∞, 2 - Log10@e }] ± N[e, 2] 

Testing

 ExA = {5251/977, 19087/53, 850341/500000}; ExB = {53/19087, 977/5251, 151/25000}; Err[ExA, ExB] Err[5251/977, 53/19087] 
  {5.3746 ± 0.0028, 360.13 ± 0.19, 1.7007 ± 0.0060}

 5.3746 ± 0.0028 
+4
source

The corrected version:

It can use N [..., 2] for errors, then take N [..., {Infinity, Accuracy [error]}] for central values. This second digitization leads to the fact that the accuracy of each central value corresponds to the accuracy of the corresponding error.

 PlusMinus @@@ Map[{N[#[[1]], {Infinity, Accuracy[#[[2]]]}], #[[2]]} &, Transpose[{ExA, N[ExB, 2]}]] 

Out [113] = {5.3746 [PlusMinus] 0.0028, 360.13 [PlusMinus] 0.19}

Daniel Lichtblau

+7
source

Source: https://habr.com/ru/post/1347944/


All Articles