For the following equation:
40 \[Lambda]1 + x (-15 - 13 \[Lambda]1 - 24 \[Lambda]2) +
y^2 (2 - 2 \[Lambda]1 - \[Lambda]2) +
x y (-7 - \[Lambda]1 + 2 \[Lambda]2) +
x^2 (3 + \[Lambda]1 + 3 \[Lambda]2) +
y (5 + 11 \[Lambda]1 + 8 \[Lambda]2) == 0
How to extract the coefficients for x², y², xy, x, y terms and the constant term from the equation to obtain results in the following format?
{3 + \[Lambda]1 + 3 \[Lambda]2,
2 - 2 \[Lambda]1 - \[Lambda]2, -7 - \[Lambda]1 + 2 \[Lambda]2, -15 -
13 \[Lambda]1 - 24 \[Lambda]2, 5 + 11 \[Lambda]1 + 8 \[Lambda]2,
40 \[Lambda]1}
Why does the following code produce incorrect results, and how can I fix it to get the expected output?
eq = 40 \[Lambda]1 + x (-15 - 13 \[Lambda]1 - 24 \[Lambda]2) +
y^2 (2 - 2 \[Lambda]1 - \[Lambda]2) +
x y (-7 - \[Lambda]1 + 2 \[Lambda]2) +
x^2 (3 + \[Lambda]1 + 3 \[Lambda]2) +
y (5 + 11 \[Lambda]1 + 8 \[Lambda]2) == 0;
coefficients = {x^2 -> Coefficient[eq[[1]], x, 2],
y^2 -> Coefficient[eq[[1]], y, 2], x*y -> Coefficient[eq[[1]], x*y],
x -> Coefficient[eq[[1]], x, 1], y -> Coefficient[eq[[1]], y, 1],
"Constant" -> eq[[1]] /. {x -> 0, y -> 0}}