title: Can someone assist with speeding up my Woodbury matrix inversion code in r?
body: <p>I have code for inverting large matrices and finding the log determinant in R. I really would like this code to run quicker but am struggling for anymore ideas. I have used the Cholesky decomposition and removed unwanted variables for memory.</p>
  
  <p>Please can someone help with ways this code can be improved?</p>
  
  <pre><code>Woodbury_det1 &lt;- function(A,B,C){
  Ua2 &lt;- chol(A) # A=t(U)xU, take U from this
  Ub2 &lt;- chol(B)
  A_inv &lt;- chol2inv(Ua2)# A^-1
  B_inv &lt;- chol2inv(Ub2) # B^-1
  Ua2 &lt;- chol(A_inv) # A^-1=U^tU
  UC &lt;- Ua2 %*% C # UxC
  CA &lt;- crossprod(UC,Ua2) # t(UxC)xU = t(C)xt(U)xU = t(C)xA^-1
  BpCAC &lt;- B_inv + crossprod(UC) # C^TxA^-1xC
  BpCAC_ch = chol(BpCAC)
  BpCAC_inv &lt;- chol2inv(BpCAC_ch) # (B^-1 + t(C)xAxC)^-1
  logdetA &lt;- -2*sum(log(diag(Ua2)))
  logdetB &lt;- -2*sum(log(diag(Ub2)))
  logdetbr &lt;- 2*sum(log(diag(BpCAC_ch)))
  logdetin &lt;- logdetbr+logdetB+logdetA # final determinant calculation
  V &lt;- chol(BpCAC_inv)
  VCA &lt;- V %*% CA
  ACYCA &lt;- crossprod(VCA)
  ACYCA &lt;- as(ACYCA, "dspMatrix")
  X &lt;-  A_inv- ACYCA
  list(X,logdetin)}
  </code></pre>