From c1aaa846fae7db1839f8db7f9732bb2c49de4c7a Mon Sep 17 00:00:00 2001 From: malika01-sanofi Date: Fri, 4 Jul 2025 14:47:30 +0530 Subject: [PATCH] Create assignment2 add assignment code --- assignment2 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 assignment2 diff --git a/assignment2 b/assignment2 new file mode 100644 index 00000000000..d9c1a526b21 --- /dev/null +++ b/assignment2 @@ -0,0 +1,55 @@ +## The function creates a special "matrix" object that can cache its inverse. + +makeCacheMatrix <- function(x = matrix()) { + + inv <- NULL + + set <- function(y) { + + x <<- y + + inv <<- NULL + + } + + get <- function() x + + setinverse <- function(inverse) inv <<- inverse + + getinverse <- function() inv + + list(set = set, + + get = get, + + setinverse = setinverse, + + getinverse = getinverse) + +} + + +## The function calculates the mean of the special "vector" created with the above function + +cacheSolve <- function(x, ...) { + + inv <- x$getinverse() + + if(!is.null(inv)) { + + message("getting cached data") + + return(inv) + + } + + mat <- x$get() + + inv <- solve(mat, ...) + + x$setinverse(inv) + + inv + +} +