1
$\begingroup$

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[[1]] == 0, s[[2]] == 0, s[[3]] == 0, 
    Subscript[y, 0][0] == 0, Subscript[y, 1][0] == 0, 
    Subscript[y, 2][0] == 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]
$\endgroup$
2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Excellent! Thank you very much. I write it to find the Asymptotic Solution of a differential equation. It cannot work when pure function added ? $\endgroup$
    – plus Plus
    Sep 3 at 10:23
2
$\begingroup$

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.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.