Displaying numbers explicitly?
5 次查看(过去 30 天)
显示 更早的评论
I'd like MATLAB to display numbers explicitly whenever possible - that is to say, instead of a rounded decimal number, I want it to express the value using only whole numbers, such as 2+sqrt(5), pi/2 or e^3. If it can't do that out of the box, is there perhaps a plugin that lets me do that?
0 个评论
采纳的回答
Walter Roberson
2017-5-23
If you are starting from rational values and manipulating them, and want the results to be in the form you show, then the Symbolic Toolbox will generally do that.
But if you are starting from floating point numbers and want to find some representation in terms of rationals, sqrt() of rational, Pi, and exp() of rationals, then there is a lot of different ways to do that, most of which will be more or less accidental.
For example, sin(1) is about 0.841470984807897 which is not so different from sqrt(2) - pi/2 + 1 which is 0.843417235578199 ... more or less by chance.
sin(1) could also be expressed as being approximately
1 - 1/6 + 1/120 - 1/5040 + 1/362880 - 1/39916800 + 1/6227020800 - 1/1307674368000 + 1/355687428096000 - 1/121645100408832000 + 1/51090942171709440000 - 1/25852016738884976640000 + 1/15511210043330985984000000 - 1/10888869450418352160768000000 + 1/8841761993739701954543616000000 - 1/8222838654177922817725562880000000
which I derive from the taylor series.
but perhaps you would prefer
1 + 1/(-6 + 1/(-3 + 1/(-4 + 1/(-19))))
which is the output of rat(sin(1))...
更多回答(1 个)
Steven Lord
2017-5-23
Symbolic Math Toolbox can do some of this and get you close in other scenarios.
>> five = sym(5);
>> x = 2 + sqrt(five)
x =
5^(1/2) + 2
>> y = sym(pi)/2
y =
pi/2
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!