File tree Expand file tree Collapse file tree 1 file changed +23
-6
lines changed Expand file tree Collapse file tree 1 file changed +23
-6
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
1
+ # # Caching the Inverse of a Matrix
3
2
4
- # # Write a short comment describing this function
3
+ # # This function creates a special "matrix" object that can cache its inverse
5
4
6
5
makeCacheMatrix <- function (x = matrix ()) {
7
-
6
+ m <- NULL
7
+ set <- function (y ) {
8
+ x <<- y
9
+ m <<- NULL
10
+ }
11
+ get <- function () x
12
+ setsolve <- function (solve ) m <<- solve
13
+ getsolve <- function () m
14
+ list (set = set , get = get ,
15
+ setsolve = setsolve ,
16
+ getsolve = getsolve )
8
17
}
9
18
10
19
11
- # # Write a short comment describing this function
20
+ # # This function computes the inverse of the special "matrix" returned by makeCacheMatrix above
12
21
13
22
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
23
+ m <- x $ getsolve()
24
+ if (! is.null(m )) {
25
+ message(" getting cached data" )
26
+ return (m )
27
+ }
28
+ data <- x $ get()
29
+ m <- solve(data , ... )
30
+ x $ setsolve(m )
31
+ m
15
32
}
You can’t perform that action at this time.
0 commit comments