assume (L>0); f := x->piecewise( 0 <= x and x<= L/2, x, L/2 <= x and x<=L, -x+L); a0 := 2/L*int(f(x),x=0..L); an := 2/L*int(f(x)*cos(n*Pi*x/L),x=0..L); simplify(an) assuming n::even; simplify(an) assuming n::odd; parsum := (x,N) -> 1/4*L + sum((-1+(-1)^n)*4*L/((2*n)^2*Pi^2)*cos(2*n*Pi*x/L),n=1..N); L:=10; plot({f(x),parsum(x,1)},x=0..L); plot({f(x),parsum(x,2)},x=0..L); plot({f(x),parsum(x,3)},x=0..L); plot({f(x),parsum(x,4)},x=0..L); plot({f(x),parsum(x,10)},x=0..L);