Skip to content

Commit b1a84ed

Browse files
committed
finihed assignment
1 parent 7f657dd commit b1a84ed

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

cachematrix.R

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## Here are a pair of functions that cache the inverse of a matrix
32

4-
## Write a short comment describing this function
53

6-
makeCacheMatrix <- function(x = matrix()) {
4+
## This function creates a special "matrix" object that can cache its inverse
75

6+
makeCacheMatrix <- function(x = matrix()) {
7+
m <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
m <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(ivrs) m <<- ivrs
14+
getinverse <- function() m
15+
16+
list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)
817
}
918

1019

11-
## Write a short comment describing this function
20+
## This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
21+
## If the inverse has already been calculated (and the matrix has not changed),
22+
## then cacheSolve should retrieve the inverse from the cache.
1223

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

0 commit comments

Comments
 (0)