File tree Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Expand file tree Collapse file tree 1 file changed +26
-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
+ # # This functions cache the inverse of a matrix in order to
2
+ # # make computation less costly.
3
3
4
- # # Write a short comment describing this function
4
+ # # This function creates a special "matrix" object that can cache its inverse
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ m <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ m <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinverse <- function (solve ) m <<- solve
14
+ getinverse <- function () m
15
+ list (set = set , get = get ,
16
+ setinverse = setinverse ,
17
+ getinverse = getinverse )
8
18
}
9
19
10
-
11
- # # Write a short comment describing this function
20
+ # # This function computes the inverse of the special "matrix" returned by `makeCacheMatrix` above.
21
+ # # If the inverse has already been calculated (and the matrix has not changed), then
22
+ # # `cacheSolve` should retrieve the inverse from the cache.
12
23
13
24
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
25
+ m <- x $ getinverse()
26
+ if (! is.null(m )) {
27
+ message(" getting cached data" )
28
+ return (m )
29
+ }
30
+ data <- x $ get()
31
+ m <- solve(data , ... )
32
+ x $ setinverse(m )
33
+ m
15
34
}
You can’t perform that action at this time.
0 commit comments