Display symbolic expressions as rational.

31 次查看(过去 30 天)
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