File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+ # # Pair of function that compute/cache the inverse of a matrix.
52
3+ # # This function creates a special "matrix" object that can cache its inverse.
64makeCacheMatrix <- function (x = matrix ()) {
5+ s <- NULL
6+ setMatrix <- function (y ) {
7+ x <<- y
8+ s <<- NULL
9+ }
10+ getMatrix <- function () x
11+ setSolve <- function (sol ) s <<- sol
12+ getSolve <- function () s
13+ list (setMatrix = setMatrix , getMatrix = getMatrix ,
14+ setSolve = setSolve , getSolve = getSolve )
715
816}
917
1018
11- # # Write a short comment describing this function
12-
19+ # # This function computes the inverse of the special "matrix" returned by
20+ # # makeCacheMatrix above. If the inverse has already been calculated (and
21+ # # the matrix has not changed), then cacheSolve should retrieve the inverse
22+ # # from the cache.
1323cacheSolve <- function (x , ... ) {
1424 # # Return a matrix that is the inverse of 'x'
25+ s <- x $ getSolve()
26+ if (! is.null(s )) {
27+ message(" getting cached data" )
28+ return (s )
29+ }
30+ data <- x $ getMatrix()
31+ s <- solve(data , ... )
32+ x $ setSolve(s )
33+ s
1534}
You can’t perform that action at this time.
0 commit comments