MATLAB: Obtaining coeff. of syms function

symbolic

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 1×1 sym . I want to obtain the coeff.(a,b,c,d,e) separately from the sym structure.

Best Answer

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)