Display symbolic expressions as rational.

26 ビュー (過去 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 Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by