This is some matlab code to check your fourier ak's. All you have to change is the expression for ak, and any particular ak's that are not in the formula (usually a0 is one of these). The other thing you must change is in the expression for sum, the last number (in this case 6) is the period (T). Note: This is what I got for problem 3.22(e).
- t=-6:.001:6;
- k=-40:40;
- ak=0;
- f=0;
- sum=0;
- ak=1./(j.*k.*pi).*(cos(2.*pi./3.*k)-cos(pi./3.*k)); ak(41)=0;
- for num=-40:40
- sum=ak(num+41).*exp(j*num*t*2*pi/6);
- f=f+sum;
- end plot(t,f)