Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
## Put comments here that give an overall description of what your
## functions do
## The following two functions find the inverse of a matrix.
## If the matrix has already been inverted by cacheSolve, then
## the solution is retrieved from cached values.

## Write a short comment describing this function
## makeCacheMatrix sets the value of the matrix, gets the value of the matrix,
## sets the inverse of the matrix and gets the inverse of the matrix. The
## function then makes a list of 4 functions: set, get, getinverse, and setinverse.

makeCacheMatrix <- function(x = matrix()) {

invert <- NULL
set <- function(y) {
x <<- y
invert <<- NULL
}
get <- function() x
setinverse <- function(inverse) invert <<- inverse
getinverse <- function() invert
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}


## Write a short comment describing this function
## cacheSolve returns the inverse of a matrix. If the matrix has already
## been inverted by these functions, it returns the cached solution. If
## the input is a unique matrix cacheSolve solves for the inverse of the
## matrix.

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
}
invert <- x$getinverse()
if(!is.null(invert)) {
message("getting cached data")
return(invert)
}
data <- x$get()
invert <- solve(data, ...)
x$setinverse(invert)
invert
}