File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,12 @@ makeCacheMatrix <- function(x = matrix()) {
15
15
m <<- NULL
16
16
}
17
17
get <- function () x
18
- setmatrix <- function (matrix ) m <<- mean
19
- getmatrix <- function () m
18
+ # # Set and cache the inverse of the matrix using the solve function
19
+ setinverse <- function (solve ) m <<- inverse
20
+ getinverse <- function () m
21
+ # # Create a list containing a function to set the value of the matrix, get the value of the matrix,
22
+ # # set the value of the inverse, and get the value of the inverse.
23
+ list (set = set , get = get , setinverse = setinverse , getinverse = getinverse )
20
24
21
25
}
22
26
@@ -27,13 +31,16 @@ makeCacheMatrix <- function(x = matrix()) {
27
31
# # retrieve the inverse from the cache.
28
32
29
33
cacheSolve <- function (x , ... ) {
30
- m <- x $ getmatrix()
34
+ m <- x $ getinverse()
35
+ # # check to see if there is already a cached inverse
31
36
if (! is.null(m )) {
32
37
message(" getting cached data" )
33
38
return (m )
34
39
}
40
+
41
+ # # If there is no cached inverse calculate the inverse, cache it and return it
35
42
data <- x $ get()
36
- m <- matrix (data , ... )
37
- x $ setmatrix (m )
43
+ m <- solve (data , ... )
44
+ x $ setinverse (m )
38
45
m
39
46
}
You can’t perform that action at this time.
0 commit comments