-1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ interspersing code and text makes your post difficult to read $\endgroup$ Jul 7, 2015 at 4:05
  • 2
    $\begingroup$ I've only seen the power series method applied to initial value problems, never to boundary value problems. If you can tell me how to do it mathematically, I can probably help you write the code. But I doubt it can be done mathematically. $\endgroup$
    – Michael E2
    Jul 7, 2015 at 5:14

1 Answer 1

1
$\begingroup$

This only works with the assumed n !!!. Let's n = 6.

 ClearAll["Global`*"]
 n = 6;
 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

 SS = First@
 Solve[{Normal[y] == 0 /. x -> L/2, 
 Normal[y] == P /. x -> -L/2}, {c[0], c[1]}]

$\left\{c(0)\to -\frac{23040 P}{L^6-120 L^4+5760 L^2-46080},c(1)\to -\frac{1920 P}{L \left(L^4-80 L^2+1920\right)}\right\}$

SOL = Normal[y] /. SS

Yours Solution:

$\left\{-\frac{16 P x^5}{L \left(L^4-80 L^2+1920\right)}+\frac{320 P x^3}{L \left(L^4-80 L^2+1920\right)}-\frac{1920 P x}{L \left(L^4-80 L^2+1920\right)}+\frac{32 P x^6}{L^6-120 L^4+5760 L^2-46080}-\frac{960 P x^4}{L^6-120 L^4+5760 L^2-46080}+\frac{11520 P x^2}{L^6-120 L^4+5760 L^2-46080}-\frac{23040 P}{L^6-120 L^4+5760 L^2-46080}\right\}$

And

 P = 1;
 L = 3;
 sol = First@NDSolve[{x''[t] + x[t] == 0, x[L/2] == 0, x[-L/2] == P}, 
 x[t], {t, -L/2, L/2}]; Plot[{x[t] /. sol, SOL /. x -> t}, {t, -L/2,
 L/2}, PlotLegends -> {"NDSolve solution", " Yours SUM"}]

enter image description here

If you put $L=\pi$ in yours equation seeks to $\infty$

General Solution:

$$x''(t)+x(t)=0,x\left(\frac{L}{2}\right)=0,x\left(-\frac{L}{2}\right)=P$$

   Clear[L, P];
   yyy = First@DSolve[x''[t] + x[t] == 0, x[t], t];
   XSOL = First@
   Solve[{(x[t] /. yyy) == 0 /. t -> L/2, (x[t] /. yyy) == P /. 
   t -> -L/2}, {C[1], C[2]}];
   yyy /. XSOL

$\left\{x(t)\to \frac{1}{2} P \sec \left(\frac{L}{2}\right) \cos (t)-\frac{1}{2} P \csc \left(\frac{L}{2}\right) \sin (t)\right\}$

  Plot[Evaluate[
  x[t] /. (yyy /. XSOL) /. {P -> 1, L -> {3, 3.1, 3.14}}], {t, -Pi, 
  Pi}, PlotLegends -> {"3", "3.1", "3.14"}, PlotRange -> All]

enter image description here

Or:

 Limit[(1/2 P Cos[t] Sec[L/2] - 1/2 P Csc[L/2] Sin[t]) /. {t -> L, 
 P -> 1}, L -> Pi]

is $\infty$.

$\endgroup$
1
  • $\begingroup$ Thanks a lot. It was very helpful. $\endgroup$
    – Emad
    Jul 7, 2015 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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