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