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