MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Export table problem

  • To: mathgroup at
  • Subject: [mg30938] Re: [mg30891] Export table problem
  • From: Tomas Garza <tgarza01 at>
  • Date: Thu, 27 Sep 2001 02:17:00 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

You're quite right. I was too hasty in assuming that people only use Excel
outside Mathematica!

I guess the problem has to do with a very complicated subject, viz. the
arithmetic used by Mathematica. After some thinking, I concluded that your


must have different degrees of error when they are computed, so that when
the error is "small" they are exported as they appear in the display, and
otherwise they are exported with as many figures as the precision allows.
This seems to be the case for i = 7, 14 and 19 above. I checked this in the
AddOn NumericalMath`Microscope`, where I found the following illuminating
text: "Numbers on a computer comprise a discrete set. There are gaps between
the numbers and when you do arithmetic the result often is not
representable. When the result falls between two representable numbers the
best that can be done is to use the closest representable number as the
result instead of the correct result. The set of numbers that can be
represented on a computer in floating-point format are commonly referred to
as the set of machine numbers."  This led me to calculate the "MachineError"
for your table


{0.25 Ulps,0.25 Ulps,-0.3125 Ulps,0.25 Ulps,-0.1875 Ulps,-0.3125 Ulps,
  0.46875 Ulps,0.25 Ulps,0.03125 Ulps,-0.1875 Ulps,0.296875 Ulps,-0.3125
  0.078125 Ulps,0.46875 Ulps,-0.140625 Ulps,0.25 Ulps,-0.359375 Ulps,
  0.03125 Ulps,0.421875 Ulps,-0.1875 Ulps}

(the difference between two consecutive machine numbers is called an ulp -
"unit in the last place"). Here you can see that the machine errors for j =
7, 14 and 19 are indeed the largest ones (0.46875, 0.46875 and 0.421875,
respectively) in the list, and this is why (I venture to guess, since I am
far from being a computer expert, let alone a Mathematica expert) those 3
particular numbers are exported with so many decimals. We should look
forward to a good, informed explanation from the great gurus.

 Now, back to your original problem. The difficulty arises because you want
to keep at most 2 decimal figures, and you want to force this using Round
together with multiplication and division by 100 (this, by the way, is what
I always do - but, then, I only use Excel if at all and this why I have
never have experienced the situation). We see that Mathematica refuses to
export the result with only 2 decimals because of the error problem
mentioned above. One way out (not the only one, I'm sure, but this one seems
to work) is to look at the real digits in the result, throw away all but the
first two decimals, and reconstruct each quotient i/5 and i/3. I propose the
following apparently messy procedure: the function red[r_] takes a number r,
works with the string of its real digits, throws away all but the first two
after rounding, and returns the new expression for r:

    v={{z[[1,1]], If[z[[1,3]]>=5, z[[1,2]]+1,z[[1,2]]]}, z[[2]]};

(it's just an exercise in list and string manipulation). I then calculate
the following



and then


Now I read in table.txt from Microsoft Word and it gives exactly what you
wanted! Actually, you don't need the ToExpression part in the function red,
since you are going to use a text editor, where there is no difference
between strings and numbers.



----- Original Message -----
From: <maarten.vanderburgt at>
To: mathgroup at
Subject: [mg30938] Re: [mg30891] Export table problem

> Tomas,
> You should open it in a text editor. Depending on your settings, Excel
> round or truncates when you open the txt file.
> BR
> maarten

  • Prev by Date: Re: Handling several variables at once during matrix multiplications
  • Next by Date: Help! FindRoot output to list...
  • Previous by thread: Re: Export table problem
  • Next by thread: Re: Export table problem