필터 지우기
필터 지우기

Displaying numbers explicitly?

조회 수: 3 (최근 30일)
Jakob Gillinger
Jakob Gillinger 2017년 5월 23일
댓글: Jakob Gillinger 2017년 5월 23일
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?

채택된 답변

Walter Roberson
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
Jakob Gillinger
Jakob Gillinger 2017년 5월 23일
Symbolic Toolbox should cover it nicely. Thanks for the help.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
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

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by