File tree Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Expand file tree Collapse file tree 1 file changed +25
-5
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
+ # # These functions manipulate a special type of matrix which caches its
2
+ # # inverse.
3
3
4
- # # Write a short comment describing this function
4
+ # # makeCacheMatrix creates a new "cache matrix" from a regular matrix.
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ inv <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ inv <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinverse <- function (inverse ) inv <<- inverse
14
+ getinverse <- function () inv
15
+ list (set = set ,
16
+ get = get ,
17
+ setinverse = setinverse ,
18
+ getinverse = getinverse )
8
19
}
9
20
10
21
11
- # # Write a short comment describing this function
22
+ # # cacheSolve returns the inverse of x where x is a "cache matrix"
12
23
13
24
cacheSolve <- function (x , ... ) {
14
25
# # Return a matrix that is the inverse of 'x'
26
+ inv <- x $ getinverse()
27
+ if (! is.null(inv )) {
28
+ message(" getting cached data" )
29
+ return (inv )
30
+ }
31
+ data <- x $ get()
32
+ inv <- solve(data , ... )
33
+ x $ setinverse(inv )
34
+ inv
15
35
}
You can’t perform that action at this time.
0 commit comments