I am trying to extract coefficients of a complex expression which is a polynomial in two variables $x,y$ and has max order up to $x^{18},y^{18}$. I am trying to get the coefficient of say $x$ , $x^2$, $y^2$, $x^2 y^3$. I was usingCoefficient
command but seems like I am facing the possible issues listed here.
For example, just a simple example (I was avoifding using CoeeficientLists as my expressions are big) -
A = Expand [(a*x + b*y + c*x^2)^2]
gives
a^2 x^2 + 2 a c x^3 + c^2 x^4 + 2 a b x y + 2 b c x^2 y + b^2 y^2
Coefficient[A, x]
gives
2 a b y
Coefficient[A, x^2]
gives
a^2 + 2 b c y
I want purely the coefficient of $x^2$, that is I want the output to be $a^2$ only. Alos while searching for coefficient of $x$, it should return $0$. I am searching for commands which can do this? like ignore the associated variables with it? like solve the issues regarding the Coefficient
command?
Coefficient[expr, x, 2] /. y -> 0
orCoefficient[Coefficient[expr, x, 2], y, 0]
$\endgroup$x^2
times that same factor.In[7213]:= Coefficient[A*y, x^2*y] Out[7213]= a^2
This is to get around the issue thatCoefficient
does not allow one to provide a list specifying what is to be considered a variable vs what is a constant. $\endgroup$