I used the power series method to solve the differential equation y’’+y=0 with y[0]=0 and y’[0]=1 using the following code. In this code “y” is considered as “y = Sum[c[i] x^i, {i, 0, n}] + O[x]^(n + 1)”. In this case the boundary conditions resulted to c[0]=0 and c[1]=1 (8th line). I don’t have any problem with this code and it works pretty well.
ClearAll["Global`*"]
n=20;
y = Sum[c[i] x^i, {i, 0, n}] + O[x]^(n + 1);
de1 = D[y, {x, 2}] + y == 0;
coeffeqns = LogicalExpand[de1];
coeffs = Solve[coeffeqns, Table[c[i], {i, 2, n}]];
y = y /. coeffs;
mm[x_] := Normal[y] /. {c[0] -> 0, c[1] -> 1};
Plot[Evaluate[mm[x]], {x, -2 Pi, 2 Pi}, PlotRange -> All,
PlotRangeClipping -> True, Frame -> True]
Now, I am going to change the boundary condition with y[L/2]=0 and y[-L/2]=P. (L and P are constant). In this case “y” is considered as “y = Sum[c[i] (x-L/2)^i, {i, 0, n}] + O[x]^(n + 1)”. Using the new boundary conditions resulted to c[0]=0 and -c[1] L+c[2] L^2-c[3] L^3+c[4] L^4-…..=P or Sum[c[i] (-L)^i, {i, 1, n}]=P. I will appreciate if somebody help me to modify the aforementioned code to fit into my new problem.