fourier series
- Subject: fourier series
- From: aleksasd at mruni.eu
- Date: Tue, 17 May 2011 17:26:04 +0300
How do I compute the Fourier series for f(x) = { 0, (-pi/2,0) cosx (0,pi/2))
Thank you Michael C
Aleksas Domarkas solve:
(%i1) S(n):=a(0)/2+sum(a(k)*cos(k*%pi*x/L)+b(k)*sin(k*%pi*x/L),k,1,n)$
(%i2) f(x):=if x<0 then 0 else cos(x)$
(%i3) L:%pi/2$
(%i4) 1/L*integrate(cos(x)*cos(n*%pi*x/L),x,0,%pi/2)$
ratsimp(expand(%))$
define(a(n),%);
(%o6) a(n):=-(2*cos(%pi*n))/(4*%pi*n^2-%pi)
(%i7) 1/L*integrate(cos(x)*sin(n*%pi*x/L),x,0,%pi/2)$
ratsimp(expand(%))$
define(b(n),%);
(%o9) b(n):=-(2*sin(%pi*n)-4*n)/(4*%pi*n^2-%pi)
(%i10) S(3);
(%o10)
(12*sin(6*x))/(35*%pi)+(2*cos(6*x))/(35*%pi)+(8*sin(4*x))/(15*%pi)-(2*cos(4*x))/(15*%pi)+(4*sin(2*x))/(3*%pi)+(2*cos(2*x))/(3*%pi)+1/%pi
(%i11) S(n);
(%o11)
(sum((4*k*sin(2*k*x))/(4*%pi*k^2-%pi)-(2*(-1)^k*cos(2*k*x))/(4*%pi*k^2-%pi),k,1,n))+1/%pi
(%i12) wxplot2d([f(x),S(3),S(10),S(30)], [x,-%pi/2,%pi/2],
[legend, "f(x)", "S(3)","S(10)","S(30)"],
[gnuplot_preamble, "set key left top"])$
(%t12) << Graphics >>
Aleksas D