# # Helper functions # # Create a column vector (matrix with a single column in R) for the given list l. # Ex. x = vec(c(1.2, 2.4)) vec <- function(l) { len = length(l); v <- matrix(l, nrow=len, ncol=1); return(v) } # Create a matrix for the given list l with the given number of rows(r) and column(r) # Ex. x = mat(c(1,2,3,4), 2, 2) mat <- function(l, r, c, byrow=TRUE) { len = length(l); if(!(len = r*c)) { print("Error in mat(): length of l must be r x c") return (NULL); } m <- matrix(l, nrow=r, ncol=c, byrow=byrow); return(m) } # # Compute the inverse of a square matrix A # inv <- function(A) { return(solve(A)) } # # Compute the 2-norm of a vector or a matrix # #norm2 <- function(A) { # return(norm(A, type="2")) #} norminf <- function(A) { return(norm(A, type="i")) }