File tree Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Expand file tree Collapse file tree 1 file changed +28
-8
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
+ # # Create an object that contains a matrix
2
+ # # and caches its inverse
3
+ # # Use:
4
+ # # to create object
5
+ # # cmatrix <- makeCacheMatrix(matrix)
6
+ # # to invert
7
+ # # inverse <- cacheSolve(cmatrix)
5
8
9
+ # # Create an object that is a matrix caching its inverse
6
10
makeCacheMatrix <- function (x = matrix ()) {
7
-
11
+ inv <- NULL
12
+ set <- function (y ) {
13
+ x <<- y
14
+ inv <<- NULL
15
+ }
16
+ get <- function () x
17
+ setinv <- function (newinv ) inv <<- newinv
18
+ getinv <- function () inv
19
+
20
+ list (set = set , get = get , setinv = setinv , getinv = getinv )
8
21
}
9
22
10
23
11
- # # Write a short comment describing this function
12
-
24
+ # # Return a matrix that is the inverse of 'x'
13
25
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
26
+ inv <- x $ getinv()
27
+ if (! is.null(inv )) {
28
+ inv
29
+ } else {
30
+ data <- x $ get()
31
+ inv = solve(data , ... )
32
+ x $ setinv(inv )
33
+ inv
34
+ }
15
35
}
You can’t perform that action at this time.
0 commit comments