File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 1 file changed +18
-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
3
-
4
- # # Write a short comment describing this function
1
+ # # makeCacheMatrix returns an object that can cache the inverse of a specified matrix.
5
2
6
3
makeCacheMatrix <- function (x = matrix ()) {
7
-
4
+ inv <- NULL
5
+ set <- function (m ) {
6
+ x <<- m
7
+ inv <<- NULL
8
+ }
9
+ get <- function () x
10
+ setInverse <- function (i ) inv <<- i
11
+ getInverse <- function () inv
12
+ list (set = set , get = get , setInverse = setInverse , getInverse = getInverse )
8
13
}
9
14
10
15
11
- # # Write a short comment describing this function
16
+ # # cacheSolve asks if the inverse is null, meaning it hasn't been cached yet, and computes it if so.
17
+ # # Otherwise, it returns the cached inverse. This function passes any additional arguments on to solve.
12
18
13
19
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
20
+ if (is.null(x $ getInverse())) {
21
+ i <- solve(x $ get(), ... )
22
+ x $ setInverse(i )
23
+ return (i )
24
+ }
25
+ x $ getInverse()
15
26
}
You can’t perform that action at this time.
0 commit comments