File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Expand file tree Collapse file tree 1 file changed +24
-7
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
+ # # This function takes an invertible matrix to return a vector that
2
+ # # contains functions to 1) set the value of vector, 2}get the value,
3
+ # # 3)set the inverse of the matrix, and 4)get the inverse.
5
4
6
5
makeCacheMatrix <- function (x = matrix ()) {
7
-
6
+ inverse <- NULL
7
+ set <- function (z ) {
8
+ x <<- z
9
+ inverse <<- NULL
10
+ }
11
+ get <- function () x
12
+ setInverse <- function (solve ) inverse <<- solve
13
+ getInverse <- function () inverse
14
+ list (set = set , get = get ,
15
+ setInverse = setInverse , getInverse = getInverse )
8
16
}
9
17
10
18
11
- # # Write a short comment describing this function
19
+ # # This function returns the inverse of the vector created with makeCacheMtrix
20
+ # # by first getting it from cache if available.
12
21
13
22
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
23
+ inverse <- x [[getInverse()]]
24
+ if (! is.null(inverse )){
25
+ message(" getting cached data" )
26
+ return (inverse )
27
+ }
28
+ data <- x [[get()]]
29
+ inverse <- solve(data , ... )
30
+ x [[setInverse(inverse )]]
31
+ inverse # # Return a matrix that is the inverse of 'x'
15
32
}
You can’t perform that action at this time.
0 commit comments