How to show exact answers in MATLAB
Mostrar comentarios más antiguos
Hello everyone, I run into this exact answer problem with MATLAB pretty frequently. My problem is right now when I'm trying to do an inverse of a matrix containing square roots, it gives me answers in fractions or in decimals. I want it to show the square roots and other functions. How would I go about doing this? I've googled a while and all they say are precision values and rounding and what not, but nothing to do with these square roots.
2 comentarios
Karan Gill
el 14 de Nov. de 2017
Use symbolic arithmetic. See: https://www.mathworks.com/help/symbolic/choose-symbolic-or-numeric-arithmetic.html
As Walter answered, use
>> inv([sqrt(sym(21))])
ans =
21^(1/2)/21
Respuestas (3)
Mahdi
el 24 de Sept. de 2013
Why don't you try an approach where you use square the matrix to find out what the numbers are?
For example
MatrixSquared=Matrix.^2;
Then you would be able to see which numbers were square rooted. I would also suggest placing
format rat
before the code.
1 comentario
Suh-Shin
el 24 de Sept. de 2013
Sounds like you're trying to do a symbolic matrix inverse operation. The Symbolic Math Toolbox will let you do that, see
6 comentarios
Suh-Shin
el 24 de Sept. de 2013
Walter Roberson
el 25 de Sept. de 2013
inv([sqrt(sym(21))])
Seetha Rama Raju Sanapala
el 9 de Feb. de 2018
I want to get answers in fractional form for operations on fractions like 1/2 + 15/17, 2/5*3/16 etc. Which route is better - sym or format rat? Why?
Walter Roberson
el 9 de Feb. de 2018
sym as early as possible, before you even do the division. For example sym(15)/sym(17). Otherwise you are losing precision in the fractions. format rat does not return the true fraction corresponding to the internal representation of the floating point numbers: format rat uses a continued fraction approach to try to find the closest fraction within a tolerance. So where true fraction might be 38183/86917, format rat might decide that 38/87 is "close enough" to display
Seetha Rama Raju Sanapala
el 9 de Feb. de 2018
Great clarity, @ Walter Roberson! Thanks.
Karan Gill
el 13 de Feb. de 2018
Shashank Prasanna
el 24 de Sept. de 2013
Use format to reset your display format or choose a different display format:
>> format
1 comentario
Suh-Shin
el 24 de Sept. de 2013
Categorías
Más información sobre Common Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!