Reading the coefficients with Maple

212 Views Asked by At

If I have

$$ a+(b-c \cdot a) \cdot x = 5+7x $$

then I know that

$$ a = 5 $$

and

$$ b-c \cdot a = b-5c = 7 $$

Can I get this result with Maple?

If I just write solve(a+(b-c*a)*x = 5+7*x) it will solve it instead of just 'reading' the coefficient.

2

There are 2 best solutions below

1
On BEST ANSWER

The simplest is

solve(identity(a+(b-c*a)*x = 5+7*x, x, [a,b]);

which immediately returns

[[a = 5, b = 5*c+7]]
0
On

You could do as follows

 lhs:=a+(b-c*a)*x
 rhs:=5+7x
 solve(coeff(lhs,x,0)=coeff(rhs,x,0),a)

This will output $a=5$. You are solving the equation that the coefficients of the 0 degree terms on each side are equal. To solve for $a$ and say $b$ simultaneously you could try

 solve({coeff(lhs,x,0)=coeff(rhs,x,0),coeff(lhs,x,1)=coeff(rhs,x,1)},{a,b})

I hope this helps!


NOTE: The command $\verb!coeff(expression,var,degree)!$ regards $\verb!expression!$ as a polynomial in $\verb!var!$ and returns the coefficient of the term of degree specified in $\verb!degree!$.


Of course, defining $\verb!lhs!$ and $\verb!rhs!$ separately can also be replaced by storing the equation as $\verb!eq1!$ and then applying the commands $\verb!lhs(eq1)!$ and $\verb!rhs(eq1)!$ instead.