File tree Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Expand file tree Collapse file tree 1 file changed +27
-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
+ # # Matrix inversion is usually a costly computation and there may be
2
+ # # some benefit to caching the inverse of a matrix rather than compute
3
+ # # it repeatedly. These functions help cache the inverse of a matrix.
3
4
4
- # # Write a short comment describing this function
5
+ # # Creates a special "matrix" object that can cache its inverse.
5
6
6
7
makeCacheMatrix <- function (x = matrix ()) {
7
-
8
+ m <- NULL
9
+ set <- function (y ) {
10
+ x <<- y
11
+ m <<- NULL
12
+ }
13
+ get <- function () x
14
+ setinversematrix <- function (matrix ) m <<- matrix
15
+ getinversematrix <- function () m
16
+ list (set = set , get = get ,
17
+ setinversematrix = setinversematrix ,
18
+ getinversematrix = getinversematrix )
8
19
}
9
20
10
21
11
- # # Write a short comment describing this function
22
+ # # Computes the inverse of the special "matrix" returned by makeCacheMatrix.
23
+ # # Retrieve the inverse from the cache if possible.
12
24
13
25
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
26
+ m <- x $ getinversematrix()
27
+ if (! is.null(m )) {
28
+ message(" Getting inverse matrix from cache" )
29
+ return (m )
30
+ }
31
+
32
+ data <- x $ get()
33
+ m <- solve(data , ... )
34
+ a $ setinversematrix(m );
35
+ m
15
36
}
You can’t perform that action at this time.
0 commit comments