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
34 changes: 25 additions & 9 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
## Put comments here that give an overall description of what your
## functions do

## Write a short comment describing this function
## This function creates a special matrix object that can store a matrix ans its cached inverse

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

m <- NULL
set <- function(y){
x <<- y
m <<- NULL #Reset the inverse when the matrix changes
}
get <- function() x
setsolve <- function(solve) m <<- solve
getsolve <- function() m
list(set =set, get=get,
setsolve=setsolve,
getsolve=getsolve)
}


## Write a short comment describing this function
## Computes the inverse of the special matrix object

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
}
cacheSolve <- function(x, ...) { #first checks if it has been already calculated
m <- x$getsolve()
if(!is.null(m)) {
message("getting cached data") #if it has been calculated return the cached value
return(m)
}
data <- x$get() #if it has not been calculated it makes the calculation
m <-solve (data, ...)
x$setsolve(m)
m
}
## Return a matrix that is the inverse of 'x'