Skip to content

Commit bcd0edd

Browse files
author
unknown
committed
Initial commit for Programming Assignment 2
Signed-off-by: Gponster <[email protected]>
1 parent 7f657dd commit bcd0edd

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

cachematrix.R

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,44 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7+
inv <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
inv <<- NULL
11+
}
12+
13+
get <- function() {
14+
x
15+
}
716

17+
setInverse <- function(inverse) {
18+
inv <<- inverse
19+
}
20+
21+
getInverse <- function() {
22+
inv
23+
}
24+
25+
list(set = set, get = get,
26+
setInverse = setInverse,
27+
getInverse = getInverse)
828
}
929

1030

1131
## Write a short comment describing this function
1232

1333
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
34+
## Return a matrix that is the inverse of 'x'
35+
inv <- x$getInverse()
36+
37+
if(!is.null(inv)) {
38+
message('getting cached data')
39+
return (inv)
40+
}
41+
42+
data <- x$get()
43+
inv <- solve(data, ...)
44+
45+
x$setInverse(inv)
46+
inv
1547
}

0 commit comments

Comments
 (0)