From 0f82b603bc96d9d81687f6e1fa7065261a1d64d9 Mon Sep 17 00:00:00 2001 From: TimG333 Date: Thu, 24 Apr 2014 00:32:45 -0400 Subject: [PATCH] Peer Assignment Attempt One Attempting programming assignment two, peer assessment. --- cachematrix.R | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..76f1f10d1da 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,31 @@ -## Put comments here that give an overall description of what your -## functions do +## As per the assignment the functions create and solve a matrix that allows +## for a cached solution -## Write a short comment describing this function +## Creates a list of functions to allow the caching to work makeCacheMatrix <- function(x = matrix()) { - + matrixinverse <- NULL + set <- function(y) { + x <<- y + matrixinverse <<- NULL + } + get <- function() x + setInverse <- function(inverse) matrixinverse <<- inverse + getInverse <- function() matrixinverse + list(set = set, get = get, setInverse = setInverse, getInverse = getInverse) } -## Write a short comment describing this function +## Uses the list from makeCacheMatrix to solve or retrieve a Matrix cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + matrixinverse <- x$getInverse() + if(!is.null(matrixinverse)) { + message("getting cached data") + return(matrixinverse) + } + data <- x$get() + matrixinverse <- solve(data, ...) + x$setInverse(matrixinverse) + matrixinverse }