I am using the Symbolic Math Toolbox, and define polynomials as symbolic objects, e.g.:
syms a x y;
P = x^2*y + a*x*y^2 + x*y^2;
I am looking for a function that collects coefficients of the same powers – something like
collect_coeff(P,x*y^2)
that will return
a + 1
Would anyone have a solution to my problem?
You can use MuPAD's
coeff(documentation) to accomplish this within Matlab:which returns
a + 1. I recommend reading the full documentation forcoeffand related MuPAD functions for manipulating symbolic polynomials.