Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. ClearAll[f, x, n];
  2. T0 = 2 Pi; (*period*)
  3. f[x_] := Piecewise[{{1, -Pi < x <= 0}, {Sin[x], 0 <= x <= Pi}}]
  4. Plot[f[x], {x, -T0/2, T0/2}, Exclusions -> None]
  5.  
  6. nTerms = 10;
  7. c = Table[FourierCoefficient[f[x], x, n, FourierParameters -> {1, 1}], {n, 0,
  8. nTerms}];
  9. b = Table[I*(c[[n]] - Conjugate@c[[n]]), {n, 2, nTerms}];
  10. a = Table[(c[[n]] + Conjugate@c[[n]]), {n, 2, nTerms}];
  11. Grid[{{Grid[Join[{{"n", "a(n)"}}, Table[{n, a[[n]]}, {n, 1, Length@a}]],
  12. Frame -> All],
  13. Grid[Join[{{"n", "b(n)"}}, Table[{n, b[[n]]}, {n, 1, Length@a}]],
  14. Frame -> All]}}]
  15.  
  16. fapprox[x_] := (c[[1]] + Sum[a[[n]] Cos[n x], {n, 1, Length@a}] +
  17. Sum[b[[n]] Sin[n x], {n, 1, Length@b}])
  18. Plot[{f[x], fapprox[x]}, {x, -T0/2, T0/2}, Evaluated -> True,
  19. PlotRange -> All]
  20.  
  21. T0 = 2 Pi;
  22. f[x_] := Piecewise[{{1, -Pi < x <= 0}, {Sin[x], 0 <= x <= Pi}}]
  23. a0 = 1/(T0/2) Integrate[f[x], {x, -T0/2, T0/2}]
  24. an = 1/(T0/2) Integrate[f[x] Cos[n x], {x, -T0/2, T0/2}];
  25. 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