3

I'm new on Matlab, and I have a question. Can I represent recurring decimals? For example I want to operate 216.6666666… by another number.

I'll appreciate your answers.

Isai
  • 361

3 Answers3

1

As Matlab is just a numerical software this is a senseless question because with machine precision recurring decimals are uninteressting. As I am not that confident with the syntax you could try something like \[ \sum_{k=1}^\infty \frac{b}{(10^p)^k}\] where $b$ is the recurring number and $p$ is the amount of digits.

  • Thanks, I get it. But I mean only to operate simple multiplication or other operation. 435.111111… by another number. I was wondering if it possible in Matlab. – Isai Jun 08 '13 at 17:54
  • 1
    @Isai no it isn't it is machine precision. Matlab forgets everything after 16 digits. So if you calculate $1+10^{-20}$ the result will be $1$ – Dominic Michaelis Jun 08 '13 at 17:57
  • @Isai As I totally have no idea what you are doing I can't recommend anything. I heared there are symbolic toolboxes for matlab which is kind of uninteresting as it is a pure numeric software. For symbolic computations there are programs like Mathematica or Maple – Dominic Michaelis Jun 08 '13 at 18:06
1

If it's absolutely necessary, I suggest using a toolbox to extend to arbitrary precision, and then use a loop to extend this to as far as you want.

However, by default, MATLAB uses standard binary floating point representation. So, you're limited to either 32 or 64 bits of precision. (I forget which.) Thus, you won't really be able to represent a repeating decimal to infinite precision.

That said, MATLAB is pretty good with roundoff error--if I recall correctly, (1/3)*3 still returns 1.

apnorton
  • 17,706
1

As far as I'm aware there is no direct way to represent a recurring decimal.

However, if I interpret your question as "what is a way to represent $216.\dot{6}$ with very high precision", then it would be something like this:

x = 216 + (1/9)*6;

There are probably hacks to get slightly higher precision, but this should suffice for most purposes I can imagine.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Community Jul 10 '23 at 01:54
  • Sorry @Community, but I think you're wrong on this one. If you can provide any concrete ways in which I could improve my answer, let me know, but I personally think it's very clear. Also, do people ever respond positively this type of comment? Like "huh, this bot has told me that my answer is unclear, without any details as to how it has reached that assessment. Guess it's right, and I'll go back and make lots of edits."?? – Danny Garside Jul 10 '23 at 03:47