Symbolic printing without extensive decimals

1 回表示 (過去 30 日間)
Ramses Young
Ramses Young 2021 年 4 月 11 日
コメント済み: Star Strider 2021 年 4 月 11 日
syms x
f=x*1231871.1561876*5618965/3156651894-561894+4849159*15844/5189;
l=vpa(x*1231871.1561876*5618965/3156651894-561894+4849159*15844/5189);
fprintf('%s\n',f)
fprintf('%s\n',l)
(1351321833700369665875*x)/616259847708475392 + 7647426328677875/536870912
2192.7792938728320167173931401797*x + 14244441.555212950333952903747559
I am trying to get my problem to print more efficiently, I have tried the vpa tool, and it works nicely, but I have no customization (as far as im aware) as to how to control the number of decimal places on the polynomial that is being printed using these commands while having a symbolic function/polynomial.
How can I tidy up this so that it prints in an easier to read format, with, for example, 5 decimal places rather than the amount it has?

採用された回答

Star Strider
Star Strider 2021 年 4 月 11 日
Set digits to whatever value you want:
syms x
f=x*1231871.1561876*5618965/3156651894-561894+4849159*15844/5189;
digits(5)
l=vpa(x*1231871.1561876*5618965/3156651894-561894+4849159*15844/5189);
fprintf('%s\n',f)
fprintf('%s\n',l)
producing:
(1351321833700369665875*x)/616259847708475392 + 7647426328677875/536870912
2192.8*x + 1.4244e+7
.
  2 件のコメント
Ramses Young
Ramses Young 2021 年 4 月 11 日
Perfect, thanks!
Star Strider
Star Strider 2021 年 4 月 11 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Martinez Tutt
Martinez Tutt 2021 年 4 月 11 日
Try using (line spacing)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by