How do I simplify a symbolic expression into numeric output?

My answer for a calculation is:
ans =
(3060513257434037*x1^2)/1125899906842624 + x1 +
(3060513257434037*x2^2)/1125899906842624 + x2 +
4186413164276661/1125899906842624
How can I get MATLAB to display the answer with the fraction evaluated in decimal format?

2 件のコメント

Mithlesh Kumar
Mithlesh Kumar 2016 年 12 月 30 日
編集済み: Mithlesh Kumar 2016 年 12 月 30 日
As you have used symbolic function, to get output displayed in decimal format use "vpa" command.
Ganesh P. Prajapat
Ganesh P. Prajapat 2020 年 6 月 10 日
This comes out of the 'subs' command when 'syms' is associated. The simple way to have a simplified solution is, use vpa(x,d) command where x gets simplified upto d digits.

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

回答 (3 件)

Walter Roberson
Walter Roberson 2011 年 1 月 20 日

10 投票

Use vpa() to convert fractions and numeric constants (such as Pi) into symbolic fixed-point arithmetic, such as might be used for further symbolic processing.
Use double() to convert fractions and numeric constants (such as Pi) into binary floating point arithmetic, such as might be used for further processing at the Matlab level.

3 件のコメント

Christopher Creutzig
Christopher Creutzig 2011 年 1 月 21 日
Symbolic does not use fixed-point arithmetic, it uses variable-precision floating-point arithmetic (in addition to exact arithmetic).
Luis Enciso
Luis Enciso 2014 年 4 月 18 日
I had the same problem, but vpa is nice for me, thank you so much.
Jilan Samiuddin
Jilan Samiuddin 2015 年 11 月 2 日
perfect!

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

Ned Gulley
Ned Gulley 2011 年 1 月 20 日

6 投票

It looks like you've got a symbolic expression.
You can substitute real numeric values for x1 and x2 like this:
% Define your expression
syms x1 x2
f = (3060513257434037*x1^2)/1125899906842624 + x1 + ...
(3060513257434037*x2^2)/1125899906842624 + x2 + ...
4186413164276661/1125899906842624;
% If x1 is 1 and x2 is 2, you would type this
subs(f,{x1,x2},{1,2})
And the answer is...
ans =
20.3097
See the doc for subs for more information.
kalpana
kalpana 2013 年 8 月 12 日

3 投票

use MatlabFunction() to convert symbolic to numeric expression.

タグ

質問済み:

2011 年 1 月 20 日

コメント済み:

2020 年 6 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by