R/hw2_3.R

Defines functions hw2_3

Documented in hw2_3

#' Solution of Question 3(b) in HW2
#' @export
#' @param A matrix variable
hw2_3 <- function(A)
{
  n <- ncol(A)
  # initalization
  Lk <- sqrt(A[1,1])
  k <- 2
  for (k in 2:n) {
    ak <- A[1:(k-1),k]
    ell.k <- forwardsolve(Lk, ak)
    ell.kk <- sqrt(A[k,k] - crossprod(ell.k, ell.k))
    Lk <- rbind(cbind(Lk, rep(0, k-1)), c(ell.k, ell.kk))
  }
  L <- Lk
  return(L)
}
exp500/MAT8054 documentation built on Dec. 20, 2021, 7:39 a.m.