File tree Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Expand file tree Collapse file tree 1 file changed +27
-6
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
+ # # Use a pair of functions to cache the inverse of a matrix.
3
2
4
- # # Write a short comment describing this function
5
3
6
- makeCacheMatrix <- function (x = matrix ()) {
7
4
5
+ # # Creates a special "matrix" object that can cache its inverse
6
+
7
+ makeCacheMatrix <- function (x = matrix ()) {
8
+ m <- NULL
9
+ set <- function (y ) {
10
+ x <<- y
11
+ m <<- NULL
12
+ }
13
+ get <- function () x
14
+ setsolve <- function (solve ) m <<- solve
15
+ getsolve <- function () m
16
+ list (set = set , get = get ,
17
+ setsolve = setsolve ,
18
+ getsolve = getsolve )
8
19
}
9
20
10
21
11
- # # Write a short comment describing this function
22
+ # # Computes the inverse of the special "matrix" returned by makeCacheMatrix.
23
+ # # If the inverse has already been calculated (and the matrix has not changed), then the cachesolve should retrieve the inverse from the cache.
12
24
13
25
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
26
+ m <- x $ getsolve()
27
+ if (! is.null(m )) {
28
+ message(" getting cached data" )
29
+ return (m )
30
+ }
31
+ data <- x $ get()
32
+ m <- solve(data , ... )
33
+ x $ setsolve(m )
34
+ m
35
+
15
36
}
You can’t perform that action at this time.
0 commit comments