File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# # Put comments here that give an overall description of what your
22# # functions do
33
4- # # Write a short comment describing this function
5-
4+ # # returns a list of functions to get/set an 'internal' matrix and get/set its inverse.
5+ # # (get, set, getinv, setinv).
6+ # # If the matrix is 'set' via this list's set function, the inverse matrix will be cleared.
67makeCacheMatrix <- function (x = matrix ()) {
8+ m <- NULL
9+ set <- function (y ) {
10+ x <<- y
11+ m <<- NULL
12+ }
13+ get <- function () x
14+ setinv <- function (matinv ) m <<- matinv
15+ getinv <- function () m
16+ list (set = set , get = get ,
17+ setinv = setinv ,
18+ getinv = getinv )
719
820}
921
1022
11- # # Write a short comment describing this function
12-
23+ # # Returns inverse of x, storing the computation of the inverse
24+ # # x is not actually a matrix, but rather a list generated by makeCacheMatrix
1325cacheSolve <- function (x , ... ) {
26+
27+ m <- x $ getinv()
28+ if (! is.null(m )) {
29+ message(" getting cached data" )
30+ return (m )
31+ }
32+ data <- x $ get()
33+ m <- matrix (rev(c(data )), nrow = nrow(data ), ncol = ncol(data ))
34+ x $ setinv(m )
35+ m
1436 # # Return a matrix that is the inverse of 'x'
1537}
You can’t perform that action at this time.
0 commit comments