title: Plotting the Taylor polynomial of the sine function
body: <p>I'm trying to code Taylor summation for a function in Matlab, I actually evaluate McLaurin making <code>x=0</code>, named a in this code after this notation:</p>
  
  <p><img src="https://i.stack.imgur.com/OmlBX.png" alt="enter image description here"></p>
  
  <p>This is the code I've tried out so far:</p>
  
  <pre><code>&gt;&gt; a = -100;
  b = 100;
  n = 20;
  vectorx = linspace(a,b,50);
  vectory = [];
  sumterms = [];
  syms x y a;
  y = sin(a);
  for i = 1:n
  t = (diff(y,i-1) / factorial(i-1)) * (x-0)^(i-1);
  sumterms = [sumterms;t];
  end;
  sumterms
  for j = 1:length(vectorx)
  x_i = vectorx(j);
  aux = 0;
  for k = 1:length(sumterms)
  sumterm = sumterms(k);
  aux = aux + subs(sumterm, [a,x], [0,x_i]);
  end
  vectory = [vectory;aux];
  end
  length(vectory)
  length(vectorx)
  plot (vectorx, vectory)
  </code></pre>
  
  <p>But I'm not getting correct results
  I've step over each sentence and I can't really see what's wrong about it.</p>
  
  <p>This is my plot result for sin(x):</p>
  
  <p><img src="https://i.stack.imgur.com/ifVX2.png" alt="enter image description here"></p>
  
  <p>And this is plot for exponential(x)</p>
  
  <p><img src="https://i.stack.imgur.com/MIvB6.png" alt="enter image description here"></p>
  
  <p>Sumterms results for each appear in the image capture, and they seem to be ok, however I think error is in evaluation.</p>