From 0d6da97a04c1d88193f1277b10701c1347180344 Mon Sep 17 00:00:00 2001 From: lizthewiz101-alt Date: Tue, 1 Jul 2025 16:39:13 -0500 Subject: [PATCH] Add files via upload --- cachematrix.R | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..8d2587f5792 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,7 +4,17 @@ ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { - + s <- NULL + set <- function(y) { + x <<- y + s <<- NULL + } + get <- function() x + setsolve <- function(solve) s <<- solve + getsolve <- function() s + list(set = set, get = get, + setsolve = setsolve, + getsolve = getsolve) } @@ -12,4 +22,13 @@ makeCacheMatrix <- function(x = matrix()) { cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' + s <- x$getsolve() + if(!is.null(s)) { + message("getting cached data") + return(s) + } + data <- x$get() + s <- solve(data, ...) + x$setsolve(s) + s }