How to show exact answers in MATLAB
414 次查看(过去 30 天)
显示 更早的评论
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 个评论
Karan Gill
2017-11-14
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
回答(3 个)
Mahdi
2013-9-24
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.
Shashank Prasanna
2013-9-24
Use format to reset your display format or choose a different display format:
>> format
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!