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
60 changes: 53 additions & 7 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,61 @@
## Put comments here that give an overall description of what your
## functions do
## Functions that cache the inverse of a matrix

## Write a short comment describing this function
## This function creates a special "matrix" object that can cache its inverse
makeCacheMatrix <- function( m = matrix() ) {

makeCacheMatrix <- function(x = matrix()) {
## Initialize the variable for inverse property
inv <- NULL

}
## Method to set the matrix
set <- function( matrix ) {
m <<- matrix
inv <<- NULL
}

## Method to get the matrix
get <- function() {
m
}

## Set the inverse of the matrix
setInverse <- function(inverse) {
inv <<- inverse
}

## Get the inverse of the matrix
getInverse <- function() {
inv
}

## Return a list of the methods
list(set = set, get = get, setInverse = setInverse,
getInverse = getInverse)
}

## Write a short comment describing this function

## This function computes the inverse of the special matrix returned by "makeCacheMatrix" above.
## If the inverse has already been calculated (and the matrix has not changed),
## then the "cachesolve" should retrieve the inverse from the cache.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'

## Return a matrix that is the inverse of 'x'
m <- x$getInverse()

## Return the inverse if its already set
if( !is.null(m) ) {
message("Retrieving cached data")
return(m)
}

## Retrieve the matrix from our object
var <- x$get()

## Calculating the inverse using matrix multiplication
m <- solve(var) %*% var

## Set the inverse to the object
x$setInverse(m)

## Return the matrix
m
}