function fourierada(f,n)
% function fourierada(f,n)
% kresli n-ty soucet Fourierovy rady pro funkci f

fs=sym(f);
x=linspace(-pi,pi,401);

ff=strrep(f,'*','.*');
ff=strrep(ff,'/','./');
ff=strrep(ff,'^','.^');
y=eval(ff);

a0=int(f,-pi,pi)/pi;
fk=eval(a0)/2*ones(size(x));

for k=1:n
 sk=sym(['sin(',num2str(k),'*x)']);
 ck=sym(['cos(',num2str(k),'*x)']);
 ak=int(fs*ck,-pi,pi)/pi;
 bk=int(fs*sk,-pi,pi)/pi;
 fk=fk+eval(ak)*cos(k*x);
 fk=fk+eval(bk)*sin(k*x);
end
plot(x,y,'--',x,fk);
