⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
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
43 changes: 38 additions & 5 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
## Put comments here that give an overall description of what your
## functions do
## these functions allow for calculating the inverse of a matrix and stores the final output
## this allows for data to be retrieved instead of recalculating when a matrix has already been previously calculated

## Write a short comment describing this function
## makeCacheMatrix() allows the user to create a matrix

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

# setter and getter for original matrix

set <- function(y) {
x <<- y
inv <<- NULL
}

get <- function() x

# setter and getter for inverse

set_inverse <- function(solve) inv <<- solve
get_inverse <- function() inv
list(set = set, get = get,
set_inverse = set_inverse,
get_inverse = get_inverse)
}


## Write a short comment describing this function
## cacheSolve() finds the inverse of the matrix
## it gives the cached result if previously available

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

## finds stored inverse and returns it if possible

inv <- x$get_inverse()
if(!is.null(inv)) {
message("Getting cached inverse matrix...")
return(inv)
}

## calculates new matrix if unavailable

data <- x$get()
inv <- solve(data, ...)
x$set_inverse(inv)

inv
}