Module # 5 Doing Math

 

Matrix Operations in R: Determinant and Inverse

The goal of this assignment is to learn how to work with matrices in R, specifically how to compute the determinant and inverse of a matrix using built-in R functions.


Step 1: Creating the Matrices

First, I created the two matrices provided in the assignment using the matrix() function.

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

To better understand these matrices, I checked their dimensions:

dim(A) dim(B)
  • Matrix A has dimensions 10 × 10, so it is a square matrix.

  • Matrix B has dimensions 10 × 100, so it is not square.


Step 2: Determinant of Matrix A

Since matrix A is square, its determinant can be calculated using the det() function.

det(A)

Result:

The determinant of matrix A is:

0

A determinant of 0 means that matrix A is singular, which has important consequences for finding its inverse.


Step 3: Inverse of Matrix A

The inverse of a matrix in R is calculated using the solve() function.

solve(A)

Result:

R returns an error indicating that the system is computationally singular.

Explanation:

A matrix with a determinant equal to 0 does not have an inverse. Therefore, matrix A cannot be inverted.


Step 4: Determinant and Inverse of Matrix B

Matrix B is not square (10 × 100), so:

  • A determinant is not defined

  • An inverse is not defined

Attempting either operation in R results in an error, which confirms the mathematical rule that only square matrices can have determinants and inverses.


Conclusion

  • Matrix A is square, but its determinant is 0, so it does not have an inverse.

  • Matrix B is not square, so neither a determinant nor an inverse exists.

  • R correctly enforces the rules of matrix algebra when performing these operations.

This assignment helped reinforce the importance of matrix dimensions and determinants when working with inverse matrices in R.

Comments

Popular posts from this blog

ABC vs. CBS: Comparing Fictional Presidential Poll Data in R

Assignment #10: Building Your Own R Package

Module # 4 Programming structure assignment