File tree Expand file tree Collapse file tree 1 file changed +25
-8
lines changed Expand file tree Collapse file tree 1 file changed +25
-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
+ # # makeCacheMatrix creates a matrix capable of caching its inverse matrix
2
+ # # cacheSolve returns the inverse of a matrix, using the cached version if it exists
5
3
4
+ # # makeCacheMatrix createa a matrix that can cache its inverse.
5
+ # # by calling setinv you will cache the inverse matrix
6
+ # # call getinv so retrieve the inverse matrix
6
7
makeCacheMatrix <- function (x = matrix ()) {
7
-
8
+ m <- NULL
9
+ set <- function (y ) {
10
+ x <<- y
11
+ m <<- NULL
12
+ }
13
+ get <- function () x
14
+ setinv <- function (inv ) m <<- inv
15
+ getinv <- function () m
16
+ list (set = set , get = get , setinv = setinv , getinv = getinv )
8
17
}
9
18
10
19
11
- # # Write a short comment describing this function
12
-
20
+ # # This function takes a makeCacheMatrix and returns is inverse.
21
+ # # It will use a cached version of the inverse matrix if it exists.
13
22
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
23
+ m <- x $ getinv()
24
+ if (! is.null(m )){
25
+ message(" getting inverse matrix from cached data" )
26
+ return (m )
27
+ }
28
+ data <- x $ get()
29
+ m <- solve(data ,... )
30
+ x $ setinv(m )
31
+ m
15
32
}
You can’t perform that action at this time.
0 commit comments