How to get answers in decimal form?

62 views (last 30 days)
Muhammad Ahsan Mukhtar
Muhammad Ahsan Mukhtar on 4 Mar 2018
Answered: Walter Roberson on 4 Mar 2018
Hello all My program is return me answers in x/y form as so, -269871896806271195083/123594766897091545461 How to get answers in decimal form

Answers (1)

Walter Roberson
Walter Roberson on 4 Mar 2018
I can tell from the range of integers shown that you are using the symbolic toolbox. If the numbers had been smaller, you might possibly have had "format rat" in effect, but "format rat" will not generate numbers with as many digits of precision as we see.
To see a result from the symbolic toolbox in decimal form, either use vpa() or double() on the result. vpa() will return a symbolic number with as much of the input as practical converted to decimal form, and it will leave any unresolved variables intact -- so for example if the input had been symbolic 3*x/2 then it would return 1.5*x without complaining about x being unresolved. double() converts to double precision numbers, but it is unable to deal with unresolved variables.

Community Treasure Hunt

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

Start Hunting!