Does matlab supports rational number types?

조회 수: 13(최근 30일)
Anver Hisham
Anver Hisham 2016년 9월 29일
댓글: Walter Roberson 2023년 3월 8일
I see Matlab stores numbers in floating points [1], which causes round of errors!
For eg:
The above round off error is resulted, because 10^-5 is not a valid 64 bit floating point number in matlab.
However in *Mathematica*, numbers can be stored in rational format [2] (ie integer/integer format), which avoids any round off error for the same computations.
So my question is, will it be possible to avoid such round of errors in matlab?
  댓글 수: 1
Adam 2016년 9월 29일
I think you need the Symbolic Maths toolbox to have handling for this.

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2016년 9월 29일
MATLAB uses floating point numbers by default. This makes it more efficient to do things like work well on large scale linear algebra problems, but it introduces problems like this. There is no fractional integer class in MATLAB. (Well, there was one posted on the FEX that I recall, that worked with my own vpi.)
Yes, you can use the symbolic toolbox to do the kinds of things you want to do. But you then need to recognize that those computations will be quite a bit slower. You trade off speed for ultimate precision. And given the number of people who are never satisfied with the speed of their computers on any given problem, speed is important.
In the end, the real solution is to learn to use floating point arithmetic. That is a skill and sometimes an art. It is the gist of scores of numerical methods courses, teaching students how to do computations without falling under the wheels of a limited number of digits in their computations.
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 3월 8일
quite true, rationals can be useful. Unfortunately, there is no hardware support for rationals.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by