title: Fourier series - Plot in Matlab
body: <p>Here is my m-file for Fourier series plot:</p>
  
  <pre><code>clear
  clc
  syms n
  a0=input('Enter coefficient a0: ');
  an=input('Enter coefficient an: ');
  bn=input('Enter coefficient bn: ');
  a=input('Enter lower boundary: ');
  b=input('Enter upper boundary: ');
  t=linspace(a,b,10000);
  suma=0;
  for n=1:10 %% n could be any number, bigger n - better approximation
  suma=suma+(subs(an,'n',n).*cos(2.*n.*pi.*t./(b-a))+subs(bn,'n',n).*sin(2.*n.*pi.*t./(b-a)));
  end
  series=a0+suma;
  plot(t,series)
  grid
  </code></pre>
  
  <p>Problem is, it is so slow! What should I change in my code in order to inrease speed?</p>
  
  <p>EDIT: In reference to macduff's comment:
  Something like this?</p>
  
  <pre><code>clear
  clc
  a0=input('Enter coefficient a0: ');
  an=input('Enter coefficient an: ','s');
  bn=input('Enter coefficient bn: ','s');
  a=input('Enter lower boundary: ');
  b=input('Enter upper boundary: ');
  t=linspace(a,b,10000);
  suma=0;
  for n=1:10000 %% n could be any number, bigger n - better approximation
  ebn = evalin('caller',bn);
  ean = evalin('caller',an);
  suma = suma + (ean.*cos(2.*n.*pi.*t./(b-a)) + ebn.*sin(2.*n.*pi.*t./(b-a)));
  end
  series=a0+suma;
  plot(t,series)
  grid
  </code></pre>