title: loop to add present state with previous state
body: <p>I want to make a loop in order to add the current state with the previous state.</p>
  
  <p>For example:</p>
  
  <pre><code>M=1000; 
  for i=1:M A=i*(x(i));
  </code></pre>
  
  <p>This formula will be for <code>M=1</code> but when <code>M=2</code> the formula will be like this:</p>
  
  <pre><code>A=(i*(x(i))+((i-1)*(x(i-1)))
  </code></pre>
  
  <p>and when <code>M=3</code> the formula will be </p>
  
  <pre><code>A=(i*(x(i))+((i-1)*(x(i-1)))+((i-2)*(x(i-2))
  </code></pre>
  
  <p>and so on till reach the maximum length of <code>M</code> which is <code>1000</code>.</p>