f=Piecewise([[(-1,-1/2),-x],[(-1/2,1/2),0],[(1/2,1),x]]) p=plot(f) var('j') an=(2*cos(j*pi/2)+j*pi*sin(j*pi/2)+2*(-1)^j)/(j^2*pi^2) def fs(q): return 3/4+sum(an*cos(j*pi*x),j,1,q) print fs(3) p+=plot(fs(3)(x),color="red") p+=plot(fs(21)(x),color="green") p