File tree Expand file tree Collapse file tree 1 file changed +23
-8
lines changed Expand file tree Collapse file tree 1 file changed +23
-8
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
1
+ # # functions for creating a cacheable matrix and solving it.
5
2
3
+ # # creates a cacheable matrix
6
4
makeCacheMatrix <- function (x = matrix ()) {
7
-
5
+ inv <- NULL
6
+ set <- function (y ) {
7
+ x <<- y
8
+ inv <<- NULL
9
+ }
10
+ get <- function () x
11
+ setinv <- function (y ) inv <<- y
12
+ getinv <- function () inv
13
+ list (set = set , get = get ,
14
+ setinv = setinv ,
15
+ getinv = getinv )
8
16
}
9
17
10
18
11
- # # Write a short comment describing this function
12
-
19
+ # # solves for the inverse of a cacheable matrix (or uses the cached solution)
13
20
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
21
+ inv <- x $ getinv()
22
+ if (! is.null(inv )) {
23
+ message(" getting cached data" )
24
+ return (inv )
25
+ }
26
+ data <- x $ get()
27
+ inv <- solve(data , ... )
28
+ x $ setinv(inv )
29
+ inv
15
30
}
You can’t perform that action at this time.
0 commit comments