Skip to content
Closed
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
39 changes: 34 additions & 5 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
## Put comments here that give an overall description of what your
## functions do
## This pair of functions allows to cache the inverse of a matrix.
##If the inverse of a matrix is already cache the program doesn't need to compute it
##repeatedly.

## Write a short comment describing this function
## This function generates a matrix object, and a list that contains a function
##to set and get the value of the matrix, and also the value of the inverse.

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

i <- NULL
set <- function(z) {
x <<- z
i <<- NULL
}
get <- function() x
setsolve <- function(solve) i <<- solve(x)
getsolve <- function() i
list(set = set,
get = get,
setsolve = setsolve,
getsolve = getsolve)

}


## Write a short comment describing this function
## The following function calculates the inverse of the matrix generated with the
## makeCacheMatrix function. First verifies if the inverse has already been calculated.
## If it's true, it gets the inverse from the cache and skips the computation.
## Or else it calculates the inverse of the data and sets the return value in the cache
## by the setinverse function.


cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
i <- x$getsolve()
if(!is.null(i)) {
message("Getting cached data")
return(i)
}
dt <- x$get()
i <- solve(dt, ...)
x$setsolve(i)
i
}