<

Question: how to automatically solve p(x) = q(x) polynomials for coefficients by comparing terms?

given one equation where both sides are polynomials in one variable x, like this

eq:=c1*(x^2+x)+c2*(2+2*x)+c3=-4*x^2+2*x+6;

And we want to solve for the coefficients on the LHS, which are c1,c2,c3.  By hand, this is solved by expanding both sides, and then comparing the coefficient of each power of x. This generates 3 equations (in this example) and then these are solved for c1,c2,c3.

Is there a way to automatically do this in Maple without the user having to do the first manual step of generating the equations needed to solve for c1,c2,c3?

eq1:=c1=-4;eq2:=c1+2*c2=2;eq3:=2*c2+c3=6;
PDEtools:-Solve([eq1,eq2,eq3],[c1,c2,c3])

gives

              {c1 = -4, c2 = 3, c3 = 0}

But It will be nice if there is a command in Maple which will do it starting from the first equation. Ofcourse one has to tell Maple what to solve for. PDEtools:-Solve(eq,[c1,c2,c3]); or solve(eq,[c1,c2,c3]) does not work, because Maple does not know it needs to expand and compare coefficients as we do by hand.

It is not hard to write code to generate these equations, but I am asking if there is already a command in Maple which somehow does it automatically. I looked at SolveTools, but did not spot something yet there.

edit

Ok, I think this is easy to do. I found a command

eq:=c1*(x^2+x)+c2*(2+2*x)+c3=-4*x^2+2*x+6;
eqs:=PolynomialTools:-CoefficientList((lhs-rhs)(eq),x);
PDEtools:-Solve(eqs,[c1,c2,c3])

{c1 = -4, c2 = 3, c3 = 0}

 

 

Please Wait...