File tree Expand file tree Collapse file tree 1 file changed +30
-7
lines changed Expand file tree Collapse file tree 1 file changed +30
-7
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
+ # #
2
+ # # Matrix Inversion Caching
3
+ # ##
3
4
4
- # # Write a short comment describing this function
5
+ # # Creates a special "matrix" object that can cache its inverse.
5
6
6
- makeCacheMatrix <- function (x = matrix ()) {
7
+ makeCacheMatrix <- function (m = matrix ()) {
8
+ i <- NULL
9
+ set <- function (v ){
10
+ m <<- v
11
+ i <<- NULL
12
+ }
13
+ get <- function () m
14
+ setinverse <- function (inverse ) i <<- inverse
15
+ getinverse <- function () i
16
+ list (set = set , get = get ,
17
+ setinverse = setinverse ,
18
+ getinverse = getinverse )
7
19
8
20
}
9
21
10
22
11
- # # Write a short comment describing this function
23
+ # # Computes the inverse.
24
+ # # If the inverse is already computed,
25
+ # # then the cachesolve should retrieve the inverse from the cach
12
26
13
- cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
27
+ cacheSolve <- function (m , ... ) {
28
+ i <- m $ getinverse()
29
+ if (! is.null(i )){
30
+ message(" getting cached data" )
31
+ return (i )
32
+ }
33
+ data <- m $ get()
34
+ i <- solve(data , ... )
35
+ m $ setinverse(i )
36
+ i
15
37
}
38
+
You can’t perform that action at this time.
0 commit comments