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
+ # # `makeCacheMatrix` creates a special matrix that can hold its cached inverse
2
+ # #
3
+ # # internal fields
4
+ # # x : cached matrix
5
+ # # i : cached inverse
6
+ # #
7
+ # # To explore:
8
+ # # use matrix equality to avoid assignment when matrix is already cached
9
+ # # https://stat.ethz.ch/pipermail/r-help/2012-June/315408.html?BHT-9c73f427-7e3a-bc46-bc8a-5ff5849f6d30.0
5
10
6
11
makeCacheMatrix <- function (x = matrix ()) {
7
- # internal fields
8
- # x : cached matrix
9
- # i : cached inverse
10
-
11
- # explore:
12
- # use matrix equality to avoid assignment when matrix is already cached
13
- # https://stat.ethz.ch/pipermail/r-help/2012-June/315408.html?BHT-9c73f427-7e3a-bc46-bc8a-5ff5849f6d30.0
14
12
i <- NULL
15
13
set <- function (y ) {
16
14
x <<- y
@@ -26,12 +24,14 @@ makeCacheMatrix <- function(x = matrix()) {
26
24
)
27
25
}
28
26
29
- # # Write a short comment describing this function
27
+ # # Return a matrix that is the inverse of 'x'
28
+ # # If there is a cached inverse return that,
29
+ # # if not calculate, cache, and return the inverse of the matrix
30
+ # #
31
+ # # `x`: is the special matrix made by makeCacheMatrix
32
+ # # ex: makeCacheMatrix(matrix(c(3,1,7,5)),2,2)
30
33
31
34
cacheSolve <- function (x , ... ) {
32
- # # Return a matrix that is the inverse of 'x'
33
- # # `x`: is the special matrix made by makeCacheMatrix
34
- # # ex: makeCacheMatrix(matrix(c(3,1,7,5)),2,2)
35
35
i <- x $ getInverse()
36
36
if (! is.null(i )) {
37
37
message(" getting cached inverse" )
0 commit comments