title: Construct a matrix out of multiplied submatrices efficiently
body: <p>I want to construct a matrix like (where A is a real matrix and I is the identity matrix):</p>
  
  <p><a href="https://i.stack.imgur.com/neWlV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/neWlV.png" alt="enter image description here"></a></p>
  
  <p>I don't want to use a for loop. I tried things like:</p>
  
  <pre><code>sequence = 1:T
  sapply(sequence, function(i) matrix(A%^%(i-1)))
  </code></pre>
  
  <p>but failed. I thought of creating the first matrix column in the picture and continue to copy calculated matrices diagonaly, but I have no idea how to realize this.</p>
  
  <p><strong>Edit:</strong> I'm very sorry for the trouble I've caused. Here is what I'm looking for in a quick and dirty for loop</p>
  
  <pre><code>library("expm")
  
  n&lt;-5
  
  A&lt;-matrix(1, 2, 2)
  output &lt;- matrix(0, 5*2, 5*2)
  
  for (i in 1:5) {
    for (j in i:1) {
      output[(2*(i-1)+1):(2*i),(2*(j-1)+1):(2*j)] = A %^% (i-j)
    }
  }
  </code></pre>