Update error in line :

 one     <-  cbind(matrix(1,I(Tn-1),1),as.matrix(seq(1,I(Tn-1))))

  Q_T     <- diag(I(Tn-1)) - one %*% solve(crossprod(one)) %*% t(one)

There was a 2 at Tn-1 that should have been a 1.