title: Saving intermediate variable values of a recursive function
body: <p>I'm trying to code a function calculating difference quotients. I need to this for polynomial interpolation. Given nodes <code>x = linspace(a,b,n+1)</code>, function values at the nodes <code>y = func(x)</code> I want to find the values of difference quotients <code>f[x0], f[x_0,x_1], ..., f[x_0,x_1,...,x_n]</code>. To calculate <code>f[x_0,x_1,...,x_n]</code> I will need <code>f[x_0,x_1,...,x_(n-1)]</code>, etc., thus it would be a good idea save the intermediate steps on my way to <code>f[x_0,x_1,...,x_n]</code>, so that on my way to <code>f[x_0,x_1,...,x_n]</code> I will save the preceding difference quotients as elements of a vector.</p>
  
  <p>Could someone tell me how to correct my code in order to save appropriate difference quotient values? Here's the code:</p>
  
  <pre><code>function [fx, all_fx] = ilo2(a,b,x,y,fx,all_fx)
      if a == b
          fx(end+1) = y(a);
          if a == 1
              all_fx(end+1) = fx(end);
          end
          return
      end
      a;
      b;
      [c, all_fx] = ilo2(a+1,b,x,y,fx,all_fx);
      [d, all_fx] = ilo2(a,b-1,x,y,fx,all_fx);
      fx(end+1) = (c-d)/(b-a);
      if a == 1
          all_fx(end+1) = fx(end);
      end
  end
  </code></pre>
  
  <p>The difference quotients I need are under '<code>if a == 1</code>' condition.</p>