-
Notifications
You must be signed in to change notification settings - Fork 144k
my work
<>
##Caching the Inverse of a Matrix: ##Matrix inversion is usually a costly computation and there may be some ##benefit to caching the inverse of a matrix rather than compute it repeatedly. ##Below are two functions that are used to create a special object that ##stores a matrix and caches its inverse.
##This function creates a "matrix" object that can cache its inverse.
makeCacheMatrix <- function(x = matrix()) { inv <- NULL set <- function(y) { x <<- y inv <<- NULL } get <- function() x set.inverse <- function(inverse) inv <<- inverse get.inverse <- function() inv list(set = set, get = get, set.inverse = set.inverse, get.inverse = get.inverse) }
##This function computes the inverse of the special "matrix" created by ##makeCacheMatrix above. If the inverse has already been calculated (and the ##matrix has not changed), then it should retrieve the inverse from the cache.
cacheSolve <- function(x, ...) {
inv <- x$get.inverse() if (!is.null(inv)) { message("getting cached data") return(inv) } mat <- x$get() inv <- solve(mat, ...) x$set.inverse(inv) inv }