0
$\begingroup$

I am trying to calculate the complex fourier series of $f(x)=\cosh x$ for $-\pi<x<\pi$ . I tried

f[x_] = If[\pi>x > -pi, Cosh[x], 0];
a[n_] := (2/L)*Integrate[f[x]*Cos[2 n*Pi*x/L], {x, -L/2, L/2}]
a[0] = (1/L)*Integrate[f[x], {x, -L/2, L/2}]
b[n_] := (2/L)*Integrate[f[x]*Sin[2 n*Pi*x/L], {x, -L/2, L/2}]
F[x_, N_] := 
a[o] + Sum[a[n]*Cos[2 n*Pi*x/L] + b[n]*Sin[2 n*Pi*x/L], {n, 1, N}]
p[N_, a_] := 
 Plot[Evaluate[F[x, N]], {x, -a, a}, PlotRange -> All, 
 PlotPoints -> 200]
L = 2Pi;
a[n]
a[0]
b[n]
p[20, 1]    

`

but I cannot the method for the complex Fourier method. Any help?

$\endgroup$
1
  • 1
    $\begingroup$ Your approach here does not take advantage of the built-in FourierSeries. Since your previous, almost identical question from earlier today received an answer, can you specify why the method proposed in that answer does not work for you here? $\endgroup$
    – MarcoB
    Jan 16, 2020 at 19:20

1 Answer 1

1
$\begingroup$

It looks like you do not want to use FouierSeries ? Because you asked similar question before. But if you want to do it yourself, then you can just use the definition. (You say you want complex F.S. but you are using the standard F.S. in your question).

$$ f\left( x\right) \sim\sum_{n=-\infty}^{\infty}c_{n}e^{in\frac{2\pi}{T}x} $$

Where $T$ is the period of $f\left( x\right) $. And $c_{n}=\frac{1}{T} \int_{-\frac{T}{2}}^{\frac{T}{2}}f\left( x\right) e^{-in\frac{2\pi}{T}x} \,dx$

Therefore:

ClearAll[T, x, n, c];
T = 2 Pi; (*period*)
f[x_] := Piecewise[{{Cosh[x], -T/2 < x < T/2}, {0, True}}];
c[n_, T_] := 1/T*Integrate[f[x] Exp[-I 2 n Pi/T x], {x, -T/2, T/2}]
series[nTerms_, T_] := Sum[ c[n, T]* Exp[I 2 n Pi/T x], {n, -nTerms, nTerms}]

And now

series[3,T] (*from -3..3 in the sum*)

Mathematica graphics

Verify

 FourierSeries[f[x], x, 3]

Mathematica graphics

To plot:

   Plot[{Cosh[x], Evaluate@series[3, T]}, {x, -Pi, Pi}]

Mathematica graphics

enter image description here

Manipulate[
 Plot[{Cosh[x], Evaluate@series[nTerms, T]}, {x, -Pi, Pi}, 
  ImageSize -> 400, GridLines -> Automatic, 
  GridLinesStyle -> LightGray, PlotStyle -> {Blue, Red}],
 {{nTerms, 1, "How many terms?"}, 1, 10, 1, Appearance -> "Labeled"},
 ContinuousAction -> False,
 TrackedSymbols :> {nTerms}
 ]
$\endgroup$

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.