Lets say I have 2 lists, containing elements:
Values are stored as exact fractions and I want to print out combined list of numerical values. For example if i have 1 element lists:
ExA = {5251/977, 19087/53};
ExB = {53/19087, 977/5251};
I want the output to be: {5.3746 ± 0.0028, 360.13 ± 0.19}
, with using Err[ExA, ExB]
.
Basically I want uncertainty to have a element precision of 2 digits and value to have same precision as the paired uncertainty. At the moment I have:
Err[x_, \[CapitalDelta]x_]:=
N[x] \[PlusMinus] NumberForm[N[\[CapitalDelta]x], 2];
SetAttributes[Err, Listable];
Edit: Following almost works 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 uncertainties second digit rounds to 0, then shorter version is used - I do not want that. For example 1.7007 ± 0.006
where I want 1.7007 ± 0.0060
.
Corrected version:
Can use N[...,2] on the errors, then take N[...,{Infinity,Accuracy[error]}] on the central values. THis second numericization causes the accuracy of each central value to match the accuracy of its 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
Improved version, inspired by Daniel's answer:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With