retrieve coefficients from multivariable symbolic equation.

조회 수: 2 (최근 30일)
themaze
themaze 2011년 7월 11일
Hi,
what will be the easiest/best to extract coefficients from multivariate symbolic equations. for instance if I have
131823*c1^4 - 1092957*c1^3*c2 - 1903326*c1^3*c3 + 315414*c1^3 + 681399*c1^2*c2^2 + 291012*c1^2*c2*c3 - 642874*c1^2*c2 + 97275*c1^2*c3^2 + 3458345*c1^2*c3 + 124940*c1^2 + 560571*c1*c2^3 + 1107126*c1*c2^2*c3 + 149922*c1*c2^2 + 548367*c1*c2*c3^2 + 342112*c1*c2*c3 + 457357*c1*c2 + 2496438*c1*c3^3 + 330818*c1*c3^2 - 657587*c1*c3 - 82147*c1 + 779506*c2^3 - 2672451*c2^2*c3 - 254337*c2^2 + 69082*c2*c3^2 + 76916*c2*c3 + 50604*c2 - 1760499*c3^3 - 800417*c3^2 - 317442*c3 - 22910
How can I extract - 800417 as the coefficient of c3^2 and 681399 as the coefficient of c1^2*c2^2?
Thanks

채택된 답변

Friedrich
Friedrich 2011년 7월 11일
Hi,
I think the coeffs function from the Symbolic Math Toolbox could help here:
  댓글 수: 4
Paulo Silva
Paulo Silva 2011년 7월 11일
ok number 1- isn't really true if you provide c1^2 this way
C = coeffs(F1, sym('c1^2'))
themaze
themaze 2011년 7월 11일
Thanks I found a way to do it using coeffs and looping.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 7월 11일
The first question can be solved by messing around with coeffs and using the imagination, second question I have no idea
s=sym('131823*c1^4 - 1092957*c1^3*c2 - 1903326*c1^3*c3 + 315414*c1^3 + 681399*c1^2*c2^2 + 291012*c1^2*c2*c3 - 642874*c1^2*c2 + 97275*c1^2*c3^2 + 3458345*c1^2*c3 + 124940*c1^2 + 560571*c1*c2^3 + 1107126*c1*c2^2*c3 + 149922*c1*c2^2 + 548367*c1*c2*c3^2 + 342112*c1*c2*c3 + 457357*c1*c2 + 2496438*c1*c3^3 + 330818*c1*c3^2 - 657587*c1*c3 - 82147*c1 + 779506*c2^3 - 2672451*c2^2*c3 - 254337*c2^2 + 69082*c2*c3^2 + 76916*c2*c3 + 50604*c2 - 1760499*c3^3 - 800417*c3^2 - 317442*c3 - 22910')
[C,T]=coeffs(s,'c3') %notice T(2) is c3^2
c=C(2); %using the clue that the index 2 is what you are looking for
c=coeffs(c); %get the coeffs again
c(1) %this is what you are looking for
  댓글 수: 1
themaze
themaze 2011년 7월 11일
Thanks I found a way to do it using coeffs and looping.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by