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