From 6ad12818ff6b27d22c91af2d153324d699e3380d Mon Sep 17 00:00:00 2001 From: Revathi0612 Date: Mon, 7 Apr 2025 11:21:53 +0530 Subject: [PATCH] Update cachematrix.R --- cachematrix.R | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..98d95a2cacc 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -3,13 +3,22 @@ ## Write a short comment describing this function -makeCacheMatrix <- function(x = matrix()) { - +makeCacheMatrix <- function() { +mat <- NULL +inv_cache <- NULL +setMatrix <-function(x){ +mat <<-x +inv_cache<<- NULL } - - -## Write a short comment describing this function - -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' +getInverse <- function() { +if (is.null(inv_cache)){ +inv_cache <<-solve(mat) +} +inv_cache +} +list(setMatrix=setMatrix,getInverse = getInverse) +} +cacheSolve <- function(x,...){ +inv_cache <-x$getInverse() +inv_cache }