obtaining coeff. of syms function

I m solving a 4th order eqn using syms, its like a*x^4+b*x^3+c*x^2+d*x+e=0, where a,b,c,d,e are constants. the eqn is stored in syms as 1x1 sym . I want to obtain the coeff.(a,b,c,d,e) separately from the sym structure.

 採用された回答

Paulo Silva
Paulo Silva 2011 年 7 月 12 日

0 投票

a=1;b=2;c=3;d=4;e=5;
syms x
s=a*x^4+b*x^3+c*x^2+d*x+e
c=coeffs(s)
The c vector is what you want, the index values are in reverse order so
c=fliplr(c)
c(1) is your a c(2) is your b ...
just noticed that c is also symbolic so if you want the numeric values do
double(c)

1 件のコメント

ajit bhuddi
ajit bhuddi 2011 年 7 月 14 日
thanks a lot
It works quite well.

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

その他の回答 (1 件)

ajit bhuddi
ajit bhuddi 2011 年 7 月 14 日

0 投票

But I want to add some more thing to the answer
if the equation is for example: g=ax^3+bx^2+c
coeffs(g) will return only [c,b,a] and it will not give coeff. corresponding to coeff. of x (which is 0 in this case).

2 件のコメント

Paulo Silva
Paulo Silva 2011 年 7 月 14 日
That's completely different from your original question but I will help you once more:
a=1;b=2;c=3;
syms x
s=a*x^3+b*x^2+c
pf=sym2poly(s);
pf(end-1) %the coefficient for x
ajit bhuddi
ajit bhuddi 2011 年 7 月 15 日
this seems fine for a more general polynomial case.

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

カテゴリ

ヘルプ センター および 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