File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44# # Write a short comment describing this function
55
66makeCacheMatrix <- function (x = matrix ()) {
7-
7+ cachedInverse <- NULL
8+ set <- function (newMatrix ) {
9+ x <<- newMatrix
10+ cachedInverse <<- NULL
11+ }
12+ get <- function () x
13+ setInverse <- function (inverse ) cachedInverse <<- inverse
14+ getInverse <- function () cachedInverse
15+ list (set = set ,
16+ get = get ,
17+ setInverse = setInverse ,
18+ getInverse = getInverse )
819}
920
1021
1122# # Write a short comment describing this function
1223
1324cacheSolve <- function (x , ... ) {
1425 # # Return a matrix that is the inverse of 'x'
26+ inverse <- x $ getInverse()
27+ if (! is.null(inverse )) {
28+ message(" getting cached data" )
29+ return (inverse )
30+ }
31+ data <- x $ get()
32+ inverse <- solve(data )
33+ x $ setInverse(inverse )
34+ inverse
1535}
You can’t perform that action at this time.
0 commit comments