can I convert a decimal number into rational number in matlab and how can i write a factorial of large number like 30 completely i.e. in complete integral from instead of decimal form

9 views (last 30 days)
can I convert a decimal number into rational number in matlab. How can I write a factorial of large number like 30 completely i.e. in complete integral from instead of decimal form.

Answers (2)

Stephen23
Stephen23 on 21 Feb 2016
Try using rat or rats:
>> [N,D] = rat(0.8)
N =
4
D =
5
>> rats(0.8)
ans =
4/5

Star Strider
Star Strider on 21 Feb 2016
To get the full numeric precision for ‘factorial(30)’, you would need the Symbolic Math Toolbox (although I believe John D’Errico has a File Exchange contribution that will provide the same results).
Example:
fd = factorial(30) % Double-Precision Representation
fs = vpa(factorial(30), 40) % Symbolic Math Toolbox ‘vpa’ Representation
fd =
2.65252859812191e+32
fs =
265252859812191032188804700045312.0

Categories

Find more on Discrete Math 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!