When I use the code syms x; c = coeffs(3*x^2, 'All'); 3*x^2 displays not [3, 0, 0] how can I fix that?

조회 수: 1 (최근 30일)
When I use the code syms x; c = coeffs(3*x^2, 'All'); 3*x^2 displays not [3, 0, 0]; how can I fix that? I'm actually wanting to use a code more like: syms x y; c = coeffs(y*x^2, y,'All') but that displays "Error using sym/coeffs Too many input arguments." Any help here would be greatly appreciated! Thanks!

채택된 답변

Star Strider
Star Strider 2016년 4월 3일
It works for me in R2016a:
syms x
c = coeffs(3*x^2, 'All')
c =
[ 3, 0, 0]
The current online documentation is for R2016a. If you’re using a prior release, the online documentation might not apply. There have recently been significant changes between versions.
The sym2poly function will produce the same result if you need it for other calculations:
f = 3*x^2;
p = sym2poly(f)
p =
3 0 0
That should work in previous releases as well.
  댓글 수: 2
SciFiPhysics Guy
SciFiPhysics Guy 2016년 4월 3일
I have 2015b would that make the difference? I'm primarily trying to use a function that can distinguish from multiple symbols; so far I can only think of coeffs. Thanks for the quick response!
Star Strider
Star Strider 2016년 4월 3일
My pleasure!
I went through the online documentation to look up the R2015b and R2016a documentation for coeffs. The 'All' option is indeed new in R2016a. (It wasn’t mentioned in the Release Notes, so I had to go digging.)
The sym2poly work-around is the best I can do.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by