This repository was archived by the owner on Nov 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +23
-9
lines changed
Expand file tree Collapse file tree 1 file changed +23
-9
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
3-
4- # # Write a short comment describing this function
1+ # # Following is a pair of functions that cache the inverse of a matrix.
52
3+ # # Creates a special "matrix" object that can cache it's inverse
64makeCacheMatrix <- function (x = matrix ()) {
7-
5+ m <- NULL
6+
7+ set <- function (y ) {
8+ x <<- y
9+ m <<- NULL
10+ }
11+ get <- function () x
12+ setInverse <- function (matrix ) m <<- matrix
13+ getInverse <- function () m
14+ list (set = set , get = get , setInverse = setInverse , getInverse = getInverse )
815}
916
10-
11- # # Write a short comment describing this function
12-
17+ # # Computes the inverse of the special "matrix" returned by makeCacheMatrix function above.
18+ # # If the inverse has already been calculated, then returns the inverse from the cache.
1319cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
20+ m <- x $ getInverse()
21+ if (! is.null(m )) {
22+ message(" getting cached data" )
23+ return (m )
24+ }
25+ data <- x $ get()
26+ m <- solve(data , ... )
27+ x $ setInverse(m )
28+ m
1529}
You can’t perform that action at this time.
0 commit comments