diff --git a/.RData b/.RData new file mode 100644 index 00000000000..73543b0d3a9 Binary files /dev/null and b/.RData differ diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 00000000000..e5abdfa32ae --- /dev/null +++ b/.Rhistory @@ -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)