Skip to content

Commit 2d6a72f

Browse files
committed
Assignment version 1.
1 parent 7f657dd commit 2d6a72f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

cachematrix.R

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@
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+
14+
getinv = function () inv
15+
setinv = function (iv) {
16+
inv <<- iv
17+
}
18+
list(set = set, get = get, getinv = getinv, setinv = setinv)
819
}
920

1021

1122
## Write a short comment describing this function
1223

1324
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
25+
inv = x$getinv()
26+
if (!is.null(inv)) {
27+
message("cache!")
28+
return (inv)
29+
} else {
30+
x_data = x$get()
31+
inv = solve(x_data)
32+
x$setinv(inv)
33+
inv
34+
}
1535
}

0 commit comments

Comments
 (0)