Assignment #5: Matrix Algebra in R

 


R code for creating A and B, and for computing invA, detA, invB, and detB:




Outputs for each operation:


Why solve(A) and det(A) behave this way:

Since Matrix A is 10x10 and therefore a square, it could technically have an inverse. However, since the determinant of A is 0, it is considered a singular matrix, meaning it does not have full rank and therefore cannot be inverted. Due to this, solve(A)  returns an error even though the matrix is a square, yet it is still able to run and confirm the singularity.

Why operations on B fail (non‑square matrix):

Since Matrix B is 10x100, it is not square. Inverses and determinants can only be defined for square matrices, meaning both solve(B) and det(B) return errors. Though it is expected, it highlights how important it is to check matrix dimensions before attempting further operations. 

Notes on numeric stability or performance:

There are important considerations when dealing with matrices, even when they are square and invertible. If the determinant is extremely close to zero, the matrix is called ill-conditioned and could result in much larger errors in the inverse. Because of this, it is more stable to solve for a system of equations rather than compute the full inverse. Likewise, as matrices grow, these operations can also become computationally expensive, another instance to watch out for. 

Reference: https://deepai.org/machine-learning-glossary-and-terms/ill-conditioned-matrix

Additional Matrix Operations:

I also used the following operations to better understand how matrices interact: 

- Transpose (t()) - flips rows and columns
- Matrix-vector multiplication (A %*% v) - multiplies a 10x10 matrix by a length 10
- Matrix-matrix multiplication (A %*% B) - multiplies a 10x10 matrix by a 10x100 matrix

Comments

Popular posts from this blog

Assignment #3: Analyzing 2016 data “Poll” Data in R

Assignment #4: Visualizing and Interpreting Hospital Patient Data