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