title: Nested for loops in R - Issue with final result
body: <p>I am in the midst of solving a problem in Reconstructing (or recovering) a probability distribution function when only the moments of the distribution are known. I have written codes in R for it and although the logic seems right to me, I am not getting the output that I want.   </p>
  
  <p>The equation I am trying to using as the approximated (or reconstructed or recovered) CDF is what you see in the image below. I am writing codes for the right hand side of the equation and equating that to a vector that I call F in my codes. </p>
  
  <p>The link to paper that contains the original equation can be found here. </p>
  
  <ul>
  <li><a href="http://www.sciencedirect.com/science/article/pii/S0167715208000187" rel="nofollow">http://www.sciencedirect.com/science/article/pii/S0167715208000187</a></li>
  </ul>
  
  <p>It is marked as equation (2) in the paper. </p>
  
  <p>Here is the code I wrote.: </p>
  
  <pre><code>#R Codes:  
  alpha &lt;- 50
  T &lt;- 1
  x &lt;- seq(0, T, by = 0.1)
  
  # Original CDF equation
  Ft &lt;- (1-log(x^3))*(x^3)  
  plot(x, Ft, type = "l", ylab = "", xlab = "")
  
  # Approximated CDF equation using Moment type reconstruction
  k&lt;- floor(alpha*y/T)  
  for(i in 1:length(k))  
  {
  for(j in k[i]:alpha)  
  {  
  F[x+1] &lt;- (factorial(alpha)/(factorial(alpha-j)*factorial(j-k)*factorial(k)))*(((-1)^(j-k))/(T^j))*((9/(j+3))^2)
  }
  }
  plot(x[1:7], F, type = "l", ylab = "", xlab = "")
  </code></pre>
  
  <p>Any help will be appreciated here because the approximation and the graph obtained using my codes is grossly different from the original curve.   </p>