MATLAB: How to find quadratic part of a symbolic polynomial

polynomialquadratic partsymbolic

I have a rather large symbolic polynomial with lots of variables, I need the quadratic part of this polynomial.
The best solution that I came up with so far is to choose two variables x, y (or one variable for x^2), substitute all other variables with zero. Then take the partial derivative of this term with respect to x, then take the partial derivative of the resulting term with respect to y, then substitute x and y with zero in the resulting term – and the result should be the coefficient of xy in the polynomial.
Since my polynomial has so many variables and is so large, this solution would take way too long – is there an easier way to do this?

Best Answer

Read about coeffs. This will gove you all the coefficients.
c = coeffs(p,'All') ;
c has all the coefficents, you can pcik your required using c by indexing.
c2 = c(end-2) ; % coefficent of x^2
Related Question