Skip to content

Commit b223428

Browse files
committed
Create cachematrix.R
1 parent e4e33e8 commit b223428

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

cachematrix.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)