Skip to content

Commit ee97e07

Browse files
committed
Adding code for both functions
1 parent 3f3eb83 commit ee97e07

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

cachematrix.R

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
## This function creates a special "matrix" object that can cache its inverse.
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
m <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
m <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(inverse) m <<- inverse
14+
getinverse <- function() m
15+
list(set = set, get = get,
16+
setinverse = setinverse,
17+
getinverse = getinverse)
818
}
919

1020

@@ -14,4 +24,15 @@ makeCacheMatrix <- function(x = matrix()) {
1424

1525
cacheSolve <- function(x, ...) {
1626
## Return a matrix that is the inverse of 'x'
27+
m <- x$getinverse()
28+
if(!is.null(m)) {
29+
message("getting cached data")
30+
return(m)
31+
}
32+
data <- x$get()
33+
m <- solve(data)
34+
x$setinverse(m)
35+
m
1736
}
37+
38+

0 commit comments

Comments
 (0)