Does matlab supports rational number types?
조회 수: 13(최근 30일)
표시 이전 댓글
Anver Hisham 2016년 9월 29일
댓글: Walter Roberson 2023년 3월 8일
I see Matlab stores numbers in floating points , which causes round of errors!
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  (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
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 2023년 3월 8일
quite true, rationals can be useful. Unfortunately, there is no hardware support for rationals.
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!