Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ClearAll[f, x, n];
- T0 = 2 Pi; (*period*)
- f[x_] := Piecewise[{{1, -Pi < x <= 0}, {Sin[x], 0 <= x <= Pi}}]
- Plot[f[x], {x, -T0/2, T0/2}, Exclusions -> None]
- nTerms = 10;
- c = Table[FourierCoefficient[f[x], x, n, FourierParameters -> {1, 1}], {n, 0,
- nTerms}];
- b = Table[I*(c[[n]] - Conjugate@c[[n]]), {n, 2, nTerms}];
- a = Table[(c[[n]] + Conjugate@c[[n]]), {n, 2, nTerms}];
- Grid[{{Grid[Join[{{"n", "a(n)"}}, Table[{n, a[[n]]}, {n, 1, Length@a}]],
- Frame -> All],
- Grid[Join[{{"n", "b(n)"}}, Table[{n, b[[n]]}, {n, 1, Length@a}]],
- Frame -> All]}}]
- fapprox[x_] := (c[[1]] + Sum[a[[n]] Cos[n x], {n, 1, Length@a}] +
- Sum[b[[n]] Sin[n x], {n, 1, Length@b}])
- Plot[{f[x], fapprox[x]}, {x, -T0/2, T0/2}, Evaluated -> True,
- PlotRange -> All]
- T0 = 2 Pi;
- f[x_] := Piecewise[{{1, -Pi < x <= 0}, {Sin[x], 0 <= x <= Pi}}]
- a0 = 1/(T0/2) Integrate[f[x], {x, -T0/2, T0/2}]
- an = 1/(T0/2) Integrate[f[x] Cos[n x], {x, -T0/2, T0/2}];
- bn = 1/(T0/2) Integrate[f[x] Sin[n x], {x, -T0/2, T0/2}];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement