# Set each coefficient to 0 simultaneously

Here is a simple problem where I want to estimate the center manifold using a series expansion. I want to solve for the coefficients:

adot[a_, b_] := -a^2 + α a b
bdot[a_, b_] := a^2 - α a b - b
bseries[a_] := Sum[Subscript[b, n] a^n, {n, 0, 3}]
CoefficientList[bdot[a, bseries[a]] - D[bseries[a], a] adot[a, bseries[a]], a]

At this point, I'd like to set each of coefficients to zero simultaneously. Is there a smarter way to do this, rather than just copy and paste each of them into to solve and set them to 0? I'd imagine there is, thanks for the help.

• I would suggest making alpha a parameter of the function adot and bdot as well - global variables are going to give you lots of trouble. If you wrap the final calculation in with, With[{a=0,b=0},CoefficientList[...]], you can quickly change the values used for that calculation. – N.J.Evans Aug 4 '17 at 14:13

Updated to include more details

bdot[a_,b_]:=a^2-α a b-b

Now, let's take the series expansion of b[a]:

ansatz = Series[b[a], {a, 0, 4}];
ansatz //TeXForm

$b(0)+a b'(0)+\frac{1}{2} a^2 b''(0)+\frac{1}{6} a^3 b^{(3)}(0)+\frac{1}{24} a^4 b^{(4)}(0)+O\left(a^5\right)$

Putting the ansatz into the expression that should be 0:

ser = lhs[ansatz];
ser //TeXForm

$-b(0)+a \left(-\alpha b(0) b'(0)-b'(0)-\alpha b(0)\right)+a^2 \left(-\alpha b(0) b''(0)-\frac{b''(0)}{2}-\alpha b'(0)-b'(0) \left(\alpha b'(0)-1\right)+1\right)+a^3 \left(-\frac{1}{2} \alpha b(0) b^{(3)}(0)-\frac{1}{6} b^{(3)}(0)-\frac{1}{2} \alpha b''(0)-\frac{1}{2} \alpha b'(0) b''(0)-b''(0) \left(\alpha b'(0)-1\right)\right)+a^4 \left(-\frac{1}{6} \alpha b(0) b^{(4)}(0)-\frac{1}{24} b^{(4)}(0)-\frac{1}{6} \alpha b^{(3)}(0)-\frac{1}{2} \alpha b''(0)^2-\frac{1}{6} \alpha b^{(3)}(0) b'(0)-\frac{1}{2} b^{(3)}(0) \left(\alpha b'(0)-1\right)\right)+O\left(a^5\right)$

We want to set each coefficient to 0, and Solve is capable of doing this without further preprocessing. All we need to do is to figure out what the unknowns are, which in this case are {b[0], b'[0], b''[0], ...}. We can extract these from ser using:

unknowns = Cases[ser, (b | Derivative[_][b])[0], Infinity] //Union;
unknowns //TeXForm

$\left\{b(0),b'(0),b''(0),b^{(3)}(0),b^{(4)}(0)\right\}$

Finally, we can use Solve to find the unknowns:

sol = First @ Solve[ser == 0, unknowns];
sol //TeXForm

$\left\{b(0)\to 0,b'(0)\to 0,b''(0)\to 2,b^{(3)}(0)\to -6 (\alpha -2),b^{(4)}(0)\to 24 \left(\alpha ^2-7 \alpha +6\right)\right\}$

Inserting these unknowns into the ansatz:

res = ansatz /. sol;
res //TeXForm

$a^2+(2-\alpha ) a^3+\left(\alpha ^2-7 \alpha +6\right) a^4+O\left(a^5\right)$

Inserting the ansatz into the expression:

lhs[res] //TeXForm

$O\left(a^5\right)$

Another method

It is also possible to use Solve without specifying the unknowns, although it may not be completely robust:

sol2 = First @ Solve[CoefficientList[ser, a] == 0];

res2 = ansatz /. sol2;
res2 //TeXForm

$a^2+(2-\alpha ) a^3+\left(\alpha ^2-7 \alpha +6\right) a^4+O\left(a^5\right)$

• Can you possibly explain the syntax in the line after Ansatz? – Gregory Aug 4 '17 at 18:36
• @Gregory See update. – Carl Woll Aug 4 '17 at 20:49
• SolveAlways[], can be used instead: SolveAlways[lhs[Series[b[a], {a, 0, 4}]] == 0, a] – J. M. will be back soon Aug 4 '17 at 22:19
• @CarlWoll, the Derivative[_][b] tells Mathematica to solve for any derivative that it sees of b? – Gregory Aug 4 '17 at 23:41