Skip to content

Commit 090d9e0

Browse files
committed
add method body follow makeVector/cachemean
1 parent 7f657dd commit 090d9e0

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

cachematrix.R

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## Below are two functions that are used to create a special object that stores a matrix and caches its inverse
32

4-
## Write a short comment describing this function
3+
## Create a list of function to set/get the matrix, and set/get the inverse
54

65
makeCacheMatrix <- function(x = matrix()) {
7-
6+
i <- NULL
7+
set <- function(y) {
8+
x <<- y
9+
i <<- NULL
10+
}
11+
get <- function() x
12+
seti <- function(v) i <<- v
13+
geti <- function() i
14+
list(set = set, get = get,
15+
seti = seti,
16+
geti = geti)
817
}
918

1019

11-
## Write a short comment describing this function
20+
## Calculate the inverse of matrix and store to cache
1221

1322
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
23+
i <- x$geti()
24+
if(!is.null(i)) i
25+
data <- x$get()
26+
i <- solve(data,...)
27+
x$seti(i)
28+
i
1529
}

0 commit comments

Comments
 (0)