File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change 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
3
2
4
- # # Write a short comment describing this function
3
+ # # Create a list of function to set/get the matrix, and set/get the inverse
5
4
6
5
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 )
8
17
}
9
18
10
19
11
- # # Write a short comment describing this function
20
+ # # Calculate the inverse of matrix and store to cache
12
21
13
22
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
15
29
}
You can’t perform that action at this time.
0 commit comments