Skip to content

Commit 0552541

Browse files
Complete two functions.
Complete the two function following the detail description which make the matrix inverse.
1 parent 7f657dd commit 0552541

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

cachematrix.R

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,33 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
inv <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
inv <<- NULL
11+
}
12+
get <- function() x
13+
setInverse <- function(inverse) inv <<- inverse
14+
getInverse <- function() inv
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

1324
cacheSolve <- function(x, ...) {
1425
## Return a matrix that is the inverse of 'x'
26+
## Return a matrix that is the inverse of 'x'
27+
inv <- x$getInverse()
28+
if (!is.null(inv)) {
29+
message("getting cached data")
30+
return(inv)
31+
}
32+
mat <- x$get()
33+
inv <- solve(mat, ...)
34+
x$setInverse(inv)
35+
inv
1536
}

0 commit comments

Comments
 (0)