Module # 5 Doing Math

 

Matrix Inversion and Determinants in R


My assignment was finding the value of inverse of a matrix, determinant of a matrix by using the following values:

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

Procedure ⚒️⚙️

Define the Matrices:
I started by creating two matrices, A and B, in R. Both matrices were square (10x10) matrices:
A <- matrix(1:100, nrow=10)

B <- matrix(1:100, nrow=10)


Calculate the Determinants:
Using the det() function, I calculated the determinants of both matrices:
det_A <- det(A)

det_B <- det(B)

print(paste("Determinant of A:", det_A))

print(paste("Determinant of B:", det_B))


Checking if the Matrices Are Invertible:
I checked whether each matrix had an inverse. A matrix is invertible only if its determinant is non-zero.

Since both matrices had a determinant of zero, neither matrix is invertible.
if (det_A != 0) {

  inv_A <- solve(A)

  print("Inverse of A:")

  print(inv_A)

} else {

  print("Matrix A is singular, so no inverse exists.")

}


if (det_B != 0) {

  inv_B <- solve(B)

  print("Inverse of B:")

  print(inv_B)

} else {

  print("Matrix B is singular, so no inverse exists.")

}


Results📜

After running the code:

  1. Matrix A:

    • Determinant of A: 0

    • Inverse of A: Since the determinant is zero, Matrix A is singular and does not have an inverse.

  2. Matrix B:

    • Determinant of B: 0

    • Inverse of B: Similarly, Matrix B is singular and does not have an inverse.

Conclusion

  • Both Matrix A and Matrix B have a determinant of zero, meaning they are singular matrices.

  • Singular matrices cannot have an inverse, so I couldn't calculate an inverse for either matrix.




Comments

Popular posts from this blog

Module # 6 Doing math in R part 2