Decimal to Fraction Calculator
You can use MATLAB's rat() function to obtain a rational approximation of a decimal value. For example, rat(0.625) gives a representation equivalent to 5/8. If you simply want to verify decimal/fraction conversions without running MATLAB, a browser-based decimal-to-fraction calculator can also be useful.
4 Comments
Time DescendingFloating-point form is generally preferred for numerical computation, while rational form is useful for interpretation, pattern recognition, and mathematical presentation.
And of course, rat also gives us some juicy tidbits, like these classic rational approximations for pi.
[N,D] = rat(pi,0.01)
[N,D] = rat(pi) % the default tolerance
And even a not so good approximation.
[N,D] = rat(pi,1) % The lazy schoolboard approximation
When I wear my numerical analyst hat, it is not too often I want to work in rational form, because usually I need floating point numbers without that rational approximation. But sometimes rational approximations are important to see what is happening. And of course, sometimes the rat format is nice to have too.
format rat
hilb(5)
You can also use sym to get that rational form.
sym(0.625)
Sign in to participate