Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .RData
Binary file not shown.
32 changes: 32 additions & 0 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Function to create a special matrix object that can cache its inverse
makeCacheMatrix <- function(mat = matrix()) {
inv <- NULL
set <- function(matrix) {
mat <<- matrix
inv <<- NULL
}
get <- function() mat
setInverse <- function(inverse) {
inv <<- inverse
}
getInverse <- function() inv
list(set = set, get = get, setInverse = setInverse, getInverse = getInverse)
}
# Function to compute the inverse of the matrix and cache the result
cacheSolve <- function(cacheMatrix) {
inv <- cacheMatrix$getInverse()
if (!is.null(inv)) {
message("Getting cached inverse")
return(inv)
}
mat <- cacheMatrix$get()
inv <- solve(mat)
cacheMatrix$setInverse(inv)
inv
}
# Create a sample matrix
A <- matrix(c(1, 2, 3, 4), nrow = 2)
# Create a cache-enabled matrix object
cachedMatrix <- makeCacheMatrix(A)
# Compute and cache the inverse
cacheSolve(cachedMatrix)