# I use the rule, but it cannot work, So I want to know why it can't? [closed]

I make a approximate solution of the differential equations. But when I use the rule for one, and it can work. But when using a list of rules, It cannot. I mean "(Sum[ep^k*Subscript[y, k], {k, 0, n - 1}] /. First@s1)[x]" cannot caculate.(The last line cannot work, the line before the last line can work) Could you help me please? Thanks a lot.

Clear["*"]
f := ((1 + #3)*#2^2 + 1) &
n = 3;
s = CoefficientList[Collect[D[Series[y[x, ep], {ep, 0, n}], x] -
Series[f[x, y[x, ep], ep], {ep, 0, n}], ep], ep] // Simplify;
s = s /. {
\!$$\*SuperscriptBox[\(y$$,
TagBox[
RowBox[{"(",
RowBox[{"j_", ",", "i_"}], ")"}],
Derivative],
MultilineFunction->None]\)[x, 0] :> D[Subscript[y, i][x], {x, j}],
y[x, 0] :> Subscript[y, 0][x]};
s1 = DSolve[{s[] == 0, s[] == 0, s[] == 0,
Subscript[y, 0] == 0, Subscript[y, 1] == 0,
Subscript[y, 2] == 0}, {Subscript[y, 0], Subscript[y, 1],
Subscript[y, 2]}, x];
a = (Subscript[y, 0] /. s1[[1, 1]])[x]

(Sum[ep^k*Subscript[y, k], {k, 0, n - 1}] /. First@s1)[x]


What you are doing is quite complicated (I wonder whether you wrote this or copied it from somewhere).

To make it work you only need a simple change - the last line could be written as

Sum[ep^k*Subscript[y, k][x], {k, 0, n - 1}] /. First[s1]
(* 1/4 ep Sec[x]^2 (2 x - Sin[2 x]) + Tan[x] +
1/8 ep^2 Sec[x]^2 (-6 x + 3 Sin[2 x] + 4 x^2 Tan[x]) *)


Your version added the functions (which Mathematica doesn't understand), and then tried to evaluate the sum at x. This evaluates the functions at x first, and then sums them.

• Excellent! Thank you very much. I write it to find the Asymptotic Solution of a differential equation. It cannot work when pure function added ? Sep 3 at 10:23

Suggest you change

(Sum[ep^k*Subscript[y, k], {k, 0, n - 1}] /. First@s1)[x]


To

(Sum[ep^k*Subscript[y, k][x], {k, 0, n - 1}] /. First@s1)
`

Each Subscript[y,*] is a function of x.

• We obviously looked at this at the same time! Sep 2 at 19:32
• And came to the same recommendation. All good.
– JV3
Sep 2 at 20:09
• So good! Thank you very much! Sep 3 at 10:24