File tree 1 file changed +23
-6
lines changed
1 file changed +23
-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
+ # # These functions provide a method of caching matrix inversions
3
2
4
- # # Write a short comment describing this function
3
+ # # makeCacheMatrix creates an object wrapping a matrix that allows the calculated
4
+ # # inverse to be cached.
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ i <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ i <<- NULL
11
+ }
12
+
13
+ get <- function () x
14
+ setsolve <- function (inv ) i <<- inv
15
+ getsolve <- function () i
16
+ list (set = set , get = get , setsolve = setsolve , getsolve = getsolve )
8
17
}
9
18
10
19
11
- # # Write a short comment describing this function
20
+ # # cacheSolve will invert a matrix created by makeCacheMatrix and cache the results,
21
+ # # returning a matrix that is the inverse of 'x'.
12
22
13
23
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
24
+ i <- x $ getsolve()
25
+ if (! is.null(i )) {
26
+ return (i )
27
+ }
28
+ m <- x $ get()
29
+ i <- solve(m , ... )
30
+ x $ setsolve(i )
31
+ i
15
32
}
You can’t perform that action at this time.
0 commit comments