x=linspace(0,1,N); %independent variable x -- N must be odd, defined outside f=x.*(1:N<(N+1)/2)+(1-x).*(1:N>=(N+1)/2); %f=x on [0,0.5], f=1-x on [0.5 1] 2*SimpsonsRule(f.*sin(pi*x),0,1) %find the first Fourier coefficient