FCCompareNumbers
FCCompareNumbers[x, y]
compares two purely numerical or semi-numerical expressions x
and y
and returns the number of agreeing significant digits calculated from the relative differences.
See also
Overview
Examples
These two numbers disagree in their 6th significant digit
FCCompareNumbers[5.123542342 + 1.23145 I, 5.123542324 + 1.23146 I]
FCCompareNumbers: Minimal number of significant digits to agree in: 6
FCCompareNumbers: Chop is set to 1.ˋ*∧-10
FCCompareNumbers: No number is set to 0. by Chop at this stage.
FCGV(I)FCGV(CommonDigits)(5.09042)
Requiring agreement only in the first 5 significant digits returns 0
FCCompareNumbers[5.123542342 + 1.23145 I, 5.123542324 + 1.23146 I, DigitCount -> 5]
FCCompareNumbers: Minimal number of significant digits to agree in: 5
FCCompareNumbers: Chop is set to 1.ˋ*∧-10
FCCompareNumbers: No number is set to 0. by Chop at this stage.
0
Here even the first significant digit doesn’t agree (obviously)
FCCompareNumbers: Minimal number of significant digits to agree in: 6
FCCompareNumbers: Chop is set to 1.ˋ*∧-10
FCCompareNumbers: No number is set to 0. by Chop at this stage.
FCGV(CommonDigits)(0.778151)
lhs = (0. + 0.*I) - (0.20132103165327941 - 0.00043434443313399246*I)*coeffO^2*parX^2 + (0.047227066764317975)*coeffO^2*parX^2*parY - (0.00005403882927314103)*coeffO^2*parX^2*parY^2 + (1.4588597782189382*^-6 - 4.06569606476957*^-13*I)*coeffO^2*parX^2*parY^3 + (0.03841797609570242 + 0.000028403733516153446*I)*coeffO^2*parX^2*parZ
(0.038418+0.0000284037i)coeffO2parX2parZ−(0.201321−0.000434344i)coeffO2parX2+(0.+0.i)+(1.4588597782189382ˋ*∧-6−4.06569606476957ˋ*∧-13i)coeffO2parX2parY3−0.0000540388coeffO2parX2parY2+0.0472271coeffO2parX2parY
rhs = (-0.20132103165327922 + 0.0004343444331339952*I)*coeffO^2*parX^2 + (0.0472270672349811)*coeffO^2*parX^2*parY - (0.00005403887000187252)*coeffO^2*parX^2*parY^2 + 1.4588601127764193*^-6*coeffO^2*parX^2*parY^3 + (0.038417976095702376 + 0.000028403733516153537*I)*coeffO^2*parX^2*parZ
(0.038418+0.0000284037i)coeffO2parX2parZ−(0.201321−0.000434344i)coeffO2parX2+1.4588601127764193ˋ*∧-6coeffO2parX2parY3−0.0000540389coeffO2parX2parY2+0.0472271coeffO2parX2parY
Here the two above expressions agree in their first 6 significant digits. Notice that the number of the size 10−13 is treated as a numerical fluctuation and consequently removed by Chop
FCCompareNumbers[lhs, rhs]
FCCompareNumbers: Minimal number of significant digits to agree in: 6
FCCompareNumbers: Chop is set to 1.ˋ*∧-10
FCCompareNumbers: Following numbers on the l.h.s. are set to 0. by Chop: {−4.06569606476957ˋ*∧-13}
0
The application of Chop
can be of course disabled
FCCompareNumbers[lhs, rhs, Chop -> False]
FCCompareNumbers: Minimal number of significant digits to agree in: 6
coeffO2parX2parY3FCGV(I)FCGV(Unmatched)(−4.06569606476957ˋ*∧-13)