Skip to content

Commit 5948e11

Browse files
committed
Update cachematrix.R
1 parent 7f657dd commit 5948e11

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

cachematrix.R

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## cachematrix.R
2+
##
3+
## Create a cache marix object in order
4+
## to increase performance by not have
5+
## to calculate repeatedly
36

4-
## Write a short comment describing this function
7+
## Creates cacheMatrix object
58

69
makeCacheMatrix <- function(x = matrix()) {
7-
10+
cachedInverse <- NULL
11+
set <- function(y) {
12+
x <<- y
13+
cachedInverse <<- NULL
14+
}
15+
get <- function() x
16+
setInverse <- function(inverse) cachedInverse <<- inverse
17+
getInverse <- function() cachedInverse
18+
list(set = set, get = get,
19+
setInverse = setInverse,
20+
getInverse = getInverse)
821
}
922

1023

11-
## Write a short comment describing this function
24+
## Returns the inverse cacheMatrix object
1225

1326
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
27+
## Return a matrix that is the inverse of 'x'
28+
invFunc <- x$getInverse()
29+
if(!is.null(invFunc)) {
30+
message("getting cached data")
31+
return(invFunc)
32+
}
33+
data <- x$get()
34+
invFunc <- solve(data, ...)
35+
x$setInverse(invFunc)
36+
invFunc
1537
}

0 commit comments

Comments
 (0)