File tree Expand file tree Collapse file tree 1 file changed +24
-5
lines changed Expand file tree Collapse file tree 1 file changed +24
-5
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
+ # # A couple of functions that can cache and create an inverse of a matrix
3
2
4
- # # Write a short comment describing this function
5
3
4
+ # # This function creates a special "matrix" object that can cache its inverse.
6
5
makeCacheMatrix <- function (x = matrix ()) {
7
6
7
+ inversedMatrix <- NULL
8
+
9
+ set <- function (y ) {
10
+ x <<- y
11
+ inversedMatrix <<- NULL
12
+ }
13
+ get <- function () x
14
+
15
+ setInverse <- function (inverse ) inversedMatrix <<- inverse
16
+ getInverse <- function () inversedMatrix
17
+
18
+ list (set = set , get = get ,
19
+ setInverse = setInverse ,
20
+ getInverse = getInverse )
8
21
}
9
22
10
23
11
- # # Write a short comment describing this function
12
-
24
+ # # This function creates an inverse of the matrix x. Unless the inverse is
25
+ # # already created, then it returns the cached inversed matrix.
13
26
cacheSolve <- function (x , ... ) {
14
27
# # Return a matrix that is the inverse of 'x'
28
+ inverse = x $ getInverse()
29
+ if (is.null(inverse )) {
30
+ inverse = solve(x $ get())
31
+ x $ setInverse(inverse )
32
+ }
33
+ inverse
15
34
}
You can’t perform that action at this time.
0 commit comments