File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change
1
+ README.html
Original file line number Diff line number Diff line change 1
1
# # A couple of functions that cache the inverse of a matrix so that the cost of
2
2
# # repetitive computation can be avoided
3
3
4
- # # Write a short comment describing this function
4
+ # # makeCacheMatrix creates an object that can hold the inverse of a matrix.
5
+ # # get/set gets and sets the matrix
6
+ # # getinverse/setinverse gets and sets the inverse of the matrix set
5
7
6
8
makeCacheMatrix <- function (x = matrix ()) {
7
-
9
+ i <- NULL
10
+ set <- function (y ) {
11
+ x <<- y
12
+ i <<- NULL
13
+ }
14
+ get <- function () x
15
+ setinverse <- function (inverse ) i <<- inverse
16
+ getinverse <- function () i
17
+ list (set = set , get = get ,
18
+ setinverse = setinverse ,
19
+ getinverse = getinverse )
8
20
}
9
21
10
22
11
- # # Write a short comment describing this function
23
+ # # cacheSolve returns the inverse of a matrix using the solve function. It
24
+ # # caches the result in a makeCacheMatrix object
12
25
13
26
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
27
+ i <- x $ getinverse()
28
+ if (! is.null(i )) {
29
+ message(" getting cached data" )
30
+ return (i )
31
+ }
32
+ data <- x $ get()
33
+ i <- solve(data , ... )
34
+ x $ setinverse(i )
35
+ i
15
36
}
You can’t perform that action at this time.
0 commit comments