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

## Write a short comment describing this function
## The aim of the folowing functions is to cache the
## inverse matrix calculation so that we can avoid
## multiple useless computations

makeCacheMatrix <- function(x = matrix()) {
## This function create a matrix that can have its
## inverse cached

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

## initialise the inverse matrix
inverse <- NULL

## define the getter and setter functions
get <- function() x
set <- function(y) {
x <<- y
inverse <<- NULL
}

## define the functions for the inverse
setInverse <- function(Inv) inverse <<- Inv
getInverse <- function() inverse

list(set = set, get = get,
setInverse = setInverse,
getInverse = getInverse)
}


## Write a short comment describing this function
## This function returns the inverse of a matrix by first checking
## if it has not been computed before !

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'

## initialise the inverse matrix
inverse <- x$getInverse()

## check the existence of a cached value
if(!is.null(inverse)) {
message("getting cached data")
return(inverse)
}
else {
data <- x$get()
inverse <- solve(data)
x$setInverse(inverse)
return(inverse)
}
}