File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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.
4
+
5
+ makeCacheMatrix <- function (x = matrix ()) {
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 )
16
+ }
17
+
18
+
19
+ # # This function returns the inverse of the vector created with makeCacheMtrix
20
+ # # by first getting it from cache if available.
21
+
22
+ cacheSolve <- function (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'
32
+ }
You can’t perform that action at this time.
0 commit comments