Skip to content

Commit dcc5b13

Browse files
committed
Update cachematrix.R
задание2 для Coursera
1 parent 7f657dd commit dcc5b13

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

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+
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, 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+
inv <- x$getinverse()
23+
if(!is.null(inv)) {
24+
message("getting cached data.")
25+
return(inv)
26+
}
27+
data <- x$get()
28+
inv <- solve(data)
29+
x$setinverse(inv)
30+
inv
1531
}

0 commit comments

Comments
 (0)