0

I want to add two arrays length and Apice, It's accuracy to six decimal places. When I use NumberForm in Table I can get normal display results.

L = Table[NumberForm[length[[i]] + Apice[[i]], {20, 6}], {i, 1, 63, 2}]

enter image description here

But if I don't use NumberForm, It only shows six digits.

L1 = Table[length[[i]] + Apice[[i]], {i, 1, 63, 2}]

enter image description here

And if I copy it, some of the data gets weird like 1738.7604379999998 `, but shouldn't it be accurate to six decimal places? Why does this happen?

enter image description here

Two table I used as below:

length = {200.000000, 212.115008, 225.868224, 242.378091, 257.828801, 
   272.097053, 288.473261, 302.301205, 317.722170, 328.294180, 
   341.219205, 354.796398, 365.059240, 380.752053, 393.884689, 
   409.720935, 422.491637, 436.821486, 451.583677, 465.562686, 
   480.832709, 494.209854, 517.194735, 532.293884, 545.823898, 
   557.184369, 576.162592, 592.980488, 608.876434, 621.865923, 
   636.938468, 651.753063, 663.431800, 666.319720, 677.400281, 
   686.410644, 697.074233, 700.348906, 707.746790, 712.203767, 
   715.053581, 721.561347, 724.549487, 725.797116, 728.979858, 
   729.081471, 733.814231, 735.237762, 738.475131, 741.799661, 
   741.771007, 742.562259, 744.025644, 747.807148, 750.559859, 
   751.632473, 752.804419, 755.629828, 756.577273, 756.870575, 
   758.172753, 759.441409, 761.056067};

Apice = {10.000000, 422.115008, 432.115008, 900.361323, 910.361323, 1440.287177, 1450.287177, 2041.061643, 2051.061643, 2697.077993, 2707.077993, 3403.093596, 3413.093596, 4158.904889, 4168.904889, 4972.510513, 4982.510513, 5841.823636, 5851.823636, 6768.969999, 6778.969999, 7754.012562, 7764.012562, 8813.501181, 8823.501181, 9926.509448, 9936.509448, 11105.652528, 11115.652528, 12346.394885, 12356.394885, 13645.086416, 13655.086416, 14984.837936, 14994.837936, 16358.648861, 16368.648861, 17766.072000, 17776.072000, 19196.022557, 19206.022557, 20642.637485, 20652.637485, 22102.984088, 22112.984088, 23571.045417, 23581.045417, 25050.097410, 25060.097410, 26540.372202, 26550.372202, 28034.705468, 28044.705468, 29536.538260, 29546.538260, 31048.730592, 31058.730592, 32567.164839, 32577.164839, 34090.612687, 34100.612687, 35618.226849, 35628.226849};

xzczd
  • 65,995
  • 9
  • 163
  • 468
shrocat
  • 189
  • 7
  • 1
    NumberForm is only a tag for printing, it does not change the underlying number. The default is 6 digits. If a tick (NumberMark) is shown is specified by: $NumberMark $NumberMark=Automatic/True/False. It indicates precision. – Daniel Huber Apr 08 '21 at 07:28
  • As Daniel said, in Mathematica one distinguishes the internal representation of numbers, matrices, etc., and the displayed form. The latter is only for us, humans, convenience and should not be used for copy-pasting. Use assignment instead of copying. – yarchik Apr 08 '21 at 08:11
  • @ Daniel Huber @yarchik Thanks for you two replies, But why the numbers likes 1738.7604379999998 ' appeared? All of my data are to six decimal places, shouldn't they add up to six decimal places too? – shrocat Apr 08 '21 at 13:51
  • Most probably, you are dealing with numbers in machine precision (~15 decimal digits), they are more accurate than just 6 digits. – yarchik Apr 08 '21 at 13:54
  • @yarchik Most of the calculations in the list are correct, but only a few are errow. If it's mechanical precision shouldn't the rest be replaced by zeros? Although this issue does not affect my usage, I would like to understand why this is the case. – shrocat Apr 09 '21 at 05:00
  • Frankly, I do not understand your confusion. You have to better formulate your post. If you round 1738.7604379999998 to 6 decimal digits you get 1738.760438. Why do you say it is an error? Quite generally 1.0 and 0.9999999.. are equal, isn't it? – yarchik Apr 09 '21 at 06:58
  • @ yarchik well, I don't understand why mathematica did this, why it write as 1738.7604379999998. As you can see, most of the calculations are performed to six decimal places except for a few individual values like 1738.7604379999998 as two addends have only six decimal places of accuracy. I just can't see any difference between these values and other normal results. Well, maybe it's just a trivial issue that doesn't warrant me treating him like this. – shrocat Apr 09 '21 at 14:26
  • In short, it's not a matter of precision, it's a matter of displaying. – xzczd Apr 14 '21 at 09:57
  • 1
    Floating-point is binary and does not represent all decimal numbers exactly. Two half-bit rounding errors in the same direction can add up to a one-bit error. For instance, compare FullForm[0.6 + 0.7] with FullForm[1.3]. The rounding errors may be inspected like this, SetPrecision[0.6, Infinity] - 6/10. (Keep in mind that there are potentially three rounding errors in 0.6 + 0.7, two for converting the input decimals to floating-point numbers and one more for the sum.) — This is one reason for decimal computers seem better for human culture, but binary is more efficient electronically. – Michael E2 Apr 14 '21 at 16:53
  • @xzczd Yes,thank you. it solved part of my question, but I still don't understand what it means to change a number that already has a certain dimension of six decimal point accuracy into a larger decimal point accuracy. And Michael E2's word solved it. – shrocat Apr 15 '21 at 02:26
  • @Michael E2 Thanks, That's a very good answer to my question. – shrocat Apr 15 '21 at 02:30
  • For your new question in the comment, possible duplicate: https://mathematica.stackexchange.com/a/188135/1871 There should be more. – xzczd Apr 15 '21 at 02:37

0 Answers0