From 15553c8c605a400a1c274f6bfb9b133c31a2fe89 Mon Sep 17 00:00:00 2001 From: Vidith2602 <96585068+Vidith2602@users.noreply.github.com> Date: Mon, 14 Apr 2025 22:21:49 +0530 Subject: [PATCH] Add files via upload --- cachematrix.R | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..9590e6b1505 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,12 +4,30 @@ ## 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) } ## Write a short comment describing this function cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + ## Return a matrix that is the inverse of 'x' s <- x$getsolve() + if(!is.null(s)) { + message("getting inversed matrix") + return(s) + } + data <- x$get() + s <- solve(data, ...) + x$setsolve(s) + s }