# Fourier expansion does not match parent function

Posted 7 years ago
7341 Views
|
5 Replies
|
2 Total Likes
|
 I am trying to evaluate Fourier series expansion of flow rate as a function of crank angle in a duplex positive displacement pump. I have evaluated Fourier series coefficients for the function. However the Fourier series expansion does not match the parent function even if I sum the series to a large number of terms. I would appreciate any help in identifying what I could be doing wrong. Clear[fsum, fourier, n, nmax, coeff]; f = 5; n =.; t =.; \[Omega] = 2 \[Pi] f; r = 1.; L = 5 r; \[Theta] = \[Omega] t; Clear[P1, P2, coeff, a, b]; P1[\[Theta]_] := -r Sin[\[Theta]] - (r^2 Sin[\[Theta]] Cos[\[Theta]])/ Sqrt[L^2 - r^2 (Sin[\[Theta]])^2]; P2[\[Theta]_] := P1[\[Theta] + Pi]; fsum[\[Theta]_] := Max[P1[\[Theta]], 0] + Max[P2[\[Theta]], 0]; coeff[n_Integer] := coeff[n] = (1/\[Pi]) Quiet@ NIntegrate[ fsum[\[Theta]] Exp[-I n \[Theta]], {\[Theta], -\[Pi], -3/ 4 \[Pi], -\[Pi]/2, -1/4 \[Pi], 0, 1/4 \[Pi], 1/2 \[Pi], 3/4 \[Pi], \[Pi]}, AccuracyGoal -> 8]; a[n_] = Re@coeff[n]; b[n_] = Im@coeff[n]; Clear[fourier, ul]; ul = 1000; fourier[n_] := a /2 + Sum[Re@coeff[n] Cos[n \[Theta]] + Im@coeff[n] Sin[n \[Theta]], {n, 1, ul}]; Plot[{fsum[\[Theta]], fourier[n]}, {\[Theta], 0, 2 \[Pi]}, Frame -> True, Axes -> True, PlotRange -> { {0, 2 \[Pi]}, {0, 1.5}}, FrameLabel -> {"Crank Angle (rad)", "Flow rate"}, GridLines -> Automatic, AspectRatio -> .65, PlotStyle -> {{Red, Thickness[0.005]}, {Green, Thickness[0.0051]}, {Gray, Thickness[0.01]}}, BaseStyle -> {FontWeight -> "Bold", FontSize -> 15, FontFamily -> "Arial"}] Attachments:
5 Replies
Sort By:
Posted 7 years ago
 You have a sign error in your expression for fourier, it should be: fourier[] := a/2 + Sum[ Re@coeff[n] Cos[n \[Theta]] - Im@coeff[n] Sin[n \[Theta]], {n, 1, ul}] I.e., before the Sin term. (Note also that your definition for fourier should not have an argument since the n that you use does not appear in the expression.)Also note the existence of a NFourierSeries function in the "FourierSeries`" package that is part of the Mathematica distribution:http://reference.wolfram.com/language/FourierSeries/ref/NFourierSeries.html
Posted 7 years ago
 Thank you. Appreciate it!
Posted 7 years ago
 Did you mean to repost the original question?
Posted 7 years ago
 No I didn't. Not sure what happened there. Thanks again.
Posted 7 years ago
 You're welcome! Best, David
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.