File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change 1
- # # Make a cache matrix with an initially unset inverse
1
+ # # Make a cached ' matrix' with an initially unset inverse
2
2
makeCacheMatrix <- function (x = matrix ()) {
3
3
# Inverse is initially null
4
4
i <- NULL
@@ -22,16 +22,17 @@ makeCacheMatrix <- function(x = matrix()) {
22
22
# # Memoize the solve function so as to provide a cached version of the inverse, if available, otherwise
23
23
# # calculate, cache and return the inverse.
24
24
cacheSolve <- function (x , ... ) {
25
- # If the inverse is already calculated return it
25
+ # Get the inverse, if the inverse is already calculated return it
26
26
i <- x $ getinv()
27
27
if (! is.null(i )) {
28
28
message(" getting cached data" )
29
29
return (i )
30
30
}
31
31
# Retrieve the data from the 'matrix'
32
32
data <- x $ get()
33
- # Solve the matrix to retrieve the inverse
33
+ # Solve the matrix to retrieve the inverse, passing the additional options from the caller
34
34
i <- solve(data , ... )
35
+ # Store the result
35
36
x $ setinv(i )
36
37
i
37
38
}
You can’t perform that action at this time.
0 commit comments