cachematrix.R

## The aim of this Assignment is to write a pair of functions that cache 
## the inverse of a matrix. The first one will create a special "matrix" 
## object that can cache its inverse. And the second one, computes the inverse
## of the special "matrix" returned by the first function.

## The first function, `makeCacheMatrix`, creates a special "matrix" object,
## which is really a list containing a function to

## 1. set the value of the matrix
## 2. get the value of the matrix
## 3. set the value of the inverse
## 4. get the value of the inverse

makeCacheMatrix <- function(x = matrix()) {

            t <- NULL
            set <- function(y) {
                    x <<- y
                    t <<- NULL
            }
            get <- function() x
            set_inverse <- function(inverse) t <<- inverse
            get_inverse <- function() t
            list(set = set, get = get,
                 set_inverse = set_inverse,
                 get_inverse = get_inverse)

}


## This second function, `cacheSolve`, computes the inverse of the special
## "matrix" returned by the function above. If the inverse has already been
## calculated (and the matrix has not changed), then `cacheSolve` retrieves
## the inverse from the cache.

cacheSolve <- function(x, ...) {

      t <- x$get_inverse()
            if(!is.null(t)) {
                    message("getting cached data")
                    return(t)
            }
            data <- x$get()
            t <- solve(data)
            x$set_inverse(t)
            t
        
}