Skip to content

Commit 1fab875

Browse files
author
Merrell Reed
committed
added code for assignment
1 parent 7f657dd commit 1fab875

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

cachematrix.R

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
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
53

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
67
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)
817
}
918

1019

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.
1322
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
1532
}

0 commit comments

Comments
 (0)