In this question, I have used the debugging tool in matlab and checked step by step. Everything looks fine. However, when I test my codes in the whole, everything seems broken. Could someone give me a hint how to fix my codes? Previously, someone has posted his codes for the same question, but my codes do not have the same issues. In particular, when n=10, the first element of v should be 0, but i got something different. The weird thing is that i did get 0 when debugging.
for t = 0:4*pi
for k = 0:n
me(k+1) = ((-1).^k)*sin(2.*k.*t+t)./(2.*k+1).^2;
k = k+1;