File tree Expand file tree Collapse file tree 1 file changed +29
-7
lines changed
Expand file tree Collapse file tree 1 file changed +29
-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
3-
4- # # Write a short comment describing this function
1+ # # Matrix inversion is usually a costly computation and there may be some
2+ # # benefit to caching the inverse of a matrix rather than compute it repeatedly
3+ # # (there are also alternatives to matrix inversion that we will not discuss
4+ # # here).
55
6+ # # Create a special "matrix" object that can cache its inverse.
67makeCacheMatrix <- function (x = matrix ()) {
7-
8+ m <- NULL
9+ set <- function (y ) {
10+ x <<- y
11+ m <<- NULL
12+ }
13+ get <- function () x
14+ setsolve <- function (solve ) m <<- solve
15+ getsolve <- function () m
16+ list (set = set , get = get ,
17+ setsolve = setsolve ,
18+ getsolve = getsolve )
819}
920
1021
11- # # Write a short comment describing this function
12-
22+ # # Compute the inverse of the special "matrix" returned by makeCacheMatrix
23+ # # above. If the inverse has already been calculated (and the matrix has not
24+ # # changed), then the cachesolve should retrieve the inverse from the cache.
25+ # # Assumption: provided matrix is invertible.
1326cacheSolve <- function (x , ... ) {
1427 # # Return a matrix that is the inverse of 'x'
28+ m <- x $ getsolve()
29+ if (! is.null(m )) {
30+ message(" getting cached data" )
31+ return (m )
32+ }
33+ data <- x $ get()
34+ m <- solve(data , ... )
35+ x $ setsolve(m )
36+ m
1537}
You can’t perform that action at this time.
0 commit comments