Manipulate[
Module[{L,f,x,step,tooth,a0,an,bn,aotext,g,fourier},
L=1;f[x,1]=x+1;f[x,2]=1-x;f[x,3]=x;f[x,4]=x;f[x,5]=0;f[x,6]=1;
step[1]=Table[{{i-1,1},{i,0},{i+1,1}},{i,1,3,2}];
step[3]=Table[{{(i-2),-1},{i,1},{i,-1}},{i,1,3,2}];
step[5]=Table[{{(i-1),1},{i,1},{i,0},{(i+1),0},{(i+1),1}},{i,1,3,2}];tooth=ListLinePlot[step[choice],PlotRange->{{0,3.1},{-1.2,1.2}},AspectRatio->1.5,ImageSize->{200,300}];
a0=(1/(2L))((∫_(-L)^0)f[x,choice]\[DifferentialD]x+(∫_0^L)f[x,choice+1]\[DifferentialD]x);
an=Table[(1/L)((∫_(-L)^0)(f[x,choice]Cos[((i*π*x)/L)])\[DifferentialD]x+(∫_0^L)(f[x,choice+1]Cos[((i*π*x)/L)])\[DifferentialD]x),{i,1,n}];
bn=Table[(1/L)((∫_(-L)^0)(f[x,choice]Sin[((i*π*x)/L)])\[DifferentialD]x+(∫_0^L)(f[x,choice+1]Sin[((i*π*x)/L)])\[DifferentialD]x),{i,1,n}];
a0text=Row[{(Subscript[Style["a",Italic], 0])," = ", TraditionalForm[a0]}];
antext=TraditionalForm[an];
bntext=TraditionalForm[bn];
g[x_]:=a0+(∑_(i=1)^n)(an[[i]]Cos[((i*π*x)/L)]+bn[[i]]Sin[((i*π*x)/L)]);fourier=Plot[g[x],{x,0,3},PlotRange->{{0,3.1},{-1.2,1.2}},AspectRatio->1.5,ImageSize->{200,300}];
Show[{tooth,fourier},ImageSize->{300,400}]],
{{choice,1,"funkcija"},{1->"     sawtooth 1     \n   (parna funkcija)     ",3->"     sawtooth 2     \n   (neparna funkcija)     ",5->"     square wave     \n(ni parna ni neparna)"},ControlType->Setter,ControlPlacement->Top},
{{n,1,"broj perioda"},Range[4],ControlType->Setter,ControlPlacement->Top},
Delimiter,
Style["Fourierovi koeficijenti",Bold],
"                                                                     ",
Dynamic[Text[Style[a0text,16]]],
Delimiter,
Text@Style[Row[{Style["(Subscript[a, n])",Italic],": ",
Dynamic[antext]}],16],
Delimiter,
Text@Style[Row[{Style["(Subscript[b, n])",Italic],": ",
Dynamic[bntext]}],16],
{aotext2,ControlType->None},
{{antext,{TraditionalForm[4/π^2]}},ControlType->None},
{{bntext,{TraditionalForm[0]}},ControlType->None},
ControlPlacement->Left,TrackedSymbols:>{n,choice}]