Display symbolic expressions as rational.

조회 수: 30 (최근 30일)
Agustín Rico
Agustín Rico 2021년 2월 2일
댓글: Robert Ukrow 2022년 1월 26일
How can I display symbolic expressions as rationals? Functions like sympref or vpa allows to display in decimal format, but doesn't provide a way to display symbolic expressions as rationals.
For example:
syms x
(1/2)*(3*x^2)
ans =
1.5000*x^2
Instead of that output I desire the rational expression (or similar):
(3*x^2)/2
  댓글 수: 1
James Tursa
James Tursa 2021년 2월 2일
That's what I get:
>> syms x
(1/2)*(3*x^2)
ans =
(3*x^2)/2
Do you have something set in preferences that is forcing the decimal output?

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

채택된 답변

madhan ravi
madhan ravi 2021년 2월 2일
편집: madhan ravi 2021년 2월 2일
syms x
sympref('FloatingPointOutput',true);
(1/2)*(3*x^2)
ans = 
sympref('FloatingPointOutput',false);
(1/2)*(3*x^2)
ans = 
  댓글 수: 3
Diaa
Diaa 2021년 12월 18일
Thanks to you for this answer, and special thanks to google algorithm for bringing me here without wasting my whole day.
Robert Ukrow
Robert Ukrow 2022년 1월 26일
Had the same problem and it worked..thanks !

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by