We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7f657dd commit 2d6a72fCopy full SHA for 2d6a72f
cachematrix.R
@@ -4,12 +4,32 @@
4
## Write a short comment describing this function
5
6
makeCacheMatrix <- function(x = matrix()) {
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)
19
}
20
21
22
23
24
cacheSolve <- function(x, ...) {
- ## 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
35
0 commit comments