File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # # Put comments here that give an overall description of what your
2- # # functions do
3-
4- # # Write a short comment describing this function
1+ # # Set of functions to add the ability to cache the inverse of the Matrix and to
2+ # # use the cached value while getting the inverse of a Matrix
53
4+ # # Adds the ability to cache the inverse of the matrix passed in as a paramter to this## function
65makeCacheMatrix <- function (x = matrix ()) {
7-
6+ inverse <- NULL
7+ set <- function (y ) {
8+ x <<- y
9+ inverse <<- NULL
10+ }
11+ get <- function () x
12+ setinverse <- function (i ) inverse <<- i
13+ getinverse <- function () inverse
14+ list (get = get , set = set , getinverse = getinverse , setinverse = setinverse )
815}
916
1017
11- # # Write a short comment describing this function
12-
18+ # # Gets the inverse of the Matrix and caches the result if required.
1319cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
20+ # # Return a matrix that is the inverse of 'x'
21+ i <- x $ getinverse()
22+ if (! is.null(i )) {
23+ message(" Getting cached inverse" )
24+ return (i )
25+ }
26+ m <- x $ get()
27+ i <- solve(m , ... )
28+ x $ setinverse(i )
29+ i
1530}
You can’t perform that action at this time.
0 commit comments