Skip to content

Commit 01d0714

Browse files
committed
Update cachematrix.R
second
1 parent 1b811f7 commit 01d0714

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
@@ -37,6 +37,27 @@ makeCacheMatrix <- function(x = matrix()) {
3737
## Write a short comment describing this function
3838
# cacheSolve: This function computes the inverse of the special "matrix" returned by makeCacheMatrix above. If the inverse has already been calculated (and the matrix has not changed), then the cachesolve should retrieve the inverse from the cache.
3939

40+
# cachemean <- function(x, ...) {
41+
# m <- x$getmean()
42+
# if(!is.null(m)) {
43+
# message("getting cached data")
44+
# return(m)
45+
# }
46+
# data <- x$get()
47+
# m <- mean(data, ...)
48+
# x$setmean(m)
49+
# m
50+
# }
51+
4052
cacheSolve <- function(x, ...) {
41-
## Return a matrix that is the inverse of 'x'
53+
## Return a matrix that is the inverse of 'x'
54+
m_cashe <- x$get_inverse()
55+
if(!is.null(m_cashe)) {
56+
message("getting cached data")
57+
return(m_cashe)
58+
}
59+
data <- x$get()
60+
m_cashe <- solve(data, ...)
61+
x$set_inverse(m_cashe)
62+
m_cashe
4263
}

0 commit comments

Comments
 (0)