Symbolic Expression Sum Same Denominator

30 ビュー (過去 30 日間)
Miraç Gülgönül
Miraç Gülgönül 2018 年 12 月 26 日
編集済み: Star Strider 2018 年 12 月 26 日
I have a symbolic experssion in the form: (where are symvars)
(3*a)/8 + (3*b)/8 + c/4
I would like this to be in the form of the same denominator, like:
(3*a + 3*b + 2*c) / 8
How can I achieve this ?

回答 (2 件)

Star Strider
Star Strider 2018 年 12 月 26 日
編集済み: Star Strider 2018 年 12 月 26 日
Try this:
syms a b c
Eqn = (3*a)/8 + (3*b)/8 + c/4
[Eqnn,Eqnd] = numden(Eqn)
producing:
Eqnn =
3*a + 3*b + 2*c
Eqnd =
8
Unfortunately, if you express it again as:
NewEqn = Eqnn / Eqnd
the result is the original format for ‘Eqn’.
EDIT —
The best you can hope for is a LaTeX expression for your fraction:
syms a b c
Eqn = (3*a)/8 + (3*b)/8 + c/4
[Eqnn,Eqnd] = numden(Eqn)
fn = latex(Eqnn);
fd = latex(Eqnd);
Expr = sprintf('$f(a,b,c) = \\frac{%s}{%s}$', fn, fd)
producing:

madhan ravi
madhan ravi 2018 年 12 月 26 日
編集済み: madhan ravi 2018 年 12 月 26 日
syms a b c
eqn = (3*a)/8 + (3*b)/8 + c/4
simplifyFraction(eqn,'Expand',1) % the best way to simplify a fraction by expanding also returns the same
  2 件のコメント
Miraç Gülgönül
Miraç Gülgönül 2018 年 12 月 26 日
編集済み: Miraç Gülgönül 2018 年 12 月 26 日
I don't understand, this outputs
eqn =
(3*a)/8 + (3*b)/8 + c/4
ans =
(3*a)/8 + (3*b)/8 + c/4
so no change.
madhan ravi
madhan ravi 2018 年 12 月 26 日
編集済み: madhan ravi 2018 年 12 月 26 日
Yes exactly matlab is not able to compute those fractions as you desire.
Try:
bb=factor(eqn) % gives your partial result though
Gives:
bb =
[ 1/8, 3*a + 3*b + 2*c]

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

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by