File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change 4
4
# # Write a short comment describing this function
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
+ # returns a list of functions for:
8
+ # - setting the matrix x
9
+ # - getting the matrix x
10
+ # - setting the inverse of the matrix x (s)
11
+ # - getting the inverse of the matrix x
7
12
s <- NULL
8
13
set <- function (y ) {
9
14
x <<- y
@@ -24,10 +29,12 @@ makeCacheMatrix <- function(x = matrix()) {
24
29
cacheSolve <- function (x , ... ) {
25
30
# # Return a matrix that is the inverse of 'x'
26
31
s <- x $ getinverse()
32
+ # return cached inverse if it exists
27
33
if (! is.null(s )){
28
34
message(" getting cached inverse" )
29
35
return (s )
30
36
}
37
+ # otherwise call solve to get the inverse and set it
31
38
data <- x $ get()
32
39
s <- solve(data , ... )
33
40
x $ setinverse(s )
You can’t perform that action at this time.
0 commit comments