Skip to content

Commit 3d6b326

Browse files
committed
Update with working code
1 parent 7f657dd commit 3d6b326

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

cachematrix.R

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@
44
## Write a short comment describing this function
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

11-
## Write a short comment describing this function
21+
#Return the inverse if it's cached
22+
#example: mat<-matrix(c(7, -2, 3, 5), ncol=2, nrow=2)
23+
# fancy <- makeCacheMatrix(mat)
24+
# cacheSolve(fancy)
1225

1326
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
27+
m <- x$getinverse()
28+
if(!is.null(m)) {
29+
return(m)
30+
}
31+
data <- x$get()
32+
m <- solve(data, ...)
33+
x$setinverse(m)
34+
m
1535
}

0 commit comments

Comments
 (0)