Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 858c92d

Browse files
committed
Iplementation for
1 parent 7f657dd commit 858c92d

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

cachematrix.R

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## functions in this file let you calculate the inverse of matrices
2+
## in a performant way. Should be used when you have many matrices to calculate
33

4-
## Write a short comment describing this function
4+
## creates a special type of matrix, with getters and setters for the underlying data, and the inverse.
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
i <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
i <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(inverse) i <<- inverse
14+
getinverse <- function() i
15+
list (set=set, get=get, setinverse=setinverse, getinverse=getinverse)
816
}
917

1018

11-
## Write a short comment describing this function
19+
## calculates the inverse of the supplied CacheMatrix (created via `makeCacheMatrix`)
1220

1321
cacheSolve <- function(x, ...) {
1422
## Return a matrix that is the inverse of 'x'
23+
i <- x$getinverse()
24+
if (!is.null(i)) {
25+
message("getting cached data")
26+
return(i)
27+
}
28+
data <- x$get()
29+
i <- solve(data, ...)
30+
x$setinverse(i)
31+
i
1532
}

0 commit comments

Comments
 (0)