MATLAB: ‘Polynomial expression expected.’ showed when i tried to get the coefficents

coeffsrootssymbolicsymbolic polynomial

syms T p1 p2 p3 p4 p5 p6 real
J = T + T*((6*p1)/T^2 - (2*p4)/T)^2 + T*((6*p2)/T^2 - (2*p5)/T)^2 + T*((6*p3)/T^2 - (2*p6)/T)^2 + (T^6*((12*p1)/T^3 - (6*p4)/T^2)^2)/3 + (T^6*((12*p2)/T^3 - (6*p5)/T^2)^2)/3 + (T^6*((12*p3)/T^3 - (6*p6)/T^2)^2)/3 - T^2*((6*p1)/T^2 - (2*p4)/T)*((12*p1)/T^3 - (6*p4)/T^2) - T^2*((6*p2)/T^2 - (2*p5)/T)*((12*p2)/T^3 - (6*p5)/T^2) - T^2*((6*p3)/T^2 - (2*p6)/T)*((12*p3)/T^3 - (6*p6)/T^2);
J1 = diff(J,T);
cT = coeffs(J1,T);
Just got J for another window.
why would it show "Error using symengine Polynomial expression expected." as i ran it?
should i get a normal form of J1 first, when i want the coefficients of it? If so, how?
Appreciate for an answer.

Best Answer

coeffs() can only be used for polynomials with respect to the variable. Your expression has division by your variable, and so is not a polynomial.
simplify() would bring a normal form, but it would still have division by the variable and so is not enough.
What you can do is
[N, D] = numden(J1);
Nc = coeffs(N, T, 'all');
Dc = coeffs(D, T, 'all');
Now Nc are the numerator coefficients and Dc are the denominator coefficients.
Related Question