File tree 1 file changed +40
-7
lines changed
1 file changed +40
-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
1
+ # # Matrix inversion is usually a costly computation and there
2
+ # # may be some benefit to caching the inverse of a matrix rather
3
+ # # than compute it repeatedly. These functions compute and cache
4
+ # # the matrix inverse.
5
+ # #
6
+ # # These functions assume that the matrix supplied is invertible.
3
7
4
- # # Write a short comment describing this function
5
8
9
+ # # makeCacheMatrix:
10
+ # # This function creates a special "matrix" with functions to
11
+ # # get, set, getsolve, and setsolve.
12
+ # #
13
+ # # 'x' is a matrix that is wrapped with additional functionality.
14
+ # #
15
+ # # Return a "special" matrix that is able to cache its inverse.
6
16
makeCacheMatrix <- function (x = matrix ()) {
7
-
17
+ m <- NULL
18
+ set <- function (y ) {
19
+ x <<- y
20
+ m <<- NULL
21
+ }
22
+ get <- function () x
23
+ setsolve <- function (solve ) m <<- solve
24
+ getsolve <- function () m
25
+ list (set = set , get = get ,
26
+ setsolve = setsolve ,
27
+ getsolve = getsolve )
8
28
}
9
29
10
30
11
- # # Write a short comment describing this function
12
-
31
+ # # cacheSolve:
32
+ # # This function computes the inverse of the special "matrix"
33
+ # # returned by makeCacheMatrix above.
34
+ # #
35
+ # # 'x' is a special "matrix" created by calling makeCacheMatrix
36
+ # #
37
+ # # Return the inverse of the special "matrix"
13
38
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
39
+ m <- x $ getsolve()
40
+ if (! is.null(m )) {
41
+ message(" getting cached data" )
42
+ return (m )
43
+ }
44
+ data <- x $ get()
45
+ m <- solve(data , ... )
46
+ x $ setsolve(m )
47
+ m
15
48
}
You can’t perform that action at this time.
0 commit comments