Module 5- Matrix Operations in R

Matrix Operations in R

I completed Module 5, which involved creating matrices in R and testing inverse and determinant operations.

Code:

A = matrix(1:100, nrow = 10)

B = matrix(1:1000, nrow = 10)


dim(A)
dim(B)

det(A)
solve(A)

det(B)
solve(B)

detA = det(A)
invA = tryCatch(solve(A), error = function(e) e)
detB = tryCatch(det(B), error = function(e) e)
invB = tryCatch(solve(B), error = function(e) e)

Results:

  • Matrix A dimensions: [1] 10 10 (square)
  • Matrix B dimensions: [1] 10 100 (not square)
  • det(A) = 0
  • solve(A) gave error "Lapack routine dgesv: system is exactly singular: U[6,6] = 0"
  • det(B) gave error "'x' must be a square matrix"
  • solve(B) gave error "'a' (10 x 100) must be square"

Explanation: Matrix A is square, so R can attempt det(A) and solve(A), but the determinant equals 0, meaning the matrix is singular and has no inverse. Matrix B is rectangular (not square), so both det(B) and solve(B) fail because only square matrices can have determinants and inverses.

My GitHub Link: https://github.com/ohamad03/Module-5.git

Comments

Popular posts from this blog

R Programming Journal - Omar Hamad

Assignment 6

Generic Functions in R