1. Don't use l as a variable name, it is too easy to confuse it with 1.

2. l is a constant, so the loop only does anything when n=1, and n=2.

3. It looks as though you intend x to be an array, but its only a scalar.

4. It is not clear what you are trying to do here.

The following creates an array of the coefficients:

.Code:clear b=zeros(1,40); %initialize to a row vector of 40 0's for n=1:40 if (mod(n,2)==0) L=n/2; b(n)= -1/(pi*L); else L=(n+1)/2; b(n)=2/((pi*(2*L+1))))*(1+(2*(-1)^L)/(pi*(2*L+1)); end end