File tree Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change 1
- # # Put comments here that give an overall description of what your
2
- # # functions do
1
+ # We compute the inverse of a matrix. Once we compute it, we cache it, so, that
2
+ # don't need to compute it again. We can just retrieve from the cache.
3
3
4
- # # Write a short comment describing this function
5
4
5
+ # This function takes a matrix and makes an object that will cache its inverse.
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ m <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ m <<- NULL
11
+ }
12
+ get <- function () x
13
+ setsolve <- function (solve ) m <<- solve
14
+ getsolve <- function () m
15
+ list (set = set , get = get ,
16
+ setsolve = setsolve ,
17
+ getsolve = getsolve )
8
18
}
9
19
10
20
11
- # # Write a short comment describing this function
12
-
21
+ # This function computes the inverse of a matrix. If it's already been
22
+ # calculated, then the function will retrieve the cached inverse.
13
23
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
24
+ m <- x $ getsolve()
25
+ if (! is.null(m )) {
26
+ message(" getting cached data" )
27
+ return (m )
28
+ }
29
+ data <- x $ get()
30
+ m <- solve(data , ... )
31
+ x $ setsolve(m )
32
+ m
15
33
}
You can’t perform that action at this time.
0 commit comments