Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e054216

Browse files
committed
[^] cached matrix inverse methods implemeted
1 parent 7f657dd commit e054216

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cachematrix.R

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,28 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
i <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
i <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(inv) i <<- inv
14+
getinverse <- function() i
15+
list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)
816
}
917

1018

1119
## Write a short comment describing this function
1220

1321
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
22+
i <- x$getinverse()
23+
if(!is.null(i)) {
24+
message("getting cached result")
25+
return(i)
26+
}
27+
data <- x$get()
28+
i <- solve(data, ...)
29+
x$setinverse(i)
30+
i
1531
}

0 commit comments

Comments
 (0)