title: MatLab - nargout
body: <p>I am learning MatLab on my own, and I have this assignment in my book which I don't quite understand.  Basically I am writing a function that will calculate sine through the use of Taylor series.  My code is as follows so far:</p>
  
  <pre><code>    function y = sine_series(x,n);
      %SINE_SERIES: computes sin(x) from series expansion
      % x may be entered as a vector to allow for multiple calculations simultaneously
      if n &lt;= 0
          error('Input must be positive')
      end
      j = length(x);
      k = [1:n];
      y = ones(j,1);
      for i = 1:j
      y(i) = sum((-1).^(k-1).*(x(i).^(2*k -1))./(factorial(2*k-1)));
      end
  </code></pre>
  
  <p>The book is now asking me to include an optional output <code>err</code> which will calculate the difference between sin(x) and y.  The book hints that I may use <code>nargout</code> to accomplish this, but there are no examples in the book on how to use this, and reading the MatLab help on the subject did not make my any wiser.</p>
  
  <p>If anyone can please help me understand this, I would really appreciate it!</p>