Created
December 24, 2018 04:10
-
-
Save ellango85/272a0e71c2e6e7c7f67f60a6d3c1ec3e to your computer and use it in GitHub Desktop.
Couple of functions that cache the inverse of a matrix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Couple of functions that cache the inverse of a matrix | |
makeCacheMatrix <- function(x = matrix()) { | |
inv <- NULL | |
set <- function(y){ | |
x <<- y | |
inv <<- NULL | |
} | |
get <- function() x | |
setInverse <- function(solveMatrix) inv <<- solveMatrix | |
getInverse <- function() inv | |
list(set = set, get = get, | |
setInverse = setInverse, | |
getInverse = getInverse) | |
} | |
cacheSolve <- function(x, ...) { | |
inv <- x$getInverse() | |
if(!is.null(inv)){ | |
message("getting cached data") | |
return(inv) | |
} | |
data <- x$get() | |
inv <- solve(data) | |
x$setInverse(inv) | |
inv | |
} | |
## data <- matrix(c(1, 2, 3, 0, 2, 2, 1, 3, 0), nrow=3, ncol=3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment