File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Expand file tree Collapse file tree 1 file changed +25
-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
+ # # Caching the Inverse of a Matrix
3
2
4
- # # Write a short comment describing this function
3
+ # # makeCacheMatrix creates a special object that stores
4
+ # # a matrix and its inverse.
5
5
6
6
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 ,
16
+ setinverse = setinverse ,
17
+ getinverse = getinverse )
8
18
}
9
19
10
20
11
- # # Write a short comment describing this function
21
+ # # cacheSolve computes the inverse of the given matrix
22
+ # # (created with makeCacheMatrix) and caches the result.
12
23
13
24
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
25
+ i <- x $ getinverse()
26
+ if (is.null(i )) { # No cached inverse
27
+ m <- x $ get() # Get the original matrix,
28
+ i <- solve(m , ... ) # find the inverse,
29
+ x $ setinverse(i ) # cache it.
30
+ } else {
31
+ message(" Getting cached data" )
32
+ }
33
+ i
15
34
}
You can’t perform that action at this time.
0 commit comments