0

I am having trouble finding the Fourier series of a 2nd order ODE. Should I be using the piecewise function as well to set up the range for t?

Solve $ y'' + \omega^2 = r(t) $, where $ r(t) = |t|, -\pi < t < \pi $ by using Fourier series.

So far I have set up the ODE and set equal to r[t]

r[t] = y''[t] + ω^2 y[t]
Plot(r[t], {t, -π, π}]

Any help with the Mathematica code would be greatly appreciated. How can I find An, Bn with the function being an ODE?

  • 2
    Maybe this?: dsol = DSolve[{y''[t] + w^2 y[t] == RealAbs[t], y[Pi] == 0, y[-Pi] == 0}, y, t, Assumptions -> w \[Element] Integers]; Simplify[ FourierCoefficient[y[t] /. First[dsol], t, n], w \[Element] Integers] – Michael E2 Nov 24 '20 at 00:56
  • If the original question is "Solve ′′ + ^2 = (), where () = ||, - < < using Fourier series", I'm afraid you've misunderstood the question. This doesn't mean "finding the Fourier series of a 2nd order ODE". Anyway, you may want to read the following: https://mathematica.stackexchange.com/q/155817/1871 – xzczd Nov 24 '20 at 02:55
  • @MichaelE2 I'd guess the required b.c.s are y[-Pi]==y[Pi], y'[-Pi]==y'[Pi]. (This should be clarified by OP, of course. ) – xzczd Nov 24 '20 at 03:21
  • @MichaelE2 yes those are the boundary conditions – Mord Fustang199 Nov 24 '20 at 04:25
  • 2
    By "those" you mean which b.c.s? Please clarify by editing the question. – xzczd Nov 24 '20 at 07:31

1 Answers1

1

Develop the driving force Abs[t] into FourierSeries and solve diff equation for the general coefficients.

FourierSeries[Abs[t], t, 3, FourierParameters -> {1, 1}]

(* -((2 E^(-I t))/[Pi]) - (2 E^(I t))/[Pi] - (2 E^(-3 I t))/( 9 [Pi]) - (2 E^(3 I t))/(9 [Pi]) + [Pi]/2 *)

fc[n_] = FourierCoefficient[Abs[t], t, n, FourierParameters -> {1 , 1 }]

Treat n==0 separately and proofing identity yields True

FourierSeries[Abs[t], t, 9, FourierParameters -> {1, 1}] == 
   fc[0] + Sum[fc[n] (E^(I n t) + E^(-I n t)), {n, 1, 9}] // Simplify

for comparison solve numericaly for Abs[t], since DSolve gave the wrong result in version 8.0, even for Sqrt[t^2]. And solve for n==0 separately.

ynr[w_] := 
   y /. First@
NDSolve[{y[0] == 0, y'[0] == 0, y''[t] + w^2 y[t] == Abs[t]}, 
y, {t, -Pi, 3 Pi}]

ysol[0, w_] = y /. First@ DSolve[{y[0] == 0, y'[0] == 0, y''[t] + w^2 y[t] == fc[0]}, y, t]

ysol[n_ /; n >= 1, w_] = y /. First@ DSolve[{y[0] == 0, y'[0] == 0, y''[t] + w^2 y[t] == fc[n] (E^(I n t) + E^(-I n t))}, y, t] // ExpToTrig

Manipulate[ Plot[Evaluate[{ynr[2][t], ysol[0, 2][t] + Sum[ysol[n, 2][t], {n, 1, nmax, 2}]}], {t, -Pi, 3 Pi}, GridLines -> Automatic, PlotStyle -> {Red, Blue}, PlotRange -> {0, 1.5}], {nmax, 1, 7, 1, Appearance -> "Labeled" }]

Developing to n== 5 seems sufficient.

enter image description here

Akku14
  • 17,287
  • 14
  • 32