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