File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -33,14 +33,19 @@ makeCacheMatrix <- function(x = matrix()) {
33
33
# # inverse in the cache via the setInverse function
34
34
35
35
cacheSolve <- function (x , ... ) {
36
- # # Return a matrix that is the inverse of 'x'
36
+ # # Return a matrix that is the inverse of 'x'
37
+ # # First check if the inverse of x is already stored in cache
37
38
i <- x $ getInverse()
38
39
if (! is.null(i )) {
40
+ # # If so, just return the cached value of the inverse of 'x'
39
41
message(" getting cached data" )
40
42
return (i )
41
43
}
44
+ # #If there is no value cached, use the solve function to compute the
45
+ # #Inverse of the matrix
42
46
data <- x $ get()
43
47
i <- solve(data , ... )
48
+ # #Save the result in cache and return the inverse of 'x'
44
49
x $ setInverse(i )
45
50
i
46
51
}
You can’t perform that action at this time.
0 commit comments