File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change 1
1
# # Put comments here that give an overall description of what your
2
2
# # functions do
3
3
4
- # # Write a short comment describing this function
4
+ # # Create a matrix that will cache its inverse.
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
+ inverse <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ m <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinverse <- function (inverse ) inverse <<- inverse
14
+ getinverse <- function () inverse
15
+ list (set = set , get = get ,
16
+ setinverse = setinverse ,
17
+ getinverse = getinverse )
7
18
8
19
}
9
20
10
21
11
- # # Write a short comment describing this function
22
+ # # Return a matrix that is the inverse of 'x'
23
+ # # Requires x to be of "makeCacheMatrix" type
12
24
13
25
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
26
+ inverse <- x $ getinverse()
27
+ if (! is.null(inverse )) {
28
+ return (inverse )
29
+ }
30
+ data <- x $ get()
31
+ inverse <- solve(data )
32
+ x $ setinverse(inverse )
33
+ inverse
15
34
}
You can’t perform that action at this time.
0 commit comments